Skip to content

[AutoTP] Allow ZeRO stage 3 inference with tensor parallelism#8167

Open
delock wants to merge 3 commits into
deepspeedai:masterfrom
delock:gma/allow-autotp-with-zero3
Open

[AutoTP] Allow ZeRO stage 3 inference with tensor parallelism#8167
delock wants to merge 3 commits into
deepspeedai:masterfrom
delock:gma/allow-autotp-with-zero3

Conversation

@delock

@delock delock commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Replace the unconditional zero_optimization_stage() <= 2 assert in _configure_tensor_parallel_states with a guard that only blocks AutoTP + ZeRO-3 when an optimizer is present. The ZeRO-Inference path (no optimizer → DummyOptim → DeepSpeedZeRoOffload) is now permitted; the training path (optimizer → DeepSpeedZeroOptimizer_Stage3) raises NotImplementedError.

AutoTP with ZeRO-3 checkpoint saving should be tracked seperatly in a seperate PR.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf7ae19e99

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 632 to 633
self.mpu = groups
self.mpu._init_tp_mesh_device(tensor_model_parallel_size=self.autotp_size())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep ZeRO-3 AutoTP blocked until 16-bit export is safe

For autotp_size > 1 with ZeRO stage 3, users can now enable a configuration where 16-bit export still drops TP shards: _consolidated_16bit_state_dict() checks zero_optimization_stage() == ZeroStageEnum.weights before the AutoTP branch, so save_16bit_model() when stage3_gather_16bit_weights_on_model_save is enabled gathers only ZeRO data-parallel partitions and rank 0 writes its local TP shard rather than the full weight. The removed guard was the only thing preventing silently truncated exports; please either keep blocking this combination or make the ZeRO-3 consolidation path also gather the AutoTP shards.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This comments had been addressed by allow autotp only in zero3-inference mode. If there is an optimizer, the assertion will block it. The compatibility between autotp and checkpoint saving should be tracked with a seperate issue and fixed in a seperate PR.

Replace the unconditional `zero_optimization_stage() <= 2` guard with one that
only blocks `autotp + zero_stage == 3` when an optimizer is present. The
inference path (no optimizer -> DummyOptim -> DeepSpeedZeRoOffload) is now
permitted; the training path (optimizer -> DeepSpeedZeroOptimizer_Stage3) is
blocked with a clear NotImplementedError.

Rationale: training under autotp+ZeRO-3 itself works (forward/backward/step and
gradient norms match the non-TP baseline), but the TP-aware checkpoint
consolidation path (`_consolidated_16bit_state_dict` / `save_16bit_model`)
gathers only the ZeRO data-parallel partition and would silently write rank 0's
TP shard instead of the full weight, producing incomplete checkpoints. Training
support will land alongside the checkpoint fix (tracked separately).

Signed-off-by: Guokai Ma <guokai.ma@intel.com>
@delock
delock force-pushed the gma/allow-autotp-with-zero3 branch from cf7ae19 to 2e4247e Compare July 23, 2026 07:07
@delock delock changed the title [AutoTP] Allow ZeRO stage 3 with tensor parallelism [AutoTP] Allow ZeRO stage 3 inference with tensor parallelism Jul 23, 2026
Comment thread deepspeed/runtime/engine.py Outdated
Comment on lines +631 to +634
# AutoTP + ZeRO-3 is supported only for ZeRO-Inference (no optimizer).
# With an optimizer the TP-aware checkpoint consolidation path is not yet
# implemented, so save_16bit_model()/save_checkpoint would silently drop
# TP shards. Block the training path until that is fixed (tracked separately).

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.

I think the comment can be removed since it is a duplicate of the error message.

Signed-off-by: Guokai Ma <guokai.ma@intel.com>
raise NotImplementedError("AutoTP together with ZeRO stage 3 is currently supported only for inference "
"(no optimizer). Running it with an optimizer is disabled because TP-aware "
"checkpoint consolidation is not yet implemented and would silently produce "
"incomplete checkpoints.")

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.

So this means we cannot apply AutoTP + ZeRO stage 3 to student models?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, student model need to have checkpoint saved, and zero stage 3 checkpoint saving does not support AutoTP yet. This would be taken care of in another PR (still work in progress).


### Tensor Parallel (AutoTP)
Configure AutoTP tensor parallelism for training via the DeepSpeed config and hybrid TP + ZeRO. AutoTP supports ZeRO stages 0, 1, and 2 (stage 3 is not supported). `deepspeed.tp_model_init()` remains supported for backward compatibility but is not required when `tensor_parallel` is set in the config.
Configure AutoTP tensor parallelism for training via the DeepSpeed config and hybrid TP + ZeRO. AutoTP supports ZeRO stages 0, 1, and 2. ZeRO stage 3 is supported only for inference (no optimizer); training with stage 3 is not yet supported. `deepspeed.tp_model_init()` remains supported for backward compatibility but is not required when `tensor_parallel` is set in the config.

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.

I feel this description is a little confusing. Shall we say ZeRO stage 3 is supported only for inference in the context of on-policy distillation?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Zero inference can also support other scenario where model is too large to fit in GPU memory, so not only for OPD.

@delock
delock enabled auto-merge July 24, 2026 08:02
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.

3 participants