Repository navigation
XPU bf16 on the current device, keep explicit bf16 on XPU, MLX full finetuning keeps its default dtype - #14493
Conversation
…inetuning keeps its default dtype - xpu_supports_native_bf16 judges the current XPU with its own probe validity, matching unsloth_zoo, so an unused non-native iGPU no longer turns a native dGPU to float16. - An explicit bf16 request on XPU stays bf16 (emulated if need be) in every loader, and the trainer autocasts a bf16 model in bf16 there, as before the native-bf16 probe. - MLX: no float16 default for full finetuning, which zoo would train in float32. - Test: scope the os.name patch so Python 3.13 pytest reporting does not see it.
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. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28c21f59a8
ℹ️ 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".
| index = 0 if torch.xpu.device_count() <= 1 else torch.xpu.current_device() | ||
| props = torch.xpu.get_device_properties(index) |
There was a problem hiding this comment.
Probe the XPU selected by the device map
When multiple XPUs are visible and the caller loads onto a non-current device, such as device_map="xpu:1", this probes whichever device was current during module initialization rather than the load destination. Explicit device maps are preserved without calling torch.xpu.set_device, so a native xpu:0 can make a model targeting an emulated xpu:1 default to bf16, while the inverse unnecessarily downgrades a native target to fp16. Derive the capability from the selected placement or retain the conservative all-visible result when the destination is not known.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4b44445. This answer is process-wide (it sets SUPPORTS_BFLOAT16 at import and drives the trainer's autocast), so it cannot know a later device_map. It is back to the conservative all-visible rule, as for CUDA: any visible XPU proven to lack native bf16 turns bf16 off, whichever device is current or targeted. What remains of the change is that each device is judged by its own aspects, so a device whose aspects all read False (no libocloc) is no longer counted as non-native because another device's aspects read True.
| index = 0 if torch.xpu.device_count() <= 1 else torch.xpu.current_device() | ||
| props = torch.xpu.get_device_properties(index) |
There was a problem hiding this comment.
Require the zoo release with matching XPU semantics
When users upgrade Unsloth while retaining the currently allowed unsloth_zoo>=2026.10.7, that zoo's _xpu_bf16_supported still scans every visible XPU, whereas this helper now checks only the current one. zoo_shares_xpu_bf16() gates only on the helper's existence, so heterogeneous-XPU hosts can have core load a model with one dtype while zoo's gradient-checkpointing and vLLM paths select another. Raise the dependency floor to the paired zoo release or explicitly distinguish the old helper behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
With 4b44445 core uses the same all-visible rule as zoo's existing _xpu_bf16_supported (on zoo main since #1894), so a newer core beside that zoo gives the same answer on every real host. The only difference is the per-device aspect check, which matters only if one XPU reads its SYCL aspects and another reads none in the same process; libocloc is found per process, so that does not happen in practice. Published unsloth_zoo 2026.10.7 has no _xpu_bf16_supported, so core keeps its old answer there, matching that zoo.
…ke CUDA [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4b44445f1c
ℹ️ 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".
| # XPU runs an explicit bf16 request (emulated if need be), as before the native-bf16 probe. | ||
| elif dtype == torch.bfloat16 and not SUPPORTS_BFLOAT16 and DEVICE_TYPE != "xpu": |
There was a problem hiding this comment.
Align DecisionTrainer with preserved XPU bfloat16
When FastDecisionModel loads a Clef model with an explicit dtype=torch.bfloat16 on an XPU without native bf16, it delegates to this path, so the model now remains bf16. However, decision.py::_clef_mixed_precision still derives its default from _clef_amp_dtype()/is_bfloat16_supported() and therefore enables fp16 autocast (lines 1083–1087); its evaluation paths make the same choice. This runs bf16 weights under fp16 autocast and can overflow or corrupt training and evaluation, so the decision-model precision helper also needs to follow an explicit bf16 model on XPU, as the updated RL path does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in aff9c67. On XPU, _clef_amp_dtype now follows a bf16 backbone (autocast bf16 over bf16 weights), and _clef_bnb_config keeps a bf16 compute dtype for an explicit bf16 request, matching the loaders and the RL path. CUDA and an fp16 load are unchanged. test_clef_keeps_an_explicit_bf16_model_in_bf16_on_xpu fails on the previous source.
…del on XPU [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
… keeps it too [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
…licit bf16 load kept on XPU
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Both files gain |
…tch vLLM's dtype when it refuses bf16 (unslothai#14606) ## Summary Follow-up to unslothai#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 - **Explicit bf16 plus the notebook idiom.** Since unslothai#14493 an explicit `dtype = torch.bfloat16` stays bf16 on an XPU without native bf16. The usual `fp16 = not is_bfloat16_supported()` then asks for fp16, and the generated trainer raised `TypeError: 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. - **vLLM refusing bf16 (Arc A770).** With `fast_inference = True`, when the installed vLLM refuses bf16 on this card (asked through the zoo helper from #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 (unslothai#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. - Base vs head (`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. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Summary
Follow-up to #14371 from a post-merge regression review. Pairs with the matching unsloth-zoo change so core and zoo keep one rule.
What changes
XPU_KEEPS_EXPLICIT_BF16with the matching vLLM change; without it (current zoo main) core downgrades to fp16 as main does, so vLLM and the HF weights it shares never end up in different dtypes.device_map, or vLLM's device) is not known when this is decided. Single-XPU and homogeneous hosts are unchanged.tests/test_cuda_device_order_warning.pyscopes itsos.namepatch (Python 3.13 + pytest 9).Tests