unsloth/unsloth
andrewor14 cd24ea0e50 FP8: Load model on-the-fly in vLLM (#3717)
* FP8: Load model on-the-fly in vLLM

**Summary:** Existing support for `load_in_fp8=True` performs
an offline quantization when loading the initial model.
This is no longer necessary as of vllm==0.12.0 (after
https://github.com/vllm-project/vllm/pull/23014), where we
can quantize the model on-the-fly when we load it:

```
llm = LLM(
  ...
  hf_overrides={
    "quantization_config_dict_str": json.dumps(torchao_config),
  },
)
```

**Note:** Needs https://github.com/unslothai/unsloth-zoo/pull/380

**Test Plan:**
https://gist.github.com/andrewor14/5b85119fae46845d07b608d420907423

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix on-the-fly FP8: always check mapper first, fallback to on-the-fly

The original implementation bypasses the FP8 mapper entirely for
vllm >= 0.12.0, meaning models like Llama-3.2-1B-Instruct and Qwen3-8B
that have pre-quantized FP8-Block/FP8 checkpoints would never use them.

This fixes the priority order:
1. Mapper has a pre-quantized model -> use it (always)
2. Mapper has no match + vllm >= 0.12.0 -> on-the-fly FP8 via torchao
3. Mapper has no match + vllm < 0.12.0 -> offline quantization

Changes:
- loader_utils.py: Move vllm >= 0.12.0 check after mapper lookups
- loader.py: Set load_in_fp8=False when mapper resolves to a
  pre-quantized model to prevent double quantization

Tested on B200 with Llama-3.2-1B-Instruct and Qwen3-8B. Corrected code
produces results matching baseline (pre-quantized path preserved).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Hanchen <danielhanchen@users.noreply.github.com>
2026-02-10 05:10:13 -08:00
..
dataprep [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-01-08 11:35:21 +00:00
kernels [MoE] Improve moe kernels for unsloth fine tuning (#3812) 2026-02-05 06:03:25 -08:00
models FP8: Load model on-the-fly in vLLM (#3717) 2026-02-10 05:10:13 -08:00
registry Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" 2025-12-01 07:24:58 -08:00
utils Refactor Ollama template wiring and harden packing helpers (#3890) 2026-02-09 04:04:48 -08:00
__init__.py Fix triton 3.6.0 + torch 2.9.x torch.compile crash (missing cluster_dims) (#4001) 2026-02-08 20:18:25 -08:00
_auto_install.py Add PyTorch 2.10 and xformers 0.0.34 support (#3985) 2026-02-05 05:56:26 -08:00
chat_templates.py Refactor Ollama template wiring and harden packing helpers (#3890) 2026-02-09 04:04:48 -08:00
device_type.py Add missing import of inspect (#3778) 2025-12-25 18:43:59 -08:00
import_fixes.py Fix notebook compatibility for transformers 4.57.6 and TRL 0.22-0.27 (#3998) 2026-02-09 05:11:50 -08:00
ollama_template_mappers.py Refactor Ollama template wiring and harden packing helpers (#3890) 2026-02-09 04:04:48 -08:00
save.py add llama.cpp prefix to gguf conversion help messages (#4016) 2026-02-10 01:59:05 -08:00
tokenizer_utils.py Fix notebook compatibility for transformers 4.57.6 and TRL 0.22-0.27 (#3998) 2026-02-09 05:11:50 -08:00
trainer.py Fix notebook compatibility for transformers 4.57.6 and TRL 0.22-0.27 (#3998) 2026-02-09 05:11:50 -08:00