Skip to content

Fix handling of empty layouts in ndd.Invocation#6304

Merged
mzient merged 3 commits intoNVIDIA:mainfrom
mzient:fix_ndd_empty_layout
Apr 23, 2026
Merged

Fix handling of empty layouts in ndd.Invocation#6304
mzient merged 3 commits intoNVIDIA:mainfrom
mzient:fix_ndd_empty_layout

Conversation

@mzient
Copy link
Copy Markdown
Contributor

@mzient mzient commented Apr 17, 2026

Category:

Bug fix (non-breaking change which fixes an issue)

Description:

This PR fixes a minor inconsistency in handling empty layouts. Empty layouts obtained from metadata were returned as None but as empty string if evaluation was required. Now None is returned across the board, consistent with the behavior of Tensor and Batch.

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

@JanuszL JanuszL self-assigned this Apr 17, 2026
@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [48791722]: BUILD STARTED

Comment thread dali/python/nvidia/dali/experimental/dynamic/_invocation.py
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 17, 2026

Greptile Summary

This PR fixes an inconsistency in ndd.Invocation.layout() where the init_spec (early/deferred) path already returned None for empty layouts but the post-evaluation path returned "". Both paths now consistently return None, matching Tensor and Batch behavior. The reshape.cc change enables the init_spec early-return path to work for layout-only reshapes by falling back to the input's ndim when no static shape is specified.

Confidence Score: 5/5

Safe to merge — narrow, well-tested fix with no breaking changes.

All changes are P2 or lower. The core fix is a one-line change with clear intent, the type annotation is corrected, and new targeted tests cover both deferred and evaluated paths.

No files require special attention.

Important Files Changed

Filename Overview
dali/python/nvidia/dali/experimental/dynamic/_invocation.py Core fix: converts empty-string layout returns to None via layout or None; also corrects return type annotation from str to `str
dali/operators/generic/reshape.cc Enhances ReshapeNDimFunc to short-circuit on runtime shapes and fall back to the input's ndim when no static shape is given, enabling the init_spec early-return path for layout-only reshapes.
dali/test/python/experimental_mode/test_output_metadata.py Adds reshape(layout="") to the parametrized consistency test and a dedicated test_empty_layout that verifies both pre- and post-evaluate paths return None.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Invocation.layout(result_index)"] --> B{_results is None?}
    B -- Yes --> C{init_spec available?}
    C -- Yes --> D["Call init_spec()\nRead OutputDesc layout"]
    D --> E{layout is not None?}
    E -- Yes --> F["Convert to str\nReturn None if '' else layout"]
    E -- No --> G["self.run(_eval_context)"]
    C -- No --> G
    G --> H["layout = _results[result_index].layout()"]
    B -- No --> H
    H --> I["return layout or None\n('' → None)"]
Loading

Reviews (2): Last reviewed commit: "Fix annotation." | Re-trigger Greptile

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [48791722]: BUILD PASSED

mzient added 2 commits April 21, 2026 10:58
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@mzient mzient force-pushed the fix_ndd_empty_layout branch from 10f1738 to 7e3af9b Compare April 21, 2026 09:27
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [49079846]: BUILD STARTED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [49079846]: BUILD PASSED

std::vector<float> rel_shape;
if (spec.TryGetRepeatedArgument(rel_shape, "rel_shape"))
return rel_shape.size();
return std::nullopt;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bit too pessimistic.

@mzient mzient merged commit c4b89a1 into NVIDIA:main Apr 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants