Skip to content

[bugfix]: fix modular ops activation checkpoint recomputation - #1716

Open
shaoxiongduan wants to merge 3 commits into
hao-ai-lab:mainfrom
shaoxiongduan:shao/fix-selective-activation-checkpointing
Open

[bugfix]: fix modular ops activation checkpoint recomputation#1716
shaoxiongduan wants to merge 3 commits into
hao-ai-lab:mainfrom
shaoxiongduan:shao/fix-selective-activation-checkpointing

Conversation

@shaoxiongduan

@shaoxiongduan shaoxiongduan commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Purpose

Fix the modular trainer's ops activation-checkpoint policy. It previously
wrapped the transformer root and retained only a small set of PyTorch op
objects, so custom attention backends silently fell back to full attention
recomputation. Several modular model plugins also still imported the separate
legacy-training helper, which meant the corrected policy reached MiniMax H3
but not the other modular families.

Changes

  • Wrap each discovered transformer block in its own checkpoint region.
  • Match supported fused attention operations by exact dispatcher name, avoiding
    import-time dependencies on optional backend registrations.
  • Retain fused SDPA, FastVideo FlashAttention, and all autograd-enabled generic
    block-sparse attention forwards, including the current SM90, SM100a, and
    Triton VSA ops.
  • Do not retain parameter collectives or inexpensive matrix multiplies.
  • Remove the ineffective math-SDPA entry: PyTorch decomposes that path before
    the selective policy sees a retainable attention boundary.
  • Route Wan and its descendants, LTX-2, Kandinsky5, and MiniMax H3 through the
    modular trainer's checkpoint helper; the legacy training stack is unchanged.
  • Resolve Wan checkpoint configuration once so role-level overrides also enable
    checkpoint-safe causal KV-cache snapshots.
  • Keep kernel registration drift coverage portable when fastvideo_kernel is
    unavailable on a supported platform.
  • Document the full versus ops memory/runtime tradeoff and correct the
    canonical example-config path.

Supported and fallback paths

ops retains supported dispatcher-visible fused attention outputs and can
reduce backward recomputation when memory headroom exists. It uses more
activation memory than full. Math SDPA, VMoBA, FA3, and ATTN_QAT_TRAIN do
not expose a retainable dispatcher boundary today, so their attention still
fully recomputes under ops. Memory-constrained jobs, including tight GB10
configurations, should retain full.

Regression coverage

The CPU behavioral suite uses a real autograd-enabled custom op across four
transformer blocks. It verifies:

  • forward counts: 4 without checkpointing, 8 under full, 4 when ops
    retains the custom op, and 8 for an unsupported op;
  • exact output, loss, input-gradient, and parameter-gradient parity;
  • per-block wrapper granularity and invalid-layout failure behavior;
  • known and dynamically registered block-sparse op coverage;
  • modular model-plugin wiring; and
  • role-level versus global Wan causal checkpoint/cache resolution.

Fresh verification on rebased head cce7fdf819a164b616cf946ac0e1889033f66f1e:

pytest fastvideo/tests/train/utils/test_activation_checkpoint.py -q
19 passed, 14 warnings in 0.26s

pytest fastvideo/tests/train/utils -q
98 passed, 14 warnings in 0.46s

pytest fastvideo/tests/train \
  --ignore=fastvideo/tests/train/models \
  --ignore=fastvideo/tests/train/methods -q
186 passed, 14 warnings in 0.49s

pytest fastvideo/tests/train/methods/test_minimax_h3_finetune.py::\
test_h3_model_uses_modular_activation_checkpointing -q
1 passed, 14 warnings in 0.25s

PYTHONPATH="$PWD" bash .buildkite/scripts/unit_test.sh
1012 passed, 7 skipped, 19 warnings in 23.32s

pre-commit run --files <all changed paths>
Passed

A real CUDA probe on the local NVIDIA GB10 confirmed that PyTorch 2.12
dispatches the tested shape through
aten::_scaled_dot_product_flash_attention. The ops policy executed four
underlying fused forward kernels across four blocks versus eight under full,
with exact output, loss, input-gradient, and parameter-gradient parity.

Performance evidence scope

The earlier author measurements were single-sequence-parallel-rank GB200
experiments on an earlier/private H3 setup. They show the intended
speed-for-memory direction but are not presented here as a reproducible
current-tree SP=8 benchmark. This change's merge contract is functional
checkpoint behavior and numerical parity; production throughput should be
validated with each job's actual backend, sharding, and memory headroom.

