Skip to content

Carry the float8 training mode into the parallel capability query - #16637

Merged
danielhanchen merged 7 commits into
mainfrom
dh/registry-low-precision-mode
Nov 4, 2026
Merged

danielhanchen merged 7 commits into
mainfrom
dh/registry-low-precision-mode

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

The capability registry has two rules for low precision training, cp x precision and tp / pp x precision, and a low_precision feature. All three test q.mode in ("fp8", "nvfp4", "mxfp8"), but _mode(model) only ever returned lora, qlora or full. On a real model the rules never fired, so float8 training ran unguarded under pipeline parallel and context parallel. Tensor parallel only refuses fp8 checkpoint weights (tp_native._refuse_base), which does not cover fp8 LoRA bases or torchao Float8Linear, since both keep a 16-bit weight.

Change

unsloth/parallel_capabilities.py:

  • New _low_precision(model) returns "fp8" when the model carries one of the markers the float8 code actually sets:
    • _unsloth_fp8_lora_recipe (from mark_fp8_lora at load, before the adapters exist, for example SFTTrainer(peft_config = ...)), looked up through base_model / model like _fp8_lora_request;
    • a module with __dict__["_unsloth_fp8_lora"] (attach_fp8_lora_base);
    • a non-empty _unsloth_float8_linears, or a torchao Float8Linear module (convert_model_to_float8_training, full finetuning).
  • A request marker alone is not enough once enable_fp8_lora has run: when no layer was eligible it leaves an empty bases tuple and training stays in 16 bit, so that model keeps its 16-bit mode. _unsloth_float8_linears counts only as a non-empty list or tuple.
  • _mode checks it first. Without a marker the lora / qlora / full detection is unchanged.
  • NVFP4 and MXFP8 training have no converter yet (both are planned in precision/recipes.py, and resolve_float8_training refuses them by name), so nothing sets those modes. The rule predicates still list them.

Order at the entry points: the Trainer __init__ wrapper runs _parallel_capabilities_pre (which calls check_layout with the model) before the pipeline split and the tensor parallel apply in the same wrapper. Context parallel calls check_layout before the trainer __init__. So a refused launch leaves the model unsplit. One caveat: with UNSLOTH_TP_SIZE alone, sharded loading and get_peft_model shard the model before the Trainer exists. In that case the refusal comes at the Trainer, before training starts, not before the shard.

Behaviour change: mode is now fp8 for these models instead of lora / full, so they no longer match the LoRA / full-finetuning evidence cells. Without UNSLOTH_PARALLEL_STRICT=1 nothing changes for fp8 under DDP or FSDP2 (an unverified cell only refuses when gated). With strict on, fp8 under DDP or FSDP2 is now reported as unverified, since no cell carries fp8 evidence yet. The lora / full features only declare hooks, not exclusive ones, so the composition check loses nothing.

Testing

New tests/test_parallel_capabilities_precision.py, CPU only. It uses the tiny Qwen3 config with its widths raised to the fp8 minimum (dims % 16, otherwise no layer converts). The fp8 LoRA bases are attached through the real enable_fp8_lora(allow_cpu = True), and full finetuning goes through convert_model_to_float8_training with an emulated Float8LinearConfig. The test checks that cp 2, tp 2, pp 2 and cp 2 x tp 2 raise the precision rule with parameter data pointers, devices and dtypes unchanged, and that the Trainer pre-init check refuses under UNSLOTH_PP_SIZE / UNSLOTH_TP_SIZE before the split. It also checks that dp alone (DDP, FSDP2) is not refused, and that models without a marker keep full / lora / qlora.

Test Base (main) Head
test_parallel_capabilities_precision.py (rebased on current main) 14 failed, 5 passed (every refusal case: mode stays lora / full, no rule fires; the no-eligible-layer case passes on both, since main never reports fp8) 19 passed
test_parallel_env.py, test_context_parallel_compose_refusal.py, test_parallel_cp_compose_gloo.py, test_tp_native_oracle.py, test_float8_training.py, test_fp8_lora.py, test_precision_registry.py, test_float8_training_fsdp2_gloo.py all passed (only the new file fails) all passed (432 passed, 3 skipped on current main, with the new file)

GPU-marked tests were not run (CPU-only host session).

_mode only returned lora, qlora or full, so the cp x precision and
tp / pp x precision rules never matched a real model and float8 training
ran unguarded under context and pipeline parallel (tensor parallel only
refuses fp8 checkpoint weights). The query now reports fp8 when the model
was loaded with float8_training for LoRA, when fp8 LoRA bases are
attached, or when torchao Float8Linear layers are present. Models without
these markers keep the lora, qlora and full detection.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T10:59:25.396935Z 51dbbc6 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…not fp8

enable_fp8_lora leaves an empty bases tuple when no layer is eligible, so the request marker alone no longer
reports fp8. Also read _unsloth_float8_linears only as a non-empty list or tuple.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 51dbbc6c9f

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 4e9a0c4 into main Nov 4, 2026
@danielhanchen
danielhanchen deleted the dh/registry-low-precision-mode branch November 4, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant