Skip to content

Block compile: find decoder layers structurally and wrap mixed stacks per class - #14397

Merged
danielhanchen merged 4 commits into
mainfrom
dh/s2-w3-discovery
Oct 20, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
dh/s2-w3-discovery

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

The per-decoder-layer compile (#10744) only found ModuleLists whose elements were one class named *DecoderLayer, so hybrid stacks and layers named *Block / *Layer never got it.

  • Lists found before are found and treated exactly as before.
  • New: lists of GradientCheckpointingLayer subclasses (mixed classes allowed) held next to a token embedding, outside vision / audio towers; without that base class, one class ending DecoderLayer / Block / Layer. Each class is wrapped once; the decision is per instance.
  • Newly compiled: gpt_neox, gpt2, the t5 decoder, olmo_hybrid, mllama text (self and cross attention), jamba attention layers, nemotron_h attention / MLP blocks.
  • Mamba-style SSM layers in the new lists stay eager (under a trace transformers replaces the CUDA scan kernels with its torch scan); UNSLOTH_BLOCK_COMPILE_SSM=1 opts in.
  • Shared layers count once; instances of a wrapped class outside the found lists (the T5 encoder) keep the stock forward; the dynamo recompile limit covers every layer kind of a class.

Tests

  • tests/test_block_compile_discovery.py (meta-device models from default configs, toy stacks): 18 of 23 fail on main, 24 pass here on torch 2.10, 2.13, 2.14 and transformers 4.57.6 / 5.17.
  • fp32 one-step parity, block compile on vs off (tiny random gpt_neox, gpt2, olmo_hybrid, mllama text, jamba, t5, LoRA): loss and grad norm within 1e-7 relative, 0 graph breaks (jamba: 2, its MoE experts stay outside the block as before).

Not covered

  • No step-time numbers for the newly covered architectures.
  • SSM opt-in not run on GPU.

…r class

Decoder layer lists were only found when every element was one class
named *DecoderLayer, so hybrid stacks (jamba, olmo_hybrid, mllama text)
and layers named *Block / *Layer (gpt2, gpt_neox, t5 decoder) never got
the per-block compile. Lists of GradientCheckpointingLayer subclasses
held next to a token embedding, outside vision / audio towers, are now
found too and wrapped per class. Lists the old rule found are unchanged.
Mamba-style SSM layers in the newly found lists stay eager unless
UNSLOTH_BLOCK_COMPILE_SSM=1, decided per layer. Shared layers count
once, instances of a wrapped class outside the lists keep the stock
forward, and the dynamo recompile limit covers every layer kind.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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-10-20T19:24:58.791649Z ba41d6e Manual request
🔒 Security Review ⚠️ Failed 2026-10-20T19:21:10.524268Z
We couldn’t complete this review. Comment @codex security review to try again.
ba41d6e PR opened
ℹ️ 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 danielhanchen self-assigned this Oct 20, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: ba41d6ec88

ℹ️ 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 c663d49 into main Oct 20, 2026
@danielhanchen
danielhanchen deleted the dh/s2-w3-discovery branch October 20, 2026 21:37
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