fix(core): stop run_nvrtc corrupting the interned bytes singleton#15887
Open
harjothkhara wants to merge 1 commit into
Open
fix(core): stop run_nvrtc corrupting the interned bytes singleton#15887harjothkhara wants to merge 1 commit into
harjothkhara wants to merge 1 commit into
Conversation
run_nvrtc allocated its NVRTC output buffers as `b" " * size`. NVRTC writes the compile log / PTX (a C string, including its NUL terminator) into those buffers, but `bytes` is immutable. For an empty compile log `size == 1`, and CPython's `b" " * 1` returns the interned, process-wide 1-byte singleton `b" "`; NVRTC's NUL write then turns every `b" "`, `bytes([32])` and 1-byte space slice in the whole process into `b"\x00"` permanently. Allocate the log and PTX buffers as `bytearray(size)` (mutable and never interned) and convert with `bytes(ptx)` before `np.char.array` to keep the existing behavior. Adds a GPU-free regression test that fakes the NVRTC/CUDA bindings and asserts the output buffers are mutable and the interned singleton is left intact. Fixes NVIDIA-NeMo#15790 Signed-off-by: harjoth <harjoth.khara@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.
What does this PR do ?
Fixes a process-wide memory-corruption bug in
run_nvrtc(): it allocated NVRTC output buffers as immutableb" " * size, and for an empty compile log (size == 1) CPython returns the interned, process-wide 1-byte singletonb" ". NVRTC then writes its C-string NUL terminator into that shared object, turning everyb" "/bytes([32])/ 1-byte space slice in the whole process intob"\x00"permanently. Fix: use a mutablebytearray.Collection: core (
nemo/core/utils/cuda_python_utils.py)Changelog
nemo/core/utils/cuda_python_utils.py: allocate the NVRTC log buffer and PTX buffer asbytearray(size)/bytearray(ptxSize)instead ofb" " * size(mutable, never interned).bytes(ptx)beforenp.char.array(...)so downstream behavior is byte-for-byte identical (passing abytearraydirectly tonp.char.arraywould be misinterpreted as a sequence of ints).tests/core/test_cuda_python_utils.py(new): GPU-free regression test that fakes the NVRTC/CUDA bindings and emulates NVRTC writing into the buffer viamemoryview; asserts the buffers are mutable and the interned singleton is intact. Fails on the old code (TypeError: cannot modify read-only memory), passes on the fix. Skips whencuda-pythonis unavailable, matchingtests/collections/asr/decoding/test_cuda_graph_rnnt_greedy_decoding.py.Usage
Reproduction (self-contained, no GPU / no NeMo import — just
cuda-python), from #15790:GitHub Actions CI
CI has not been triggered yet (external fork). A maintainer can start it with
/ok to test <sha>/ "Approve and run" and the Run CICD label.Before your PR is "Ready for review"
Pre checks:
tests/core/test_cuda_python_utils.pyrun_nvrtcstays behind@cuda_python_required, and the new testpytest.skips whencuda-pythonis unavailable.PR Type:
Additional Information
run_nvrtc()corrupts CPython's interned 1-byte bytes singletonb' 'when the NVRTC compile log is empty #15790cuda-pythonis present.