Skip to content

[Refactor] Rename layer boundary protocols, contracts and helpers - #41750

Merged
ch-wan merged 3 commits into
mainfrom
cheng/refactor/layer-boundary-naming
Sep 30, 2026
Merged

ch-wan merged 3 commits into
mainfrom
cheng/refactor/layer-boundary-naming

Conversation

@ch-wan

@ch-wan ch-wan commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

This PR is part of a stack (oldest at bottom):

Motivation

Several names in layers/layer_boundary did not say what the object does, and one concept often had several words:

  • StageUpdate / StageRead are the operations that write a producer's output into the residual and read a consumer's input from it; LayerResidual is a bundle of those operations, not a tensor.
  • An unfinished sum was "left", "carried" or "handed on"; "handoff" meant a MoE finalize, the rows a layer hands on, and the attention input hook.
  • StageDecl and StageDeclaration differed by one abbreviation but are different layers.
  • Entry steps shared by attention and FFN inputs were still called _mlp_input_*, and communication primitives redistribute_*, after the old communicator.

This PR renames them. It does not change behavior.

Modifications

Three commits, each renaming definitions together with every use, including the developer guide:

  1. Residual protocols and implementations. ResidualUpdate / ResidualReadout, PlainAdd (PLAIN_ADD), NormReadout / NormQuantReadout, LayerResidualOps (PLAIN_RESIDUAL_OPS); capability flags as predicates (is_plain_add, applied_at_exit, outlives_layer, is_plain_norm, reads_before_dp_gather); flashinfer_ar_fusion_applies / aiter_ar_fusion_applies.
  2. Contracts, bound paths, owed work. StageContract, EdgeContract, InputContract, OutputContract with always_partial / may_defer_to_next / may_reduce_scatter[v]; ProducerReduction.ALWAYS_PARTIAL / EXIT_SCOPED / TAIL_AFTER_SUM; DeferredFinalize (finalize_norm= on the final norm), ExitRows, attn_input_adapter; EntryPath, StagePath, bind_entry / bind_exit; entry steps named by what they run (_reduce_update_read, _dp_gather_sum_read, ...); primitives named axis then action (attn_tp_gather, dp_gather_sum, moe_cp_take_back, ...); ExitPolicy, ExitDecision, DeferredSum; ResidualStream.record / export / from_handoff; StageBoundary.finish_complete_output (was postprocess).
  3. Model-facing helpers. residual_batch.final_norm / set_written / stream_of; prepare(capture=, capture_gathered=) (models keep their own layer-forward argument names); declare_ffn(next_layer_sparse=), declare_attn(gathers_attn_tp_input=); is_dense_ffn_fully_dp(), moe_gathers_over_moe_cp() / batch_gathers_over_moe_cp(batch); TokenAxis.ATTN_TP.

Not renamed: the forward flags read by compute modules (fuse_mlp_allreduce, mlp_reduce_scatter, defer_moe_finalize), AttnTpContext / AttentionInputs, server arguments, StageBoundary.capture_output(), and generic contract fields (layout, group, read).

Accuracy Tests

Renames only. Each commit was checked against its parent by walking both ASTs file by file: the structure is identical and every differing name or string is one of the renames. The only other differences are one import statement that isort merged and two docstrings describing the renamed capture arguments. Every changed module imports on each commit, and 97 affected unit test files (2,081 tests) pass on each commit.

Speed Tests and Profiling

Not applicable: no behavior change.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #36653139245
Latest PR Test (Extra): ❌ Run #36653139182
Latest PR Test (AMD ROCm 10): ❌ Run #36653139349

@ch-wan
ch-wan force-pushed the cheng/hot-fix/release-consumed-contribution branch from 85357f5 to be31274 Compare September 29, 2026 20:00
@ch-wan
ch-wan force-pushed the cheng/refactor/layer-boundary-naming branch 2 times, most recently from 3bf8a5f to 5ff6682 Compare September 29, 2026 20:29
Base automatically changed from cheng/hot-fix/release-consumed-contribution to main September 29, 2026 23:38
@mintlify

