Repository navigation
XPU: train an explicit bf16 load in bf16 under the fp16 idiom, and match vLLM's dtype when it refuses bf16 - #14606
Conversation
…om; load fp16 when vLLM refuses bf16
…g and its vLLM agree on dtype
|
@codex review |
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7576db78e
ℹ️ 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 ( | ||
| dtype == torch.bfloat16 | ||
| and DEVICE_TYPE == "xpu" | ||
| and fast_inference | ||
| and is_vLLM_available() | ||
| and xpu_vllm_refuses_bf16() |
There was a problem hiding this comment.
Preserve forced-float32 models when vLLM rejects bf16
When FastModel loads a FORCE_FLOAT32 architecture such as Gemma 3/4 or Qwen3.5 on an affected XPU with fast_inference=True, the outer loader has deliberately changed the default fp16 dtype to bf16 and set UNSLOTH_FORCE_FLOAT32 because these models produce NaN gradients in float16. This gate unconditionally changes that bf16 back to fp16; the resulting dtype is then passed to both load_vllm and convert_vllm_to_huggingface, defeating the forced-float32 safeguard and risking corrupted training. This combination should be rejected or fall back from vLLM rather than loading the shared weights as fp16.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed: for a model loaded under UNSLOTH_FORCE_FLOAT32 (float16 gives NaN gradients) a vLLM refusal of bf16 now raises before loading, telling the user to load with fast_inference = False, instead of switching both sides to fp16 (test_a_forced_float32_model_refuses_to_load_in_fp16, for llama.py and vision.py).
|
@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". |
…sed decode RoPE kernels (#14632) `tests/utils/test_single_row_cached_attention.py` fails all 64 cases on main, in the Core jobs' "generation correctness guards (HARD GATE)" step (e.g. #14606, job 119685454271; reproduced on main `0ae76cc9f7`): ``` NameError: name 'decode_rope_inplace' is not defined ``` The test rebuilds `LlamaAttention_fast_forward_inference` and `Qwen3Attention_fast_forward_inference` from source inside a hand-written namespace. #14599 made them call the fused decode kernels `decode_rope_inplace` (llama) and `decode_qk_norm_rope` (qwen3), which that namespace did not have. The product is fine: both are imported in the real modules. ## Change - Both names are added with their CPU behaviour: the real functions return `False` / `None` (nothing written) as soon as the tensors are not on CUDA, and the unfused path runs. That is the path this test has always exercised. - The fixture now lists the decode function's free names and fails with one clear message if any is not supplied, instead of a `NameError` in every parametrized case the next time a dependency is added: ``` Qwen3Attention_fast_forward_inference now reads ['decode_qk_norm_rope']; give the harness a CPU stand-in for each ``` The test's rotary stub is the identity (cos 1, sin 0), so it checks masking and the KV cache rather than RoPE. The fused kernels' own correctness is covered by `tests/test_decode_fused_rope.py` on CUDA. ## Testing - CPU torch 2.10: main 64 failed; this branch 64 passed. - Removing the qwen3 stand-in fails the fixture with the message above.
…FLOAT32, so a stale value from an earlier load no longer refuses it [skip ci]
|
Follow-up from a re-review: the vLLM bf16 gate in |
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
…evice bf16 probe, drop the #1894-zoo pooling (no zoo release had it)
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 58b27e42d3
ℹ️ 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".
| and is_vLLM_available() | ||
| and xpu_vllm_refuses_bf16() | ||
| ): | ||
| if os.environ.get("UNSLOTH_FORCE_FLOAT32", "0") == "1": |
There was a problem hiding this comment.
Reject unsafe fp16 fallback for explicit bf16 family loads
When a user explicitly loads Gemma 3/4 or Qwen3.5 with dtype=torch.bfloat16 and fast_inference=True on an XPU where vLLM rejects bf16, this guard still allows the unsafe fp16 fallback. The additional evidence is in FastModel.from_pretrained (unsloth/models/loader.py:2968–2985): it resets UNSLOTH_FORCE_FLOAT32 to "0" and deliberately leaves it unset for an explicit bf16 request, even for these float16-unsafe architectures. Consequently, the new exception protects the default-dtype case but not explicit bf16 loads, which now reach vLLM and the shared HF weights as float16 and can produce NaN gradients. Check the architecture's float16 restriction independently of whether this particular load activated forced-float32 mode.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 05fcfb3: FastModel now refuses a bf16 fast_inference load of a FORCE_FLOAT32 family on XPU when vLLM refuses bf16, also for explicit bf16 and auto dtype on native-bf16 cards; tests/test_xpu_vllm_refuses_bf16.py covers it.
…ails early instead of dropping to fp16 when vLLM refuses bf16 [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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
Follow-up to #14493 from a post-merge review, paired with unslothai/unsloth-zoo#1947. Two cases where loading, training and vLLM disagreed on dtype on Intel XPU.
What changes
dtype = torch.bfloat16stays bf16 on an XPU without native bf16. The usualfp16 = not is_bfloat16_supported()then asks for fp16, and the generated trainer raisedTypeError: Model is in bfloat16 precision but you want to use float16. On XPU, when the card has no native bf16 and the model is bf16, training now uses bf16 mixed precision with a notice. Every other device and combination keeps today's check, including CUDA, ROCm, MPS, a native-bf16 XPU with an explicit fp16, and forced float32.fast_inference = True, when the installed vLLM refuses bf16 on this card (asked through the zoo helper from [RunPod] - llama_model_load: error loading model: error loading model vocabulary: cannot find tokenizer merges in model file #1947), the Hugging Face side loads fp16 before loading, so RoPE caches, the bnb compute dtype and the post-patch dtype match the weights vLLM shares. A model family that cannot train in fp16 (Gemma 3/4, Qwen3.5 and the rest of FORCE_FLOAT32) fails early with a clear message instead, whether bf16 was explicit, automatic or forced. With an older unsloth_zoo the helper is missing and nothing changes.Only XPU paths change. The native bf16 probe itself is main's (#14769, judged on the XPU in use, matching unsloth-zoo#1985); an earlier revision of this PR pooled aspects beside the #1894 zoo, which was dropped on merging main since no unsloth_zoo release ever shipped that function (2026.10.7 predates it, 2026.10.8 already has #1985).
Tests
tests/test_xpu_explicit_bf16_trainer_precision.py(9 cases): XPU without native bf16 + bf16 model + fp16 asked trains bf16; CUDA, HIP, MPS, native-bf16 XPU with explicit fp16 and forced float32 keep today's outcome.tests/test_xpu_vllm_refuses_bf16.py: refused gives fp16 on the HF side for a vLLM load only, accepted keeps bf16, missing zoo helper changes nothing, forced float32 vision fails early, a stale float32 env does not fail a language model load, and the FastModel family gate refuses fp16 for FORCE_FLOAT32 families only when vLLM refuses bf16 on XPU.test_differential.py): 6 FIXED, 7 unchanged negative controls, 0 head failures. Related XPU / precision suites: 165 passed.Not run on a real XPU or A770.