Repository navigation
Gate XPU bf16 on native support, hint CUDA_DEVICE_ORDER on mixed NVIDIA hosts, read the Metal GPU family for MLX bf16 - #14371
Conversation
…_ID order, read Metal GPU family for MLX bf16
… as unsloth_zoo does
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. |
[skip ci]
|
@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". |
…ype from the GPU family, decision XPU AMP follows bf16 support, shell-specific order hint [skip ci]
|
@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". |
…inetuning keeps its default dtype (unslothai#14493) ## Summary Follow-up to unslothai#14371 from a post-merge regression review. Pairs with the matching unsloth-zoo change so core and zoo keep one rule. ## What changes - **An explicit bf16 request on XPU stays bf16 only beside the paired unsloth-zoo.** zoo publishes `XPU_KEEPS_EXPLICIT_BF16` with 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. - **Each visible XPU is judged by its own SYCL capability reads.** Before, one device whose aspects read True made another device whose aspects all read False (no libocloc there) count as non-native, which turned bf16 off. The answer stays process-wide like the CUDA one: any visible XPU proven to lack native bf16 still turns it off, since the load target (a `device_map`, or vLLM's device) is not known when this is decided. Single-XPU and homogeneous hosts are unchanged. - **An explicit bf16 request on XPU stays bf16** (emulated if needed), as before unslothai#14371, across the core loaders; the trainer autocasts a bf16 model in bf16 on XPU. - **MLX full finetuning on M1 / M2 keeps its previous default dtype.** The wrapper injected float16, which zoo's MLX loader promotes to float32 for full finetuning, doubling weight memory. float16 is now injected only for LoRA. - `tests/test_cuda_device_order_warning.py` scopes its `os.name` patch (Python 3.13 + pytest 9). - CUDA and HIP behaviour is unchanged (asserted). ## Tests - Related tests: 114 passed, 31 skipped; 16 fail against main's source. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Summary
Intel XPU bf16 now reflects native support on every visible XPU, with the same answer as unsloth_zoo's
device_is_bf16_supported(which the trainer reads). Mixed NVIDIA hosts get a one-timeCUDA_DEVICE_ORDERhint. MLX bf16 reads the Metal GPU family, so M1/M2 hosts behind a VM or a renamed device stop claiming bf16.What changes
device_type.xpu_supports_native_bf16()replacestorch.xpu.is_bf16_supported()in_gpu_init.py, which counts emulation and so is always True, and the hard-coded True inmodels/_utils.py. Its answers:has_bfloat16_conversions=FalseAND the SYCL aspect query is shown to work, meaning some aspect reads True on some device. SYCL answers aspects through libocloc, which torch-xpu wheels do not ship; without it every aspect reads False everywhere, so an all-False answer is treated as unknown and bf16 stays on.unsloth_zoo.device_type._xpu_bf16_supported(Detect native bf16 on Intel XPU and Apple MLX, fall back when XPU free memory is unreadable unsloth-zoo#1894). It applies only when the installed zoo has that helper: an older zoo still counts emulated bf16 for trainer AMP, gradient checkpointing and vLLM, so core keeps its previous XPU answer there and loading and training never disagree.device_type.cuda_order_mismatch_names()adds oneUnsloth:message at import when the visible NVIDIA cards differ andCUDA_DEVICE_ORDERis unset. Message only. An explicit order, includingFASTEST_FIRST, is the user's choice and stays silent. The suggested command matches the shell ($env:CUDA_DEVICE_ORDER = 'PCI_BUS_ID'on Windows).is_bfloat16_supported()decides by the Metal GPU family when MLX reports it:applegpu_g13/g14(M1 / M2) lack native bf16. Otherwise the existing M1/M2 name check decides, as in unsloth_zoo. The MLXFastLanguageModel/FastVisionModelloaders passdtype="float16"to zoo's loader when that check says no bf16 and the caller gave no dtype, so the default load matches.Hosts affected
CUDA_DEVICE_ORDERprint one extra line. Silent: single GPU, homogeneous, ROCm, and any host with the order set.Tests
tests/test_xpu_native_bf16.py: 1 and 2 XPUs that are native, proven non-native, without libocloc, older torch, or unreadable.tests/test_cuda_device_order_warning.py: mixed and homogeneous names, HIP, and each order value.tests/test_mlx_bf16_gpu_family.py: Apple families and names.