Skip to content

Upload merged models to the requested branch or pull request - #10760

Merged
Etherll merged 9 commits into
unslothai:mainfrom
NilayYadav:merged-hub-destination
Sep 11, 2026
Merged

Etherll merged 9 commits into
unslothai:mainfrom
NilayYadav:merged-hub-destination

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Users can choose a branch or pull request when uploading a merged model. The upload could ignore that choice and write files to the main branch. Model files could also fail to stay together at the requested destination. This change prepares the complete model before starting the upload. It uploads all files together to the chosen branch or pull request. The existing model description, tags and dataset information are preserved. This keeps the uploaded model complete and available where the user expects it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-10T22:42:27.878782Z 182e125 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4cde830b89

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth/save.py
Comment on lines +5455 to +5458
operations = [
CommitOperationAdd(
path_in_repo = path.relative_to(directory).as_posix(), path_or_fileobj = path
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Delete stale checkpoint files before committing the merge

When the destination branch already contains a checkpoint with a different serialization or sharding layout, this add-only commit leaves obsolete weight files in place. For example, replacing an unsharded model.safetensors with indexed shards still leaves the old single-file checkpoint, which Transformers can select instead of the newly uploaded weights; similarly, changing serialization formats can retain a stale preferred file. Include deletion operations for superseded checkpoint artifacts so the requested revision cannot silently load the previous model.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior predates this change: Transformers _upload_modified_files emits only CommitOperationAdd, and Zoo uploads through upload_file/upload_folder without deletion patterns. Reproducing the previous uploader leaves the same stale files. Keeping cleanup outside this PR. Sources: https://github.com/huggingface/transformers/blob/main/src/transformers/utils/hub.py and https://github.com/unslothai/unsloth-zoo/blob/main/unsloth_zoo/saving_utils.py

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@NilayYadav

NilayYadav commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator Author

Verified 182e1252b2a136e6ebdd645e2d98f17cd2f6a919 on upstream-main staging (e726fb1f563948fabde75f35fd745158c210f3e9).

GitHub Actions evidence Result per job
Current fixed implementation 35 passed, 0 failed
Before validation-order fix 33 passed, 2 expected failures
Branch-permission fix / before 31 passed / 30 passed, 1 expected failure
Provenance fix / before 27 passed / 24 passed, 3 expected failures
Upstream implementation, destination regression suite 1 passed, 23 expected failures

Every run has six jobs: Ubuntu, macOS 15, Windows × Hub 0.36.2 and 1.31.0, Python 3.12. All downloaded JUnit reports have zero errors and skips. Each before/after pair uses identical tests, workflow, and dependencies; only unsloth/save.py differs. Current passing suite durations: 2.136–9.037 seconds per job.

Verified assertions include:

  • All eight staged artifacts share the requested destination; remote prose and user metadata survive.
  • Current adapter provenance replaces stale lineage for new PRs, named branches, and existing PR refs.
  • Existing release/candidate branches support PR contributions after branch-write HTTP 403. Actual installed Hub branch handling executes with intercepted HTTP; direct-push permission failures and server errors still propagate.
  • Unforced merged_4bit rejection makes zero repository, branch, merge, or upload calls. Explicit forced mode still reaches saving.
  • Card download errors prevent uploads.

Local focused and related saving tests: 100 passed. The focused suite also passed all 35 tests with Hub 1.31.0. These CPU tests execute the saving functions and real model-card/commit-operation classes with deterministic merge and Hub I/O fixtures. No live Hub upload, GPU merge, or UI change is involved.

Broader staging at PR code 4cde830b89012cd23088e6270ff1c60568f19f45: Core, lint, wheel, notebooks, workflow checks, version compatibility, repository CPU tests, and Backend Python 3.11 passed. Backend Python 3.13 failed the unchanged parser timing test test_deepseek_r1_huge_fenceless_body_is_linear on both attempts (1.009s and 1.239s versus <1.0s). The rerun had 39,865 passed, 1 failed, 250 skipped; this broader suite is not all green. Subsequent fixes have the focused evidence above.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c0820ca5f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth/save.py
Comment on lines +5447 to +5448
if isinstance(model, PeftModel):
card.data.base_model = base_model

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Refresh provenance for staged full-model uploads

When a non-PEFT full-finetuned model is uploaded to an existing destination, the remote card is reused but this condition prevents its base_model from being refreshed, so a repository or branch previously populated from another model continues advertising the old lineage. The helper already derives current provenance when no remote card exists, and the newly added full-finetune route confirms these models now pass through this helper; apply the same refresh when card was loaded remotely rather than restricting it to PeftModel.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is preexisting for full models. The previous path delegates to Transformers push_to_hub; its create_and_tag_model_card loads the existing remote card and appends tags without refreshing base_model. Running that helper and this PR with current model base/model and remote card previous/base returns previous/base in both cases. The adapter path regression was fixed separately. Source: https://github.com/huggingface/transformers/blob/main/src/transformers/utils/hub.py

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d50b365cf5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth/save.py
revision = save_kwargs["revision"]
if revision is not None and not revision.startswith("refs/pr/"):
try:
api.create_branch(repo_id = repo_id, repo_type = "model", branch = revision, exist_ok = True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Initialize new repositories before creating a branch

When repo_id is newly created and revision names a branch, the repository is still empty and has no main commit from which HfApi.create_branch can branch, so this request raises before the staged model can be committed. This makes the new named-revision upload path fail for a common first upload; initialize the repository first or otherwise create the initial commit at the requested destination.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hub create_repo initializes main with a system commit containing .gitattributes, so the stated empty-repository premise does not apply. Official list_repo_commits documentation describes that initial commit: https://huggingface.co/docs/huggingface_hub/package_reference/hf_api#huggingface_hub.HfApi.list_repo_commits . The upstream test_create_and_delete_branch calls repo_factory() then create_branch immediately: https://github.com/huggingface/huggingface_hub/blob/main/tests/test_hf_api.py#L1595 . That factory only calls create_repo and records cleanup, with no upload or extra commit: https://github.com/huggingface/huggingface_hub/blob/main/tests/conftest.py#L200 . No initialization commit to the default branch is needed here.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 10, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 182e1252b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the merged save path in unsloth/save.py drops revision and create_pr when it hands off to merge_and_overwrite_lora, so files land on main instead of the requested destination; thanks for the staged single-commit approach and the test coverage, will get this reviewed.

@Etherll Etherll self-assigned this Sep 11, 2026
@Etherll

Etherll commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

At 182e1252b2, merged exports reached the requested branch or new PR while leaving main unchanged. Baseline exports using revision or create_pr wrote model artifacts to main. Updating an existing PR reused the same PR, and a full-model export passed too. All five downloaded model snapshots reloaded successfully, and their tokenizers produced the expected output.

Native checks ran on Windows with an RTX 5090, using a tiny generated BF16 Llama for actual LoRA merging and full-model saving. Thirty-five destination tests passed with Hub 0.34.0, 1.14.0, and 1.31.0 clients; those version suites simulate merging and transport. Large-model temporary disk use was not measured. An export can overwrite a concurrent README edit made after its card snapshot. The optional Python 3.13 timing check failed, and the CPU CI job was cancelled. No exact-base CI attribution was performed.

@Etherll Etherll left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@Etherll
Etherll merged commit 6a5b21b into unslothai:main Sep 11, 2026
26 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants