Skip to content

Pipeline parallel: DeepSeek-V4.1 LoRA cells with gloo evidence, and a text-only model over a composite config is not multimodal - #18037

Merged
danielhanchen merged 5 commits into
mainfrom
pp-deepseek-v41-lora
Nov 17, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
pp-deepseek-v41-lora

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

DeepSeek-V4.1 (native DeepseekV41ForCausalLM) under UNSLOTH_PARALLEL="pp=2" was refused at trainer init:

Unsloth: composition: this cell has no numeric parity / engagement / compile evidence yet: no supported cell covers it (... family='deepseek_v41' ...)

The pipeline machinery itself was already on main (#17785): stages run through the model's own pipeline_stage_forward, cuts land only where pipeline_handoff_keys is empty (no CSA / KV group state crosses a stage), each engram table lives on the stage that owns its layer, and the mHC residual streams plus the next sublayer's mixing weights are carried between stages. What was missing:

  1. Registry: no MoE row for deepseek_v41, so every pp layout fell to "no supported cell".
  2. Multimodal misread (pp_native._media_keys): the release config keeps a vision_config, but the class has no tower and its forward takes no image input. Past the registry, PP asked for PPConfig(text_only = True) and then refused for want of towers. A media config key now counts only when the forward names a media input. A model whose forward cannot be read keeps the old path, and towers left beside the decoder are still refused.
  3. _kernels misread: the native port's own DeepseekV41Attention (under unsloth/models/deepseek_v41/modeling.py) was read as Unsloth's fast kernels, so on CPU the query said kernels=True, loss=fused_ce.

Evidence (CPU gloo, fp32, vs one process)

tests/test_parallel_deepseek_v41_gloo.py::test_deepseek_v41_parallel_matches_one_process: losses, every LoRA gradient and the saved adapter.

case schedule micro-batches checkpointing routed expert LoRA
pp2_gpipe gpipe 2 off no
pp2_1f1b 1f1b 2 off no
pp4_gpipe_mb4 gpipe, 4 stages 4 off no
pp2_gpipe_mb4_gc (new) gpipe 4 zoo replay, non-reentrant no
pp2_1f1b_gc (new) 1f1b 2 zoo replay, non-reentrant no
pp2_gpipe_experts (new) gpipe 2 off yes (target_parameters)
pp2_1f1b_experts_gc (new) 1f1b 2 zoo replay yes

Engagement, asserted in every pp case: one pipeline_stage_forward call per micro-batch and step on each rank; each rank holds and steps only its own layers' adapters; every layer is owned exactly once; engram tables are real only on the owning stage; under checkpointing the zoo replay ran. The gloo config now carries the release's vision_config.

Flips that must fail:

  • test_pp_reentrant_checkpoint_without_the_replay_breaks_parity: a plain reentrant checkpoint without the replay builds the shared KV under no_grad, so kv_proj gradients are wrong.
  • test_pp_cut_at_an_unsafe_layer_breaks_parity (existing): a stage cut inside a KV / indexer sharing group raises KeyError on the missing group state.

DeepSeek-V4.1 has no router auxiliary loss, so there is no aux term to carry.

Cells added: MoE deepseek_v41 x {lora, lora+experts} x aux off x pp, eager attention, gpipe / 1f1b, memory none / gc / unsloth_offload (Unsloth's offloading checkpoint runs the same zoo replay). Compile evidence: eager, no compiled region. QLoRA and full finetuning under pp stay refused.

Tests

Base = 20d05c2, same venvs, CUDA_VISIBLE_DEVICES= (CPU).

suite transformers 4.57.6 transformers 5.22.1
new registry tests (7) base 7 failed, head 7 passed base 7 failed, head 7 passed
test_parallel_deepseek_v41_gloo.py head 28 passed head 28 passed
PP suites (test_pp_native, test_pp_env, test_pp_moe_aux, test_pp_vlm_text_only, test_pp_gemma4_per_layer) plus the file above head 80 passed, 2 skipped head 102 passed

Pre-existing on base and head alike: test_parallel_capabilities_latent_sinks.py (2, transformers 4.57.6) and the float8 cases of test_parallel_capabilities_precision.py (10, no torchao in the 5.22.1 CPU venv).

End to end through SFTTrainer on CPU (gloo, fp32, frozen tables on disk), tiny DeepSeek-V4.1 copy, per-step loss:

run step 1 step 2 step 3 step 4
one process 11.859791 11.778872 11.483759 11.505252
pp=2 11.859791 11.778872 11.483751 11.505269
pp=2, use_gradient_checkpointing = "unsloth" 11.859791 11.778872 11.483751 11.505269

Kaggle 2x T4 (fake DeepSeek-V4.1-Flash, 16-bit LoRA, docs harness)

unsloth/DeepSeek-V4.1-Flash-1017 shrunk to a random-weight copy (real config, engram tables, mHC, compress ratios), seq 1024, global batch 8 rows, 25 steps, fp16, use_gradient_checkpointing = "unsloth", adamw_8bit, torch 2.14.1, transformers 5.17.0.

arm result steady tok/s peak reserved per GPU
base 20d05c2, 1 GPU trains 618 3.89 GB
base 20d05c2, pp=2 refused at trainer init (no numeric parity / engagement / compile evidence) - -
head, pp=2 trains, 25 steps 621 2.76 GB / 3.77 GB

Per-step loss, pp=2 against 1 GPU: largest gap 0.0014 (step 17), step 1 12.0205 vs 12.0204. The 1-GPU and base pp rows come from an earlier job of the same harness on the same build; head ran the pp arm only.

pp=2 is not faster than one T4 at this size: the second stage idles through the gpipe bubble. Its use is fitting a model whose layers do not fit one card.

… not multimodal

The native DeepSeek-V4.1 config keeps the release's vision_config, but
DeepseekV41ForCausalLM has no tower and its forward takes no image input.
pp_native read the config key alone, asked for PPConfig(text_only = True) and
then refused for want of towers. A media config key now counts only when the
model's forward names a media input; a multimodal model whose forward cannot be
read keeps the old path, and towers left beside the decoder are still refused.
The registry had no MoE row for deepseek_v41, so pp=2 was refused with
"no numeric parity / engagement / compile evidence". The stage forward, cut
points, per-stage engram tables and carried mHC streams were already in
pp_native; this adds the evidence and the cells:

- parity: pp2 gpipe / 1f1b, pp4, interleaved and ZBV vs one process in fp32
  (losses, every LoRA gradient, saved adapter), now also with zoo's
  non-reentrant checkpoint replay (gpipe 4 micro-batches, 1f1b) and with LoRA
  on the routed experts (target_parameters).
- engagement: one pipeline_stage_forward call per micro-batch and step, each
  rank holds only its own layers' adapters, every layer owned once, the replay
  ran under checkpointing.
- flip: a plain reentrant checkpoint without the replay leaves kv_proj
  gradients wrong; the existing unsafe-cut flip still raises.
- the gloo config carries the release's vision_config.

Cells: deepseek_v41 x lora and lora+experts x aux off x pp, eager attention,
memory none / gc / unsloth_offload (the same replay runs under Unsloth's
offloading checkpoint). QLoRA and full stay refused.

_kernels no longer reads a native port's own attention
(unsloth/models/<name>/modeling.py) as Unsloth's fast kernels; on CPU it
marked DeepSeek-V4.1 as kernels / fused_ce.
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T22:49:47.515113Z bfbda8f 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: bfbda8fbaa

ℹ️ 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 0d4793e into main Nov 17, 2026
@danielhanchen
danielhanchen deleted the pp-deepseek-v41-lora branch November 17, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant