Repository navigation
Propagate fp8 block_size before the early return in get_lora_parameters_bias - #7189
Conversation
…rs_bias get_lora_parameters_bias set the fp8 block_size on W/W_quant only after the disable_adapters/merged early return, so on the merged or disabled path (merged inference, DPO reference model) a block-fp8 weight lost its real block_size and downstream fp8 kernels fell back to [128, 128]. The non-bias sibling get_lora_parameters already sets block_size before its early return; move the block so both behave the same.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e389aaceb1
ℹ️ 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 getattr(base_layer, "quant_method", None) == "fp8": | ||
| # we need to somehow store and pass this information :) | ||
| W.block_size = getattr(base_layer, "block_size", [128, 128]) | ||
| W_quant.block_size = W.block_size |
There was a problem hiding this comment.
Guard missing fp8 quant state before setting block_size
On the disabled/merged path this block now runs before the early return for every layer whose base_layer.quant_method == "fp8". For decompressed compressed-tensors layers the preceding code intentionally leaves W_quant as None when the live weight is bf16, as noted in the comment above, so this line raises AttributeError before fast_linear_forward can fall back to the plain matmul path; previously those disabled/merged layers returned successfully with W_quant is None. Please only attach block_size when a scale/quant state was actually found.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, this was a real regression and it is fixed in 6ec2121.
You are right about the mechanism: a decompressed compressed-tensors layer keeps quant_method == "fp8" while its weight is back to bf16, so the W.dtype in _FP8_WEIGHT_DTYPES guard above deliberately leaves W_quant as None. Moving the block ahead of the early return made W_quant.block_size run on the merged/disabled path for those layers, which raised AttributeError before fast_linear_forward could reach its if W_quant is None plain-matmul fallback. Reproduced against both revisions: upstream returns cleanly with W_quant is None, the first revision of this PR raised.
The block size is now only attached when a quant state was actually found:
if getattr(base_layer, "quant_method", None) == "fp8":
W.block_size = getattr(base_layer, "block_size", [128, 128])
if W_quant is not None:
W_quant.block_size = W.block_sizeThat keeps the original fix (a merged block-fp8 weight now carries its real [64, 128] instead of falling back to [128, 128]) while restoring the W_quant is None return for decompressed layers. Added a second regression test covering that path: it fails on the previous revision with the AttributeError you describe and passes now.
Note the sibling get_lora_parameters has the same unguarded W_quant.block_size on its own pre-return path, so it is exposed to this for a decompressed layer with an active adapter. I have left it alone to keep this PR focused, but happy to fix it here or in a follow-up if you prefer.
There was a problem hiding this comment.
Code Review
This pull request ensures that the FP8 block size is correctly propagated even when adapters are disabled or merged in the get_lora_parameters_bias function. By moving the block size assignment logic before the early return, the code ensures that downstream kernels receive the correct configuration. A new regression test has been added to verify this behavior. I have no further feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
A decompressed compressed-tensors layer keeps quant_method == "fp8" while its weight is back to bf16, so it has no quant state and get_lora_parameters_bias must still return W_quant None for fast_linear_forward to fall back to a plain matmul. Only attach block_size when a quant state was actually found.
ErenAta16
left a comment
There was a problem hiding this comment.
Confirmed the actual bug: the fp8 block_size propagation ran AFTER the disable_adapters or merged early return, so for the merged/inference-disabled path (the common case after merge_and_unload()), the function returned before ever setting W.block_size/W_quant.block_size. Since downstream fp8 kernels default to [128, 128] when the attribute is missing, any checkpoint with a non-default block size would silently use the wrong one on that path. Moving the propagation above the early return fixes it for both branches.
The if W_quant is not None: guard is a genuine second bug, not just defensive padding, a decompressed compressed-tensors layer keeps quant_method == "fp8" in its metadata but has no live quant state once it's back to bf16, so the old unconditional W_quant.block_size = ... would raise AttributeError on that layer instead of correctly falling through to W_quant is None.
Nice approach on the test file too, extracting just the target function via ast instead of importing the full package, keeps it runnable without a GPU/torch/bitsandbytes. Both scenarios (non-default block size surviving the merged path, and the decompressed-layer None case) are covered directly.
…g quant state Mirror the get_lora_parameters_bias guard so a decompressed compressed-tensors layer (quant_method fp8, bf16 weight, no quant state) does not raise AttributeError on the fused-LoRA path. Add a CPU-only regression test.
|
Confirmed this is a real fix, not a cosmetic one.
Validation I ran before merging:
Backwards compatibility: the common I pushed one follow-up commit (85d0d5e): the sibling |
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
Summary
get_lora_parameters_biasinunsloth/kernels/utils.pypropagates the fp8block_sizeontoW/W_quantonly after itsdisable_adapters/mergedearly return:So on the merged / disabled path (merged inference, DPO reference model) the block is dead code: a block-fp8 weight never gets its real
block_sizeattached, and the downstream fp8 kernels (fp8.py, which readgetattr(weight_scale, "block_size", [128, 128])) silently fall back to[128, 128]. A block-fp8 checkpoint whose real block size is not[128, 128]is then dequantized with the wrong block size.The non-bias sibling
get_lora_parametersalready setsblock_sizebefore its early return, so the two helpers disagree for the same layer.Fix
Move the fp8
block_sizeblock ahead of the early return, soget_lora_parameters_biasmatches the long-standing ordering ofget_lora_parameters. Common[128, 128]fp8 models are unaffected; the change only restores the correct block size for non-[128, 128]block-fp8 checkpoints on the bias/merged path.Test
Added
tests/python/test_get_lora_parameters_bias_fp8_block_size.py, a CPU-only test (auto-discovered bypytest tests/, no GPU). It AST-extractsget_lora_parameters_bias(unsloth needs a GPU to import) and, for a merged/disabled block-fp8 projection shippingblock_size = [64, 128], asserts that value survives onto the returned weight scale. It fails before this change (the block size drops to[128, 128]) and passes after.