Repository navigation
[XPU] Enable FP8 training on XPU - #12535
Conversation
|
Two reds on head |
|
The new |
|
Confirmed the FP8 device check in unsloth/models/_utils.py still rejects XPU on main, so this unblocks load_in_fp8 on Intel GPUs. Could you switch the three modelopt FP8 tests to gate on has_real_cuda() so the skip-guard check goes green? |
* Add xpu path in verify_fp8_support_if_applicable * Update FP8 test to be device agnostic to support XPU hardware
f2d49c3 to
ae965ec
Compare
|
Ok, switched the three modelopt FP8 tests to gate on has_real_cuda(). |
|
Review record for #12535, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#387. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
What This PR Does
Unsloth already supports FP8, this PR just adds an XPU path to unblock Intel GPUs when training with
load_in_fp8=True. The results from the Validation section show that FP8 training uses less memory, but has lower token/s compared to bf16. XPU does not supportfbgemm, so this only verifies that XPU reaches the fallback path with less VRAM overhead.To verify the FP8 on XPU, this PR also adds Intel XPU compatibility for FP8 related tests found under
tests/. The results are shown under Validation section.Changes
In
verify_fp8_support_if_applicable, added thexpuoption:From the code, the XPU paths will follow:
Path 1 - Rowwise path
Case:
unsloth/Llama-3.2-1B-FP8-Dynamic— usesquant_method="compressed-tensors", and weights strategychannelTo verify this path, the env var
UNSLOTH_COMPRESSED_TENSORS_FP8_KERNELS=1was set for the FP8 kernels opt-in. This var was added in commit 9d15a59FbgemmFp8Linear_matmulclass calls_probe_fp8_rowwise_backendfunction which resolves rowwise backend totorch._scaled_mmsince XPU does not have fbgemm_gpu available.Path 2 - Block path
Case:
unsloth/Qwen3-0.6Bwithload_in_fp8=TrueIn
FP8BlockQuantLinearclass and runsact_quantTriton path.Validation
FP8 Trace Test
I have included the run results for a trivial fp8 trace test to capture some predefined ops (found in
unsloth/kernels/fp8.py) using the following models on XPU.No validation results for NVIDIA A100 because it does not meet the compute requirement to support fp8.
Environment:
unsloth/Qwen3-0.6B(withload_in_fp8=True)unsloth/Llama-3.2-1B-FP8-Dynamic(withUNSLOTH_COMPRESSED_TENSORS_FP8_KERNELS=1)quant_methodfp8compressed-tensors[128, 128]channel(rowwise)_scaled_mmFP8BlockQuantLinear.forwardact_quantfp8_block_matmul_blockwise_weight_dequant_any_shapeweight_dequant_blockweight_dequantfbgemm_fp8_linearFbgemmFp8Linear_matmul.forwardtorch._scaled_mmtorch_matmulFP8 SFT LoRA
To verify FP8 path correctly fallbacks on XPU, I ran a simple SFT LoRA finetuning script on both models to cover both forward paths.
Both paths show that FP8 has lower peak memory and lower token/s.
Config:
max_steps- 10batch size- 1unsloth/alpaca-cleanedResults for
unsloth/Qwen3-0.6B(block path):grad_normgrad_normResults for
unsloth/Llama-3.2-1B-FP8-DynamicwithUNSLOTH_COMPRESSED_TENSORS_FP8_KERNELS=1(rowwise path):grad_normgrad_normFP8 Test Validation
Added Intel XPU compatibility for existing FP8 related tests and ran them to verify FP8 does not raise any errors on XPU.
Modified tests files are validated by running the pytest command:
Summary:
200 passed, 24 skippedAll skipped tests are expected as CUDA-only tests:
tests/test_compressed_tensors_fp8_kernel_route.py::test_decode_gemv_matches_the_dequantized_matmulx18 (gemvis CUDA-only)tests/test_compressed_tensors_fp8_kernel_route.py::test_decode_gemv_refuses_what_it_cannot_compute(gemvis CUDA-only)tests/test_fp8_rowwise_backend.py::test_every_backend_matches_reference[fbgemm](fbgemmis CUDA-only)tests/test_fp8_rowwise_backend.py::test_quantize_matches_fbgemm(fbgemmis CUDA-only)tests/test_fp8_fbgemm_block_shapes.py::test_output_tile_grid_battery_matches_reference(fbgemmis CUDA-only)tests/test_modelopt_fp8_loading.py::test_transformers_without_per_tensor_fp8_keep_the_config(reason: this transformers loads per-tensor fp8)Remaining Work
gemvcan be supported in XPU as it is currently CUDA gated incan_use_fp8_rowwise_gemv. My plan is to benchmark the speeds with thescaled_mmanddequant + matmulfallback.Please let me know if any additional info is needed to verify this, thanks.