Validate gpu_layout inputs to fail clearly instead of ZeroDivisionError - #11
Open
Anilreddy2309 wants to merge 1 commit into
Open
Validate gpu_layout inputs to fail clearly instead of ZeroDivisionError#11Anilreddy2309 wants to merge 1 commit into
Anilreddy2309 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resolve_gpu_layout()innvflow/lib/gpu_layout.pycomputedtotal % gpus_per_nodewithout first checking thatgpus_per_nodewas positive. A misconfigured cluster config (gpus_per_node: 0) would raise a rawZeroDivisionErrorinstead of the cleanValueErrorstyle the rest of the function already uses.total_gpus,num_nodes, andnum_gpushad the same gap — zero/negative values silently produced a nonsensicalGpuLayout(e.g.num_nodes=0) instead of failing fast.This PR:
gpus_per_node,total_gpus,num_nodes, andnum_gpus, each raisingValueErrorwith a message pointing at the config field to fix.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 --checkpass on both changed filesgpus_per_node: 0previously raisedZeroDivisionError; now raisesValueError: gpus_per_node (0) must be a positive integer. ...🤖 Generated with Claude Code