Fix int downcasting in dynamic mode - #6480
Open
rostan-t wants to merge 5 commits into
Open
Conversation
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Contributor
|
mzient
reviewed
Sep 11, 2026
Comment on lines
-473
to
-486
| with Batch._nvtx_to_numpy_and_stack: | ||
| arr = np.array(unwrap_invariants(sample)) | ||
| converted_dtype_id = None | ||
| if arr.dtype == np.float64: | ||
| arr = arr.astype(np.float32) | ||
| elif arr.dtype == np.int64: | ||
| arr = arr.astype(np.int32) | ||
| elif arr.dtype == np.uint64: | ||
| arr = arr.astype(np.uint32) | ||
| elif arr.dtype == object: | ||
| arr, converted_dtype_id = _try_convert_enums(arr) | ||
| if dtype is not None and dtype.kind != DType.Kind.enum: | ||
| arr = arr.astype(_dali_types.to_numpy_type(dtype.type_id)) | ||
| arr = np.repeat(arr[np.newaxis], batch_size, axis=0) |
Collaborator
There was a problem hiding this comment.
This was an optimization to keep batches of scalars contiguous. Frankly, I haven't measured it but some operations still perform better if they work with contiguous data (e.g. issuing fewer H2D copies).
mzient
requested changes
Sep 11, 2026
mzient
left a comment
Collaborator
There was a problem hiding this comment.
Please restore the optimization that broadcasts scalars to contiguous batches. This results in fewer D2H copies when such a batch is subsequently used in a GPU operator.
This way we can restore the optimization broadcasting scalars contiguous while preserving the casting rules Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Collaborator
Author
|
!build |
Collaborator
|
CI MESSAGE: [67382482]: BUILD STARTED |
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
rostan-t
force-pushed
the
ndd-int-overflow
branch
from
September 11, 2026 15:17
c09d9e0 to
cbe966b
Compare
Collaborator
|
CI MESSAGE: [67382482]: BUILD FAILED |
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.
Category:
Bug fix (non-breaking change which fixes an issue)
Description:
Currently, 64 bits integers are cast down to int32 in dynamic mode, creating silent overflows. Python big integers aren't detected as such, go through the enum path and raise an obscure exception. Since the downcasting is performed immediately when consuming data (in the
Tensorctor), this can lead to surprising behavior:This PR fixes this by raising an exception if an integer that doesn't fit on 32 bits is used. Data that can be represented as signed int32 is stored as such and uint32 is used instead.
Generally, the entry point for data in dynamic mode is always transitively
ndd.Tensorso the fix is done there.Batch.broadcastre-implemented conversions on its own and now usesndd.as_tensorinstead.Additional information:
Affected modules and functionalities:
Dynamic mode.
Key points relevant for the review:
Tests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A