mintlify Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
sglang-doc 🟢 Ready View Preview Sep 30, 2026, 1:04 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

StageUpdate and StageRead describe how a producer writes its output into
the residual and how a consumer reads its input from it, so name them
ResidualUpdate and ResidualReadout. Their implementations and the
LayerResidual bundle follow (PlainAdd, NormReadout, NormQuantReadout,
LayerResidualOps), and the capability flags read as predicates
(is_plain_add, applied_at_exit, outlives_layer, is_plain_norm,
reads_before_dp_gather). The fusion eligibility checks are predicates
too: flashinfer_ar_fusion_applies and aiter_ar_fusion_applies.

Renames only; no behavior change.
- Contracts: StageDecl, EdgeDecl, StageInput and StageOutput become
  StageContract, EdgeContract, InputContract and OutputContract, so the
  resolved contract no longer differs from StageDeclaration by one
  abbreviation. Output permissions read as permissions
  (always_partial, may_defer_to_next, may_reduce_scatter[v]), and
  ProducerReduction values state the contract (ALWAYS_PARTIAL,
  EXIT_SCOPED, TAIL_AFTER_SUM).
- "handoff" now means only a layer handing its output on: the MoE
  finalize left for the next consumer is DeferredFinalize (finalize_norm
  on the final norm), the required output rows are ExitRows, and the
  attention input hook on an entry path is attn_input_adapter.
- Bound paths: StageEntry/StageSteps/StageEdges become EntryPath,
  StagePath and VariantEdges; make_boundary/make_output_boundary become
  bind_entry/bind_exit. Entry steps are named by what they run in order
  (e.g. _reduce_update_read, _dp_gather_sum_read) instead of
  _mlp_input_*, since attention inputs use them too. Communication
  primitives are named axis then action (attn_tp_gather, dp_gather_sum,
  moe_cp_take_back, ...) instead of redistribute_*.
- Exit and stream: OutputBoundary/FfnCompletion become ExitPolicy and
  ExitDecision; CarriedSum becomes DeferredSum next to DeclaredSum;
  ResidualStream.leave/finish/arrive become record/export/from_handoff,
  so export no longer shares a name with StageBoundary.finish.
- StageBoundary.postprocess becomes finish_complete_output: its input is
  an output compute already reduced, and it still applies the output
  transform and a producer-side residual update.

Renames only; no behavior change.
- The layer-stack helpers say what they do: residual_batch.norm becomes
  final_norm, written becomes set_written, and current becomes stream_of.
- Attention prepare takes capture= (a callback on the producer's rows)
  and capture_gathered= (a collector on the compute-input rows) instead
  of capture_output= and captured_last_layer_outputs=. The first no longer
  shares its name with StageBoundary.capture_output(), which returns a
  snapshot. Models keep their own layer-forward argument names.
- declare_ffn(next_sparse=) becomes next_layer_sparse, since it is the
  next decoder layer's FFN rather than the next stage, and
  declare_attn(gathers_tp_input=) becomes gathers_attn_tp_input.
- Configuration queries read as queries: enable_moe_dense_fully_dp()
  becomes is_dense_ffn_fully_dp(), and the MoE-CP pair becomes
  moe_gathers_over_moe_cp() / batch_gathers_over_moe_cp(batch).
- TokenAxis.ATTN_TP_SCATTER becomes ATTN_TP: membership in a layout
  already means the rows are split across that axis.

Renames only; no behavior change.
@ch-wan
ch-wan force-pushed the cheng/refactor/layer-boundary-naming branch from 661ceee to 9a817ba Compare September 30, 2026 01:01
@ch-wan
ch-wan merged commit 01b5f57 into main Sep 30, 2026
96 of 112 checks passed
@ch-wan
ch-wan deleted the cheng/refactor/layer-boundary-naming branch September 30, 2026 04:05

This branch was successfully deployed

1 active deployment
staging - docs — 9a817bab Deployed Sep 30, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd deepseek documentation Improvements or additions to documentation lora npu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant