Repository navigation
FP8 block dequant on gfx11 ROCm: route fp16 output to the byte decoder too - #15224
Merged
danielhanchen merged 4 commits intoNov 14, 2026
Merged
Conversation
danielhanchen
added a commit
that referenced
this pull request
Oct 25, 2026
…15269) 16 cases in `tests/test_fused_preference_loss.py` fail in `Repo tests (CPU, rest)` on PRs based on current main, for example #15224 and #15245: every `test_orpo_cpo_match_trl` case plus the DDP / FSDP1 / hook fallback cases. The reference run trips the hidden-states counter (`assert (1 >= 1) == False`) or the dtype check. ## Cause The test, not the product. The test builds its reference from `from trl.experimental.orpo import ORPOTrainer` (and the CPO / DPO equivalents). Unsloth's RL patch rebinds those names, and the defining module's attribute, to the generated `UnslothORPOTrainer` (`unsloth/models/rl.py`, the `trl.{name} = created_module.Unsloth{name}` lines). Since #14185, that generated class's `concatenated_forward` routes through `unsloth_fused_orpo_concatenated_forward`. So once TRL has been patched in the process, the "TRL" side of the comparison is the code under test. The stack of the reference forward shows it: `test_fused_preference_loss.py:437 -> unsloth_compiled_cache/UnslothORPOTrainer.py:1988`. It reproduces locally with unsloth-zoo main on the path (16 failed, 9 passed, run alone). With the older installed zoo 2026.10.7, TRL is not rebound here, which is why it looked like an ordering leak at first. ## Fix - `_trl_trainer(name)` loads TRL's own trainer module from its file under a private module name in the same package, so TRL's relative imports still resolve and nothing Unsloth rebinds is reused. - It asserts that the class it returns is not an `Unsloth*` class. - ORPO, CPO and DPO all take their reference from it. ## Verification - `tests/test_fused_preference_loss.py` against unsloth-zoo main: 16 failed, 9 passed on main; 25 passed here. - Against the installed zoo 2026.10.7: 25 passed on both main and this PR. - Sabotage on the product: scaling the fused ORPO path's `chosen_logps` by 1.001 in `unsloth/models/dpo.py` fails all 10 `test_orpo_cpo_match_trl` cases.
…r too _hip_bytes_dequant kept fp16 on the torch loop because the gfx1151 byte decoder rounded fp16 unlike that loop (unslothai#14936). unslothai#14992 made both dequant kernels round to fp16 with integer ops on ROCm, bit-equal to the loop and on by default there, but left this gate as it was, so ragged / rectangular block weights dequantised to fp16 on gfx11 still took the ~7x slower torch loop while bf16 / fp32 took the kernel. Gate fp16 on that rounding instead: with UNSLOTH_FP8_EXACT_F16_ROUND=0 the torch loop keeps the route. Co-Authored-By: Claude Fable 5.1 <[email protected]>
lonexreb
force-pushed
the
fix/fp8-hip-bytes-dequant-fp16-route
branch
from
October 31, 2026 23:30
eb2bb3c to
5721036
Compare
…ounding is on [skip ci]
Member
|
@codex review |
1 similar comment
Member
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
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". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
_hip_bytes_dequantinunsloth/kernels/fp8.pystill refusesout_dtype = torch.float16, with the comment "on gfx1151 the byte decoder rounds fp16 differently from the torch loop". That was true when #14936 moved the ragged / rectangular gfx11 cases to the byte decoder for bf16 / fp32 only. #14992 then made both dequant kernels round to fp16 with integer ops on ROCm, bit-equal to_torch_blockwise_dequant(itstest_dequant_kernels_match_torch_loop_fp16[bytes-1]pins that) and on by default there (_FP8_EXACT_F16_ROUND = torch.version.hip is not None), and described itself as closing the gap #14936 left. The gate was not updated, so on gfx11 a block-FP8 weight dequantised to fp16 still takes the torch loop (~7x slower per #14936) while bf16 / fp32 take the kernel. Same outputs either way; this is the speed path the rounding work was done for.How
Gate fp16 on the rounding that makes it exact instead of excluding it outright:
So the ROCm default and
UNSLOTH_FP8_EXACT_F16_ROUND=1route fp16 through the byte decoder;=0(the plain cast ROCm Triton fuses intov_fma_mixlo_f16) keeps the torch loop. bf16 / fp32 are unchanged, and nothing changes on NVIDIA, wheretorch.version.hip is Noneshort-circuits before this gate.Verification
tests/test_fp8_pre_sm89_byte_dequant.py::test_hip_bytes_dequant_takes_fp16_once_its_rounding_is_exact(new, CPU): with the arch probe and the HIP switch patched on, fp16 routes with bf16 under=1and falls back under=0.test_rocm_routes: the fp16 row now asserts the byte decoder under=1and the torch loop under=0(it was pinned to the torch loop with the stale rationale).Lifted
_hip_bytes_dequant+_fp8_exact_f16_roundfrom main's file vs this branch,_FP8_EXACT_F16_ROUND = Trueas on ROCm:UNSLOTH_FP8_EXACT_F16_ROUND10No ROCm hardware here: the gfx11 fp16 bit-equality rests on #14992's own test, and the GPU-gated route test ran only in CI.
ruff check,enforce_kwargs_spacing.pyand theruff-format-with-kwargshook pass;fp8.pyparses under Python 3.9.🤖 Generated with Claude Code