Skip to content

[FIX][Relax] Validate DeviceMesh cardinality without overflow - #20346

Open
ruiling-smartbear wants to merge 1 commit into
apache:mainfrom
ruiling-smartbear:fix/device-mesh-cardinality
Open

ruiling-smartbear wants to merge 1 commit into
apache:mainfrom
ruiling-smartbear:fix/device-mesh-cardinality

Conversation

@ruiling-smartbear

@ruiling-smartbear ruiling-smartbear commented Sep 15, 2026

Copy link
Copy Markdown

Fixes #20272.

Use a checked 64-bit shape product in both DeviceMesh constructors. Reject negative dimensions and overflow without narrowing the device count. Validate constant Range bounds and cardinality before generating IDs, and avoid overflowing the final ID.

Preserve empty-shape and zero-dimension product semantics. This does not change duplicate-ID policy.

Validation on Linux CPU / LLVM 16 (cc0f9f07, pinned TVM FFI): the original code incorrectly accepted 10 invalid-cardinality cases; after this change the complete DTensor-type test file reports 25 passed. Coverage includes both constructors, ordinary mismatches, 32/64-bit overflow, negative/zero dimensions, nonconstant ranges, and large starting IDs. Large-shape cases use empty lists or short ranges, not large allocations.

Changed-file pre-commit checks passed. No GPU tests run.

Share checked int64 shape multiplication across both constructors and validate ranges before generating device IDs. Preserve zero-dimension and empty-shape semantics.
@ruiling-smartbear
ruiling-smartbear force-pushed the fix/device-mesh-cardinality branch from 506c076 to 3c5b609 Compare September 15, 2026 21:57
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.

[Bug][Relax][Distributed] DeviceMesh accepts invalid shape/device-id cardinality after 32-bit product narrowing

1 participant