SSIM is not required: this changes which activations are retained versus
recomputed during modular training, not inference output or model weights.

Checklist

@mergify mergify Bot added type: bugfix Bug fix scope: training Training pipeline, methods, configs labels Aug 18, 2026
@mergify

mergify Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🤖 CI

Protection Waiting on
🔴 PR merge requirements 👀 reviews and 🤖 CI

🔴 PR merge requirements

Waiting for

  • #approved-reviews-by>=1
  • check-success=full-suite-passed
This rule is failing.
  • #approved-reviews-by>=1
  • check-success=full-suite-passed
  • check-success=fastcheck-passed
  • check-success~=pre-commit
  • title~=(?i)^\[(feat|feature|bugfix|fix|refactor|perf|ci|doc|docs|misc|chore|kernel|new.?model|skill|skills|infra)\]

@shaoxiongduan

Copy link
Copy Markdown
Collaborator Author

/merge

@github-actions github-actions Bot added the ready PR is ready to merge label Aug 21, 2026
@alexzms
alexzms self-requested a review August 25, 2026 23:41
alexzms
alexzms previously approved these changes Aug 25, 2026

@alexzms alexzms left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified on GB200: ops now wraps per block and retains attention (6 flash_fwd launches across 6 blocks, vs 12 under full), with loss and input grad bit-identical to no checkpointing, and func.name() never raises on the ops a real step dispatches.

The red checks look stale — builds #4878/#4905 fall in a window where unit-tests were red repo-wide (#1726 and #1739 too), and ./fastvideo/tests/train/ passes on this branch locally (161 tests). Worth a CI re-run rather than a code change.

@SolitaryThinker SolitaryThinker removed the ready PR is ready to merge label Aug 26, 2026
@SolitaryThinker
SolitaryThinker dismissed alexzms’s stale review August 26, 2026 06:19

The branch was rebased and materially updated after this review (SM100a coverage, regression tests, and documentation). A fresh exact-head approval is required after CI.

@SolitaryThinker
SolitaryThinker force-pushed the shao/fix-selective-activation-checkpointing branch from 9a19a74 to 2e2889c Compare August 26, 2026 06:20
@mergify mergify Bot added scope: infra CI, tests, Docker, build scope: docs Documentation labels Aug 26, 2026
@SolitaryThinker SolitaryThinker changed the title [bugfix] Fix ops activation checkpointing silently ran as full recomputation [bugfix]: fix modular ops activation checkpoint recomputation Aug 26, 2026
@SolitaryThinker

Copy link
Copy Markdown
Collaborator

/test full

@SolitaryThinker

Copy link
Copy Markdown
Collaborator

/merge

@github-actions github-actions Bot added the ready PR is ready to merge label Aug 26, 2026
@SolitaryThinker

Copy link
Copy Markdown
Collaborator

/test fastcheck

@SolitaryThinker

Copy link
Copy Markdown
Collaborator

/test full

shaoxiongduan and others added 3 commits August 26, 2026 15:51
The modular trainer's `ops` checkpoint policy matched a small set of op
objects and wrapped the transformer root. Custom attention backends therefore
fell through to full recomputation, while root-level replay erased the intended
per-block selective behavior.

Wrap each discovered transformer block independently and match supported fused
attention operators by exact dispatcher name. Retain fused SDPA, FastVideo
FlashAttention, and autograd-enabled block-sparse attention outputs. Do not
retain parameter collectives or inexpensive matrix multiplies.

Keep the change scoped to `fastvideo/train`: shipped legacy training configs do
not select `ops`, and that separate stack has not been validated here.
Route modular model plugins through the train-owned checkpoint policy so selective recomputation is not limited to MiniMax H3. Resolve Wan checkpoint configuration once so causal KV-cache snapshots honor role-level overrides, and keep kernel drift coverage portable when the optional kernel package is unavailable.
@SolitaryThinker
SolitaryThinker force-pushed the shao/fix-selective-activation-checkpointing branch from 2e2889c to cce7fdf Compare August 26, 2026 23:05
@SolitaryThinker SolitaryThinker removed the ready PR is ready to merge label Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: docs Documentation scope: infra CI, tests, Docker, build scope: training Training pipeline, methods, configs type: bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants