unsloth/unsloth
Daniel Han 9780cdcca1
Fix FlashAttention fp32 crash with DoRA (use_dora=True) (#6526)
* Fix FlashAttention fp32 crash with DoRA (use_dora=True)

DoRA upcasts lora_magnitude_vector to fp32 for the optimizer, which promotes
the q/k/v_proj output to fp32. FlashAttention only accepts fp16/bf16, so the
fp32 q/k/v raised 'FlashAttention only support fp16 and bf16 data type'.
Downcast q/k/v to the compute dtype before the flash kernels.

Fixes #1013

* Apply kwarg-spacing format hook to DoRA dtype test (pre-commit)

* DoRA+FA2: downcast any fp32 among Q/K/V and clamp to a flash-supported dtype

* Tighten code comments (no logic change)

---------

Co-authored-by: danielhanchen <michaelhan2050@gmail.com>
2026-06-23 01:29:19 -07:00
..
dataprep Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
kernels Windows installer: fix DiskPart UAC mid-install, drive-root cache, and spurious unsloth.exe rename warning (#6296) 2026-06-22 03:09:08 -07:00
models Fix misleading 'only for image models' error for Qwen3-VL when torchvision is missing (#6525) 2026-06-23 01:28:09 -07:00
optimizers Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
registry Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
utils Fix FlashAttention fp32 crash with DoRA (use_dora=True) (#6526) 2026-06-23 01:29:19 -07:00
__init__.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
_auto_install.py Upgrade setuptools and wheel in the auto-install command (#6282) 2026-06-13 03:59:15 -07:00
_gpu_init.py Shim removed vllm.transformers_utils.tokenizer so fast_inference works on vLLM >= 0.22 (#6390) 2026-06-17 17:25:41 -07:00
chat_templates.py Strip trailing whitespace in construct_chat_template (fixes #992) (#6008) 2026-06-11 07:08:34 -07:00
device_type.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
import_fixes.py Suppress only torchao's cosmetic cpp-extensions warning (#6506) 2026-06-22 02:28:30 -07:00
ollama_template_mappers.py Re-apply #4939: updated models template mappers (#4950) 2026-04-15 07:52:12 -07:00
save.py Fix save crash for legacy list-form _tied_weights_keys (NemotronH) (#6540) 2026-06-22 02:11:46 -07:00
tokenizer_utils.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
trainer.py Reset torch.compile cache poisoned by a stray forward before trainer.train() (#6511) 2026-06-22 05:39:48 -07:00