[Fix] Raise Python exceptions instead of exiting on CUDA errors - #13
Open
morluto wants to merge 4 commits into
Open
[Fix] Raise Python exceptions instead of exiting on CUDA errors#13morluto wants to merge 4 commits into
morluto wants to merge 4 commits into
Conversation
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.
Fixes #9.
Summary
Replace process-terminating CUDA checks in the C++ extension with
Python-visible exceptions, and add exception-safe rollback for partially
acquired VMM resources.
Problem
The extension's
CUCHECKandCUDACHECKmacros printed an error and calledexit(EXIT_FAILURE).Any checked CUDA driver or runtime failure therefore terminated the entire
Python process from inside the library. Callers could not catch the failure,
add operation context, clean up their own state, or coordinate an orderly
distributed shutdown.
Change
Use
TORCH_CHECKto propagate CUDA failures through pybind asRuntimeError.Error messages now include:
Because failures now unwind the C++ stack, scoped cleanup covers:
Ownership transfers only after the receiving tensor or return tuple is fully
constructed. Imported CUDA handles receive exactly one release attempt before
any release error is propagated; unwind cleanup does not retry an opaque handle
whose release status may reflect an earlier asynchronous CUDA error.
nvl_multicast_bind_mapnow explicitly documents that it consumes themulticast handle and borrows the physical allocation handle.
Regression coverage
The regression opens
/dev/nullas a valid POSIX file descriptor and passes itto
nvl_multicast_import. The descriptor is valid at the OS boundary but isnot a CUDA-exported shareable allocation.
The call runs in a subprocess so any accidental
exit()is observable withoutterminating pytest.
On an H100 NVL:
origin/master— the child process exited with status 1 inside the old CUDAcheck path;
RuntimeError, verified the failed CUDAexpression, and continued;
1 passed in 1.74s.The test intentionally avoids fabricated CUDA allocation handles, whose
invalid use is undefined.
Compatibility
Successful return values, ownership contracts, tensor layouts, and kernel ABI
are unchanged.
Failure behavior changes from unconditional process termination to a catchable
Python exception.
Validation
python3 -m pytest -q tests/test_cpp_error_propagation.py— 1 passed in1.74s.
git diff --check origin/master...HEAD— passed.