Allow defining output metadata in the OpSchema#6244
Draft
rostan-t wants to merge 3 commits intoNVIDIA:mainfrom
Draft
Allow defining output metadata in the OpSchema#6244rostan-t wants to merge 3 commits intoNVIDIA:mainfrom
rostan-t wants to merge 3 commits intoNVIDIA:mainfrom
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>
6f6cb95 to
98706e8
Compare
mzient
reviewed
Mar 3, 2026
| * @param index Index of the output to set the function for. | ||
| * @param fn Function that returns the data type for the given output. | ||
| */ | ||
| OpSchema &OutputDType(int index, OutputDTypeFunc fn); |
Contributor
There was a problem hiding this comment.
I think that some kind of policy would be nice - and a sane default, too. Most operators will follow the pattern:
- use the value of
dtypeargument, if notNone(and it's already a special argument) - use the data type of the 1st input if
dtypeisNone.
I say "is not None" as opposed to "is present", because some operators have a defaultdtypeand adhere to it, even if the user doesn't provide one.
The operators that do NOT follow this pattern are:
- readers (typically uint8, unpredictable type for NumPy reader, something else for video)
- arithmetic/math (use type promotion rules)
- sum (promotes all integers to int64 of the same signeddness; keeps floating point type)
- normalize, mean, rms, etc (promotes integers to float, keeps floating point type).
mzient
reviewed
Mar 3, 2026
|
|
||
| /** Try calculating the data type of a given output */ | ||
| std::optional<DALIDataType> CalculateOutputDType(int index, const OpSpec &spec, | ||
| span<const DALIDataType> input_dtypes) const; |
Contributor
There was a problem hiding this comment.
- I think that the metadata should be a part of what is now called
OpSpec::InOutDeviceDesc - Even if it's not,
input_dtypesshould all be optional - in many cases we only need the data type of the 1st input. Inability to compute all of them will ruin the static evaluation for pipeline mode.
mzient
reviewed
Mar 3, 2026
|
|
||
| /** Try calculating the ndim of a given output */ | ||
| std::optional<int> CalculateOutputNdim(int index, const OpSpec &spec, | ||
| span<const int> input_ndims) const; |
mzient
reviewed
Mar 3, 2026
|
|
||
| /** Try calculating the layout of a given output */ | ||
| std::optional<TensorLayout> CalculateOutputLayout(int index, const OpSpec &spec, | ||
| span<const TensorLayout> input_layouts) const; |
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:
New feature (non-breaking change which adds functionality)
Description:
It is currently necessary to run operators in order to know the output ndim, dtype and layouts. This PR adds the possibility to specify those metadata when defining an
OpSchema.This is especially relevant for dynamic mode because accessing those metadata currently causes immediate evaluation of tensors, even when
EvalMode.eagerorEvalMode.deferis used.Additional information:
Affected modules and functionalities:
Key points relevant for the review:
Tests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: DALI-2778