Skip to content

[1/6] refactor(draft): move draft layer components under modeling/draft/layers - #1025

Open
maocheng23 wants to merge 2 commits into
mainfrom
maocheng/pr1023-1-move
Open

maocheng23 wants to merge 2 commits into
mainfrom
maocheng/pr1023-1-move

Conversation

@maocheng23

@maocheng23 maocheng23 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

The first step in splitting #1023. This PR only moves files, so reviewing it means checking renames and import paths.

Modifications

  • specforge/layers/{embedding,linear,lm_head,ring} → specforge/modeling/draft/layers/
  • modeling/draft/{flex_attention,flex_attention_backend}.py → modeling/draft/layers/attention/backends/
  • generate_eagle3_mask → modeling/draft/eagle3_mask.py
  • modeling/draft/llama3_eagle.py → modeling/draft/eagle3.py
  • LlamaMLP → layers/ffn/dense.py:GatedMLP, still importable as eagle3.LlamaMLP
  • tests/test_layers → tests/test_modeling/test_layers (test_decoder.py → test_ring_attention.py, since it tests ring attention)
  • Import updates in benchmarks, providers, PEagle, DFlash, tests, and CODEOWNERS

A second, separable commit keeps the old import paths working for one release. specforge.layers.*, draft.llama3_eagle and draft.flex_attention_backend resolve to the same module objects as the new paths, so registries, class identity and mock.patch targets are unchanged. draft.flex_attention re-exports the helpers and generate_eagle3_mask. All of them emit a DeprecationWarning. Drop commit 2 if a clean break is preferred.

Accuracy Test

No numerical change. git diff -M origin/main shows renames plus import edits only.

tests/test_modeling on CPU (torch 2.14, transformers 5.12): 158 tests, 23 skipped, 4 errors. The 4 errors are the moved TP/ring tests failing to import sglang/yunchang, which aren't installed in that environment; they import those at module level, both before and after the move. test_moved_import_paths.py covers the shims.

Stack

This is part of a split of #1023 (by @jiapingW) into reviewable layers. Each PR targets the branch of the previous one, and only its own commits show in the diff.

  1. [1/6] refactor(draft): move draft layer components under modeling/draft/layers #1025: Move draft layer components (pure move + legacy-import shims) 👈 this PR
  2. [2/6] refactor(draft): extract GQA/MLA attention into reusable layers #1026: GQA/MLA attention extraction (bit-exact parity test)
  3. [3/6] feat(draft): residual hooks with Qwen GR and DeepSeek-V4.1 mHC #1027: Residual hooks + GR + mHC
  4. [4/6] feat(attention): unify visibility across dense attention backends #1028: Visibility unified across dense backends (behavior change)
  5. [5/6] feat(attention): sparse attention and SWA interfaces #1029: Sparse attention / SWA interfaces
  6. [6/6] feat(attention): DSA and QSA draft attention training #1030: DSA and QSA training

The code is @jiapingW's from #1023 (commits are authored by them). The split adds a parity test, legacy import shims, and two fixes in the visibility PR, each noted in the PR it belongs to.

🤖 Generated with Claude Code

jiapingW and others added 2 commits October 27, 2026 13:30
Pure relocation, no behavior change. Split from #1023.

- specforge/layers/{embedding,linear,lm_head,ring} -> specforge/modeling/draft/layers/
- modeling/draft/{flex_attention,flex_attention_backend}.py -> layers/attention/backends/
- generate_eagle3_mask -> modeling/draft/eagle3_mask.py
- modeling/draft/llama3_eagle.py -> modeling/draft/eagle3.py
- LlamaMLP -> layers/ffn/dense.py:GatedMLP (re-exported from eagle3 as LlamaMLP)
- tests/test_layers -> tests/test_modeling/test_layers (test_decoder.py -> test_ring_attention.py)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
specforge.layers, modeling/draft/{llama3_eagle,flex_attention,flex_attention_backend}
now resolve to the relocated modules (same module objects, so registries and
class identity are preserved) and emit a DeprecationWarning. This commit can
be dropped if a clean break is preferred.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Oct 31, 2026
The five commits before this one carry sgl-project#1025 to sgl-project#1028 (draft layers
moved, GQA/MLA attention components with the layer factory, residual
kinds, visibility). This commit reconnects the MoE FFN to them:

- layers/factory.py: build_ffn takes the layer index and delegates to
  the MoE package's switch, so moe_preset and ffn_layer_types work again.
- layers/decoder.py: DecoderLayer.forward takes moe_token_mask and hands
  it to an MoELayer as its second argument; dense MLPs keep one argument.
- dflash.py: pass the layer index and the mask; DFlash2 already calls
  _ffn. The one test that used the old build_ffn signature is updated.

Temporary until sgl-project#1025 to sgl-project#1028 land on main; then this stack rebases
onto them and only this commit is replayed.
yushengsu-thu added a commit to yushengsu-thu/SpecForge that referenced this pull request Nov 4, 2026
The five commits before this one carry sgl-project#1025 to sgl-project#1028 (draft layers
moved, GQA/MLA attention components with the layer factory, residual
kinds, visibility). This commit reconnects the MoE FFN to them:

- layers/factory.py: build_ffn takes the layer index and delegates to
  the MoE package's switch, so moe_preset and ffn_layer_types work again.
- layers/decoder.py: DecoderLayer.forward takes moe_token_mask and hands
  it to an MoELayer as its second argument; dense MLPs keep one argument.
- dflash.py: pass the layer index and the mask; DFlash2 already calls
  _ffn. The one test that used the old build_ffn signature is updated.

Temporary until sgl-project#1025 to sgl-project#1028 land on main; then this stack rebases
onto them and only this commit is replayed.

This branch has not been deployed

No deployments
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.

2 participants