Repository navigation
Stop losing the cause of a failed save, and stop dropping 4bit in silence - #9678
Conversation
…ence
Two diagnostics that sent readers to the wrong place.
save.py wraps save failures as RuntimeError(f"Failed to save model: {e}"). An
exception with no args formats as the empty string, so that renders as "Failed
to save model: " and names nothing at all. That is what a GGUF export produced,
and the run had to be repeated with a traceback capture just to learn which call
had failed. _describe_exception always leads with the type, so the class of
failure survives a silent instance, and all three wrappers now chain with
`from e` so the original traceback is not discarded either.
loader.py has four copies of the '-bf16' branch, which disables 4bit, 8bit and
fp8 when the resolved repo is a 16bit checkpoint. That is the right behaviour
and it happened without a word, including when the caller had explicitly passed
load_in_4bit=True. On a small card the consequence arrives much later as an
out-of-memory failure during weight conversion, whose message mentions neither
memory nor quantization, so there is no path back to the line that made the
decision. Each site now says what it disabled, why, and what to do instead, and
only when something was actually requested, so an ordinary 16bit load stays
quiet.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1aad1b07a2
ℹ️ 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".
| except Exception as e: | ||
| raise RuntimeError(f"Failed to save/merge model: {e}{_offloaded_parameter_hint(self)}") | ||
| raise RuntimeError( | ||
| f"Failed to save/merge model: {_describe_exception(e)}" |
There was a problem hiding this comment.
Update the save-error wiring test for the new formatter
With the normal test dependencies installed, tests/test_offloaded_parameter_hint.py::test_the_original_error_is_still_reported now fails: line 147 searches save.py for the literal anchors Failed to save/merge model: {e} and Failed to save model: {e}, both of which this change removes, so SRC.index(anchor) raises ValueError. Update that regression test to recognize _describe_exception(e) so the suite can exercise the new behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed: at the previous head pytest tests/test_offloaded_parameter_hint.py raised ValueError: substring not found on SRC.index("Failed to save/merge model: {e}"). Fixed in e9ed3d1. The anchor is now the message prefix and either rendering is accepted, and it scans every occurrence rather than the first, because _describe_exception's own docstring quotes those messages and was being matched instead of the call site.
| f"Unsloth: `{model_name}` is a 16bit (-bf16) checkpoint, so the " | ||
| f"requested 4bit/8bit/fp8 loading is disabled and the model will " | ||
| f"load in 16bit. Point at the 4bit repo instead if that is not " |
There was a problem hiding this comment.
Clear config-driven quantization before claiming it is disabled
When the caller requests 4-bit or 8-bit loading through kwargs["quantization_config"], the initialization code copies that request into these local flags, so this warning fires, but this branch only clears the locals and leaves the original configuration in kwargs. The later calls at lines 1028-1054 and 2051-2089 still forward that configuration to the Transformers loader, which can therefore quantize the -bf16 checkpoint despite the new message saying quantization was disabled and the model will load in 16-bit; remove or neutralize the configuration here, or report the effective behavior accurately.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and traced end to end: loader.py:462 reads kwargs["quantization_config"] into the local flags but never removes it, the only pop (loader.py:609) is gated on bitsandbytes being unavailable, and vision.py:1345/1390 set their own config only if user_quantization_config is None. So the object is forwarded and Transformers still quantizes while the notice claims 16bit.
I took the second remedy rather than the first. Clearing the config would break on-the-fly 4bit quantization of a bf16 checkpoint, which is the supported BitsAndBytesConfig workflow, so e9ed3d1 suppresses the notice instead and leaves behaviour unchanged. The guard reads kwargs, not the local, because the local is not reset by the pop at 609. Guarded by tests/test_bf16_quant_disabled_message.py, which asserts all four branches carry the gate.
A file search for the pattern found three more wrappers that render an exception with empty args as nothing at all: the q2_k_l quantize path, the GGUF conversion failure, and the convert-to-GGUF wrapper. Two of them also dropped the traceback. All three now use _describe_exception and chain with from e, and the helper moves above its first use rather than relying on module-level name resolution happening to work out.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4d991b0e7
ℹ️ 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".
| else: | ||
| raise RuntimeError(f"Unsloth: GGUF conversion failed: {e}") from e | ||
| raise RuntimeError( | ||
| f"Unsloth: GGUF conversion failed: {_describe_exception(e)}" |
There was a problem hiding this comment.
Update the Kaggle error wiring test for the new formatter
With the normal test dependencies installed, tests/test_kaggle_gguf_error_message.py::test_the_real_error_survives_either_way now fails because line 155 still requires the literal GGUF conversion failed: {e}, which this change replaces with _describe_exception(e). Update that source-level regression test to recognize the new formatter so the suite can continue verifying that the original conversion error survives.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed: test_the_real_error_survives_either_way failed at the previous head on assert "GGUF conversion failed: {e}" in window. Fixed in e9ed3d1; the sibling window.count("from e") >= 2 assertion was already passing and is untouched. The same commit also routes the SIGKILL and Kaggle-disk branches through _describe_exception, since a Kaggle export is the case that motivated the formatter and those two still printed a bare Error: .
…aiming
The formatter change renamed the literals two tests anchor on, so both went
red: test_offloaded_parameter_hint indexes 'Failed to save/merge model: {e}'
and test_kaggle_gguf_error_message asserts 'GGUF conversion failed: {e}'.
Both now accept either rendering, and the first scans every occurrence
rather than the first, because _describe_exception's own docstring quotes
those messages and would otherwise be matched instead of the call site.
The -bf16 notice claimed a 16bit load even when the caller passed
quantization_config=BitsAndBytesConfig(load_in_4bit=True). That object is
only read into the local flags; it stays in **kwargs and is forwarded to
Transformers, which quantizes anyway (loader.py reads it at 462, the only
pop at 609 is gated on bitsandbytes being absent, and vision.py sets its own
config only when the user supplied none). Clearing it would break on-the-fly
quantization of a bf16 checkpoint, so the notice is suppressed instead and
behaviour is unchanged.
Also route the SIGKILL and Kaggle-disk GGUF branches through
_describe_exception. A Kaggle Q8_0 export is the case that motivated the
formatter, and those two were still printing a bare 'Error: ' for an
exception with no args.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9ed3d1431
ℹ️ 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".
| if (load_in_4bit or load_in_8bit or load_in_fp8 != False) and kwargs.get( | ||
| "quantization_config", None | ||
| ) is None: |
There was a problem hiding this comment.
Distinguish the default 4-bit flag from an explicit request
When a caller loads a remote *-bf16 repository without specifying any precision flags, load_in_4bit is still True from the method default, so this condition emits a warning claiming that the caller requested quantized loading and suggesting a different repository. The same misleading warning appears for an ordinary load_in_16bit=True call unless the caller also knows to override load_in_4bit=False, contradicting the intended quiet ordinary 16-bit path; track whether a quantization argument was explicitly supplied rather than testing the normalized/default flag.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and this PR merged before the round closed, so the fix is in #9685.
Confirmed: load_in_4bit defaults to True at loader.py:431 (FastLanguageModel) and :1236 (FastModel), and nothing between the signature and the -bf16 branch clears it. The block at :462 only ever turns flags on, and the bitsandbytes branch at :577 only fires when bitsandbytes is absent. A bare from_pretrained('org/model-bf16') therefore reached the notice with the default set and was told its request was disabled when it made none.
#9685 makes the notice report what happens rather than what was asked for, names the 4bit default so the advice still lands, and suppresses it when load_in_16bit is explicitly set. All four copies, and the quantization_config gate is unchanged. I left the signature default alone rather than moving to a None sentinel, since load_in_4bit = True is a documented public default and int(load_in_4bit) arithmetic exists at vision.py:1234.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…ence (#9678) * Stop losing the cause of a failed save, and stop dropping 4bit in silence Two diagnostics that sent readers to the wrong place. save.py wraps save failures as RuntimeError(f"Failed to save model: {e}"). An exception with no args formats as the empty string, so that renders as "Failed to save model: " and names nothing at all. That is what a GGUF export produced, and the run had to be repeated with a traceback capture just to learn which call had failed. _describe_exception always leads with the type, so the class of failure survives a silent instance, and all three wrappers now chain with `from e` so the original traceback is not discarded either. loader.py has four copies of the '-bf16' branch, which disables 4bit, 8bit and fp8 when the resolved repo is a 16bit checkpoint. That is the right behaviour and it happened without a word, including when the caller had explicitly passed load_in_4bit=True. On a small card the consequence arrives much later as an out-of-memory failure during weight conversion, whose message mentions neither memory nor quantization, so there is no path back to the line that made the decision. Each site now says what it disabled, why, and what to do instead, and only when something was actually requested, so an ordinary 16bit load stays quiet. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply the same cause-preserving wrapper to the three sibling save paths A file search for the pattern found three more wrappers that render an exception with empty args as nothing at all: the q2_k_l quantize path, the GGUF conversion failure, and the convert-to-GGUF wrapper. Two of them also dropped the traceback. All three now use _describe_exception and chain with from e, and the helper moves above its first use rather than relying on module-level name resolution happening to work out. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Repair the two source-anchored tests and stop the -bf16 notice overclaiming The formatter change renamed the literals two tests anchor on, so both went red: test_offloaded_parameter_hint indexes 'Failed to save/merge model: {e}' and test_kaggle_gguf_error_message asserts 'GGUF conversion failed: {e}'. Both now accept either rendering, and the first scans every occurrence rather than the first, because _describe_exception's own docstring quotes those messages and would otherwise be matched instead of the call site. The -bf16 notice claimed a 16bit load even when the caller passed quantization_config=BitsAndBytesConfig(load_in_4bit=True). That object is only read into the local flags; it stays in **kwargs and is forwarded to Transformers, which quantizes anyway (loader.py reads it at 462, the only pop at 609 is gated on bitsandbytes being absent, and vision.py sets its own config only when the user supplied none). Clearing it would break on-the-fly quantization of a bf16 checkpoint, so the notice is suppressed instead and behaviour is unchanged. Also route the SIGKILL and Kaggle-disk GGUF branches through _describe_exception. A Kaggle Q8_0 export is the case that motivated the formatter, and those two were still printing a bare 'Error: ' for an exception with no args. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Tighten the comments added by this PR --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Two diagnostics found while building GPU CI coverage. Both sent me to the wrong place for long enough to be worth fixing.
A save failure that names nothing
save.pywraps save failures as:An exception whose
argsare empty formats as the empty string, so this renders as:A message ending at the colon with no cause in it. I hit this on a GGUF export and had to re-run the whole thing with a traceback capture purely to learn which call had failed.
_describe_exceptionalways leads with the exception type, so the class of failure survives even when the instance is silent. All three wrappers in the file now also chain withfrom e, so the original traceback is preserved rather than discarded.An explicit
load_in_4bit = Truedropped without a wordloader.pyhas four copies of the-bf16branch, which disables 4bit, 8bit and fp8 when the resolved repo turns out to be a 16bit checkpoint.Disabling is correct. Doing it silently is not: it happens even when the caller explicitly passed
load_in_4bit = True, and on a small card the consequence arrives much later as an out-of-memory failure during weight conversion. That failure mentions neither memory nor quantization, so there is no path back to the line that made the decision.Each site now reports what it disabled, why, and what to do instead, and only when something was actually requested, so an ordinary 16bit load stays quiet.
Notes
-bf16sites are edited identically; they are duplicated in the source, not factored.