Skip to content

[distributed] Raise ValueError for invalid parallelism degrees - #5014

Merged
tianyu-l merged 2 commits into
pytorch:mainfrom
YeonwooSung:pr/validate-parallelism-degrees
Oct 2, 2026
Merged

tianyu-l merged 2 commits into
pytorch:mainfrom
YeonwooSung:pr/validate-parallelism-degrees

Conversation

@YeonwooSung

Copy link
Copy Markdown
Contributor

Summary

ParallelismContext._validate used assert to reject a bad parallelism recipe. That is the wrong tool for user-facing config:

  • python -O (and -OO) strips assert. A zero degree then hits ZeroDivisionError while auto-filling dp_shard=-1, or the product check disappears and dp_shard is left truncated so it no longer multiplies out to world_size.
  • The expert-parallel check immediately below already raises ValueError when ep does not divide dp_shard * cp * tp. Degree checks should fail the same way.

Those degree checks now raise ValueError with the same rules:

  • dp_replicate, cp, tp, pp, and ep must be >= 1.
  • dp_shard must be -1 or >= 1. dp_shard=-1 still auto-fills as world_size // (dp_replicate * cp * tp * pp), and the filled value must be >= 1.
  • dp_replicate * dp_shard * cp * tp * pp must equal world_size.

Mesh construction, the expert-parallel rule, and the world-size formula are unchanged. Expert parallel is not a factor of world_size.

Test plan

  • python -m pytest tests/unit_tests/cpu/test_parallelism_context.py -q --tb=line
    • test_validation_invalid_world_size, test_validation_zero_parallelism, and test_validation_invalid_dp_shard expect ValueError and the message names the bad condition (world size mismatch, degree >= 1, dp_shard).
    • test_auto_calculate_dp_shard still accepts dp_shard=-1.

CI has not been run for this branch.

@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 2, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 2, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@tianyu-l
tianyu-l merged commit dd96691 into pytorch:main Oct 2, 2026
@YeonwooSung
YeonwooSung deleted the pr/validate-parallelism-degrees branch October 2, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants