[Refactor] Unify SAC checkpointing and GLM DSA dataflow - #2039
Conversation
b2047db to
5c15855
Compare
|
@claude review |
|
Claude: Summary本 PR 把 activation checkpointing 统一到一个 PyTree-aware 的 reentrant 边界( Main Flowchart after this PRflowchart TD
A["MoE._forward / _micro_batch_forward"] --> B["_decoder_stack /<br/>_micro_batch_decoder_stack<br/>(新增, 11 参数 + 可变 output dict)"]
B --> C{"模型类型"}
C -->|"通用 MoE"| D["MoE._call_decoder_layer<br/>(offload 窗口 + block_idx 规则)"]
C -->|"GLM-5.2"| E["Glm52MoE._call_decoder_layer<br/>(整段 override: DSA IDs + 另一套 block_idx 规则)"]
D --> F["_saved_tensors_offload_ctx<br/>(storage-ptr 匹配, reserve_pin_memory)"]
E --> F
F --> G["decoder_layer(...) -> TypedDict"]
G --> H["GLM52AttnOutputs.dsa_topk_ids<br/>显式传给下一 consumer 层"]
H --> I["MTPBlock._call_decoder_layer<br/>GLM52MTPBlock 无条件透传 dsa_topk_ids"]
style D fill:#ffe0b2,stroke:#e65100
style E fill:#ffcdd2,stroke:#b71c1c
style F fill:#ffcdd2,stroke:#b71c1c
style I fill:#ffe0b2,stroke:#e65100
核心原理实现与单测
抽象与信息隐藏评估
其他 Issues
VerdictREQUEST_CHANGES |
| """Build one policy-neutral saved-tensor offload window. | ||
|
|
||
| The decoder-stack caller decides which tensors belong to the current | ||
| window and advances ``block_idx`` only when the list is non-empty. | ||
| """ | ||
| if not tensors: | ||
| return contextlib.nullcontext() |
There was a problem hiding this comment.
Claude: [正确性] 匹配条件从原来的 x.data_ptr() == hidden_states.data_ptr() 放宽为 storage 指针,会把共享 storage 的非零偏移视图一并纳入窗口,同一 storage 可能被重复 pack/D2H。另外单 micro-batch 路径新增了 reserve_pin_memory=True 且 block_idx 由绝对层号改为相对号,改变了 OffloadManager 的 key 与 prefetch 顺序,而本 PR 基准未覆盖 XTUNER_ACTIVATION_OFFLOAD=1 的单 micro-batch 路径。
Flatten structured inputs and outputs at one checkpoint boundary so nested MTP micro-batch tensors receive gradients. Keep FSDP outside replay and remove the non-reentrant MTP switch.
Move GLM-specific decoder and MTP adapters under the model package, thread DSA IDs through keyed outputs, and remove SequenceContext cache lifecycle state. Share one saved-tensor offload window for activation and DSA ID storage.
Keep reusable no-grad outputs in checkpoint-call-local FIFO frames, freeze DSA indexers through their model config, and preserve the original int32 storage across shared layers and offload. Add real regressions for source call counts and pinned-memory DSA offload.
703db3e to
9a3d730
Compare
Summary
Regression coverage
Validation