[AutoTP] Support frozen AutoTP models and manage AutoTP mode per model #8851
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8851"
general
weight: 0.35
jinyouzhi
Summary
Two bugs show up when a frozen teacher runs next to an AutoTP student in one process, as in on-policy distillation (deepspeedai/DeepSpeedExamples#1019, #8850).
1. Frozen replicated parameters break
deepspeed.initialize.register_replicated_grad_hooksregisters a gradient all-reduce hook on every replicated (non-TP) parameter. PyTorch refuses hooks on tensors withrequires_grad=False, so a fully or partially frozen model fails duringinitialize.initialize. If any of them becomes trainable later, the next backward raises a clear error instead of letting TP replicas drift apart silently.2. The AutoTP training mode leaks into
init_inference.deepspeed.initializewith AutoTP sets a process-global training-mode flag. A teacher passed todeepspeed.init_inferenceafterwards still sees training mode. As a result:tp_size;The fix makes the mode per model instead of process-wide:
AutoTPMeta, which AutoTP already passes to every layer it builds, gains atrainingfield. AutoTP fills it from itstraining_modeargument, whichdeepspeed.initializesets toTrueandinit_inferencetoFalse.TensorParallel_Layertakes its mode fromtp_meta, so the forward path (RowParallel,add_bias) follows how that model was sharded. The student keeps training-mode behavior after the teacher is built, and vice versa.AutoTP.set_tensor_parallel_configandreplace_transformer_layer(kernel injection,set_lm_head, MP checkpoint saving) use the explicittraining_modeinstead of the global flag.AutoTP(training_mode=None)(the new default) and layers built withouttp_metastill followset_autotp_mode, so existing direct callers behave as before.Related work
I searched open and closed PRs and issues for
register_replicated_grad_hooks,AUTOTP_MODEand frozen AutoTP models, and found no existing fix. Reported while integrating #1019.Sibling paths checked:
is_autotp_training_mode()reader indeepspeed/:auto_tp.py(set_tensor_parallel_config) andreplace_module.py(kernel injection,set_lm_head, MP checkpoint saving) now use the explicit mode; the remaining reads are the fallbacks for callers that pass no mode.AutoTP(...)call sites indeepspeed/(engine,TpTrainingManager,InferenceEngine) already passtraining_modeexplicitly. No code indeepspeed/builds TP layers outside AutoTP.Tests
New tests in
tests/unit/v1/autotp/test_tp_plan_e2e.py. Each fails without the corresponding fix and passes with it.test_frozen_qwen3_initializes_and_runs: 2 ranks; the frozen model's outputs match the unsharded reference.test_unfreezing_replicated_param_after_initialize_raises: 2 ranks.TestInferenceTeacherAfterTrainingStudent: 4 ranks. A student with TP=2 is trained, then a teacher is built withinit_inference(tp_size=4)and checked to be sharded 4 ways and frozen.Results at head
68647c93e:| Tests | Result |
|---|---|
|
tests/unit/v1/autotp/test_tp_plan_e2e.py| 8 passed ||
tests/unit/module_inject+ the othertests/unit/v1/autotpfiles | 171 passed, 37 skipped ||
tests/unit/v1/autotp/test_autotp_training.py(skipped on XPU byskip_on_device; run locally with that skip removed) | 42 passed, 2 skipped (bf16 overflow skip) ||
tests/unit/v1/autotp/test_autotp_training.pywithDS_ACCELERATOR=cpu| 11 passed, 33 skipped ||
test_autoep_autotp_sharded_attention.py,test_autoep_autotp_runtime.py,test_per_head_muon_accelerator.py,test_checkpoint_sharding.py(-k "not True") | 44 passed, 4 skipped, 3 failed |The 3 failures (
TestTiedOutputHead::test_row_parallel_tied_head_is_refused[False]and twotest_per_head_on_a_shard_is_the_shard_of_per_head[2-*]) fail the same way on mastera4811fbf9. Thezero_init=Truecases oftest_autoep_autotp_sharded_attention.pywere deselected becausetest_grads_and_norm_match_reference[3-True-4-2-2]hangs on master as well.Hardware and software:
Compatibility matrix
The changes are mode bookkeeping and hook registration; no numerics change on the existing training path.
| | Validated | Not validated |
|---|---|---|
| ZeRO | New tests: stage 0. Existing AutoTP suite: stages 0/1/2. | Frozen model with ZeRO-3 + AutoTP |
| Precision | New tests: fp32. Existing suite: fp16/bf16. | |
| Offload | | Not exercised |
| Parallelism | TP=2 and TP=4; student TP=2 with teacher TP=4 | DP>1 together with a frozen teacher |
| Accelerator | XPU | CUDA, HPU |
AI assistance
This PR was developed with AI assistance (GitHub Copilot CLI). I reviewed every changed line and ran the tests above.
cc @0z5a I try to fix the bug you described in Vocab-parallel pipeline with OPSD.
@delock And address AutoTP_MODE issue, I think OPSD will reach the issue soon.