Skip to content

Validate gpu_layout inputs to fail clearly instead of ZeroDivisionError - #11

Open
Anilreddy2309 wants to merge 1 commit into
NVIDIA:mainfrom
Anilreddy2309:fix/gpu-layout-validation
Open

Validate gpu_layout inputs to fail clearly instead of ZeroDivisionError#11
Anilreddy2309 wants to merge 1 commit into
NVIDIA:mainfrom
Anilreddy2309:fix/gpu-layout-validation

Conversation

@Anilreddy2309

Copy link
Copy Markdown

Summary

resolve_gpu_layout() in nvflow/lib/gpu_layout.py computed total % gpus_per_node without first checking that gpus_per_node was positive. A misconfigured cluster config (gpus_per_node: 0) would raise a raw ZeroDivisionError instead of the clean ValueError style the rest of the function already uses. total_gpus, num_nodes, and num_gpus had the same gap — zero/negative values silently produced a nonsensical GpuLayout (e.g. num_nodes=0) instead of failing fast.

This PR:

  • Adds explicit positive-integer validation for gpus_per_node, total_gpus, num_nodes, and num_gpus, each raising ValueError with a message pointing at the config field to fix.
  • Adds tests/test_gpu_layout.py (14 tests) covering the existing documented behavior plus these edge cases. The module had no prior test coverage.

No behavior changes for valid inputs — this only turns previously-unhandled invalid inputs into clear, actionable errors.

Test plan

  • ruff check / ruff format --check pass on both changed files
  • New test suite passes (14/14) in an isolated venv against this module (stdlib-only, no project dependencies needed)
  • Verified gpus_per_node: 0 previously raised ZeroDivisionError; now raises ValueError: gpus_per_node (0) must be a positive integer. ...

🤖 Generated with Claude Code

resolve_gpu_layout() computed total % gpus_per_node without checking
that gpus_per_node was positive first, so a misconfigured cluster
config (gpus_per_node: 0) raised a raw ZeroDivisionError instead of
the module's own ValueError style. total_gpus, num_nodes, and num_gpus
were similarly unvalidated, allowing zero/negative values to silently
produce a nonsensical GpuLayout (e.g. num_nodes=0).

Add explicit positive-integer checks for all four inputs, each with a
message pointing at the config field to fix. Add tests/test_gpu_layout.py
covering the existing behavior plus these edge cases; the module had no
prior test coverage.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Anil Balireddy <anilbalireddi@gmail.com>
@Anilreddy2309
Anilreddy2309 requested a review from a team September 11, 2026 16:48
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.

1 participant