Repository navigation
Fix push_to_hub_merged for full fine-tunes on transformers 5 - #11482
Conversation
|
Reproduced on a real GPU and real Hugging Face Hub pushes (Modal, NVIDIA L4, torch 2.8.0+cu128). Setup:
In every run the tokenizer
Studio Export page: I ran the real Export page (Local Model → full fine-tune folder → Merged Model → 16-bit → Push to Hub, private). Studio ran on transformers 5.5.0 with each side's Both sides succeed and behave identically. With a save folder, which the page always sends, Studio saves to |
|
Confirmed this hits unsloth/save.py where a full fine-tune push still calls model.push_to_hub with safe_serialization, which transformers 5 no longer accepts, and routing it through the staged single-commit path looks right; could you confirm the extra temp-folder staging is fine for very large full fine-tunes on small local disks before I review? |
…names we wrote
Two follow-ups to the staged full fine-tune push.
The output no longer names the repository. `push_to_hub_merged("me/model")` printed only the
temporary staging folder, and the last line claimed success against a directory deleted a moment
later. The destination is printed around the commit again, as the adapter path already does.
`reconcile_mtp_config` now receives the tensor names the save just wrote. Reading them back off
disk fails for an unindexed `pytorch_model.bin`, which `_checkpoint_tensor_names` declines to
unpickle, so a `safe_serialization = False` export reconciled against "unknown" and kept an
`mtp_num_hidden_layers` the weights do not carry. Reproduced on transformers 4.57.6: before this
commit the uploaded config kept `mtp_num_hidden_layers: 1`, on main it was stripped. Free,
because that state dict is already built for the 16-bit cast; a save that builds none still
passes `None`, so unknown stays unknown.
Both regressions now have a test that fails without the fix.
A branch upload is not on the default branch, and a fresh pull request leaves the repository page with no model files at all, so linking it after either one sends the user to the wrong place. The Hub returns the pull request's own address in `CommitInfo.pr_url`; that is preferred, and where it is absent the destination is built from what was asked for: the discussions list for a new pull request, `/discussions/<n>` for an existing `refs/pr/<n>`, and `/tree/<branch>` for a branch. A plain push to the default branch still prints the repository URL. `create_pr` is checked before `revision` because with both set the files are in the pull request, and the revision is only the branch it was opened against.
…request that cannot be met
Two things found on the staged full fine-tune path.
transformers 5 pops each tensor out of a supplied state dict as it writes the shard holding it
("remove it from state_dict to avoid keeping the ref", modeling_utils), so reading the keys
after save_pretrained reported an export carrying no tensors at all. A model that really has a
multi-token-prediction head then had mtp_num_hidden_layers stripped from the config it shipped
with, and loaders ignore the head that is there. Reproduced on transformers 5.17.0 with an mtp
module present: the uploaded config lost the declaration, and keeps it now. The names are read
before the write instead; the fixture in the test consumes the dict the way transformers does,
so the ordering cannot drift back.
safe_serialization = False now says so when it cannot be honoured. transformers 5 removed the
parameter and always writes safetensors, so an explicit request for a pickle was absorbed by
**kwargs and the export silently came back in the other format. _honours_safe_serialization
probes the signature, the same way _filter_push_to_hub_kwargs already does for the adapter path,
and the default True is never reported.
`patch_saving_functions` replaces `save_pretrained` with a `(*args, **kwargs)` passthrough and keeps the real method on `original_model_save_pretrained`, so probing the bound attribute saw a signature that says nothing. On transformers 4, where the pickle IS written, every patched model therefore got a warning claiming the opposite. Measured on 4.57.6: the probe answered False for the wrapper and True for the original. The original is probed now, and the probe answers True whenever it cannot tell, including a varargs-only signature, since a wrong warning is worse than none. transformers 4.57.6 is silent again and transformers 5.17.0 still reports, both verified against real patched models.
|
Review record for #11482, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#58. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1 — reviewed mirror
|
|
On transformers 5, pushing a full fine-tune with On transformers 4 the same call did not crash but was quietly wrong: The model is now saved to a temporary folder first and uploaded in one commit, which is how pushes to a branch or a pull request already work. The upload carries the 16-bit weights, the tokenizer and the model card. The old push-only config guard goes with it, since the saved folder is reconciled before the upload. Measured across the declared transformers range, same model, Hub calls intercepted:
The resident model dtype and the tokenizer's Also here, each with a test that fails without it:
Note on staging cost: the temporary folder is not new. The Studio Export page is not affected either way. It always sends a save directory, so the backend uploads that folder with Posted as a comment because the description could not be edited from here (the REST route refuses the token and Verification on the final head, base
|
|
pre-commit.ci run |
…ai#11482) On transformers 5, pushing a full fine-tune with `push_to_hub_merged` crashed with `TypeError: unsloth_push_to_hub() got an unexpected keyword argument 'safe_serialization'` and nothing was uploaded: transformers 5 removed `safe_serialization` from `push_to_hub` and dropped its `**kwargs`, and Unsloth generates its patched `push_to_hub` by copying that signature. On transformers 4 the same call did not crash but was quietly wrong, since `state_dict` and `variant` fell into `**deprecated_kwargs`, so a `merged_16bit` push landed as float32 weights across three separate Hub write operations. The model is now saved to a temporary folder and uploaded in one commit, the way pushes to a branch or a pull request already worked, carrying the 16-bit weights, the tokenizer and the model card. The old push-only config guard goes with it, since the staged folder is reconciled before upload. Measured across the declared transformers range, same model, Hub calls intercepted: 4.51.3 3 Hub write ops, float32 -> 1 commit, bfloat16 4.57.6 3 Hub write ops, float32 -> 1 commit, bfloat16 5.5.0 TypeError, nothing sent -> 1 commit, bfloat16 5.17.0 TypeError, nothing sent -> 1 commit, bfloat16 Of 240 enumerated routing cells, 232 are identical and the 8 that move are exactly `push_to_hub` with a non-PEFT model and no branch or pull request requested; unchanged under peft 0.18.0, 0.20.0 and 0.21.0. The resident dtype and the tokenizer's `padding_side` are untouched by a push. Also here, each with a test that fails without it: - The output names the destination again, preferring the pull request's own URL from `CommitInfo.pr_url`, since a branch or pull-request upload is not on the repository page. - `reconcile_mtp_config` receives the tensor names the save just wrote, read before `save_pretrained` because transformers 5 pops each tensor out of the supplied state dict as it writes the shard holding it. Reading them afterwards stripped an `mtp_num_hidden_layers` the weights really do back; reading them off disk cannot see an unindexed `pytorch_model.bin`. - `safe_serialization = False` is reported when this transformers cannot honour it, probed against the real save method rather than the `(*args, **kwargs)` wrapper `patch_saving_functions` installs. The temporary folder is not new disk cost: `PushToHubMixin.push_to_hub` already staged the whole checkpoint before uploading, unconditionally on transformers 5 and by default on 4.

On transformers 5, pushing a full fine-tune with
push_to_hub_mergedcrashes with "unexpected keyword argument 'safe_serialization'". Pushing to the Hub from the Studio Export page fails the same way.The model is now saved to a temporary folder first and uploaded in one commit, which is how pushes to a branch or a PR already work. The upload has the 16-bit weights, tokenizer and model card. This also removes the old push-only config fix, since the saved folder is now fixed before upload. Tested on transformers 5.5.0 and 4.57.6 with a notebook and with the Export page: main failed, this branch uploaded one commit with bf16 weights.