Skip to content

Document dynamic operator wrapper arguments#6363

Merged
JanuszL merged 2 commits into
NVIDIA:mainfrom
JanuszL:document_batch
May 22, 2026
Merged

Document dynamic operator wrapper arguments#6363
JanuszL merged 2 commits into
NVIDIA:mainfrom
JanuszL:document_batch

Conversation

@JanuszL
Copy link
Copy Markdown
Contributor

@JanuszL JanuszL commented May 21, 2026

Category:

Other

Description:

This PR documents implicit dynamic operator wrapper arguments and keeps
them reserved when building dynamic operator call signatures.

Dynamic operator wrappers now expose batch_size and device as distinct
signature arguments, while tracking them as used keyword names so schema
arguments do not collide with them. The generated dynamic API docstrings
also include numpydoc entries for batch_size, device, rng
when those arguments are present.

Fixes hiding of seed argument in the dynamic mode.

Additional information:

Affected modules and functionalities:

Dynamic mode Python operator wrapper generation and operator docstring
generation.

Key points relevant for the review:

Review the handling of reserved dynamic wrapper arguments in
experimental/dynamic/_op_builder.py and the conditional documentation
generation in ops/_docs.py.

Exact docs wording.

Tests:

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

No tests were run; this is a narrow Python signature/docstring generation
change.

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

Comment thread dali/python/nvidia/dali/ops/_docs.py Outdated
Comment thread dali/python/nvidia/dali/ops/_docs.py Outdated
Comment thread dali/python/nvidia/dali/ops/_docs.py Outdated
return _numpydoc_formatter(
"seed",
"int",
"The seed to use for the random number generator.",
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.

Please share your ideas regarding the docs itself

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 21, 2026

Greptile Summary

This PR documents the implicit batch_size and device arguments that the dynamic operator fn-wrapper injects, and reserves them in used_kwargs so schema arguments cannot collide with them. It also fixes the pre-existing bug where "batch_size=None, device=None" was a single merged string in signature_args, making the two parameters appear as one in every generated signature.

  • _op_builder.py: signature_args is now initialized with two separate elements; used_kwargs is pre-seeded with {\"batch_size\", \"device\"}; the seed removal loop is fixed from an exact-string check (which silently failed for \"seed=None\") to a list comprehension.
  • _docs.py: New _get_batch_size_doc() and _get_device_doc() helpers are added and emitted by _get_kwargs when the dynamic API wrapper exposes those args; copyright year bumped to 2026.
  • dynamic_mode.ipynb: Removes the now-unsupported seed=seed kwarg from a random operator call, keeping the example consistent with the updated fn-wrapper signature.

Confidence Score: 5/5

Safe to merge; all previously identified runtime defects are resolved and the remaining comment is a minor style hardening.

The three targeted fixes (merged signature string, wrong used_kwargs initialization, broken seed removal) are all correctly applied. The only remaining note is that the "seed" not in arg substring filter works for every current DALI operator but is more permissive than needed.

No files require special attention; the changes are narrow and self-contained.

Important Files Changed

Filename Overview
dali/python/nvidia/dali/experimental/dynamic/_op_builder.py Fixes the batch_size/device signature split (was a single merged string), pre-populates used_kwargs so schema args cannot collide, and corrects the seed removal to use a list comprehension instead of the old exact-string check that missed "seed=None".
dali/python/nvidia/dali/ops/_docs.py Adds _get_batch_size_doc() and _get_device_doc() helpers and emits them in _get_kwargs whenever the dynamic API wrapper includes those args; copyright year updated to 2026.
docs/examples/image_processing/decoder/dynamic_mode.ipynb Removes the now-unsupported seed=seed kwarg from a random operator call, consistent with build_fn_wrapper dropping seed from the signature of random ops in favour of rng.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["build_fn_wrapper(op)"] --> B["signature_args = ['batch_size=None', 'device=None']\nused_kwargs = {'batch_size', 'device'}"]
    B --> C["Loop schema.GetArgumentNames()"]
    C --> D["Add arg to used_kwargs & signature_args"]
    D --> E{"op._has_random_state_arg?"}
    E -- Yes --> F["Append 'rng=None' to signature_args\nAdd 'rng' to used_kwargs\nRemove 'seed' from used_kwargs\nFilter 'seed*' from signature_args"]
    E -- No --> G["Skip seed removal"]
    F --> H["header = fn_name(inputs + signature_args)"]
    G --> H
    H --> I["_docstring_generator_fn(schema, api='dynamic', args=used_kwargs)"]
    I --> J["_get_kwargs: schema args\n+ batch_size doc\n+ device doc\n+ rng doc (if present)"]
Loading

Fix All in Claude Code

Reviews (12): Last reviewed commit: "Fix" | Re-trigger Greptile

Comment thread dali/python/nvidia/dali/ops/_docs.py Outdated
Comment thread dali/python/nvidia/dali/experimental/dynamic/_op_builder.py Outdated
@JanuszL
Copy link
Copy Markdown
Contributor Author

JanuszL commented May 21, 2026

@greptile review

Comment on lines -473 to -477
# Remove 'seed' from used_kwargs and signature_args if present
if "seed" in used_kwargs:
used_kwargs.remove("seed")
if "seed" in signature_args:
signature_args.remove("seed")
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.

@mzient does this make sense? It seems to work but maybe you know the reason why it was placed here on the first place.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dynamic mode doesn't have a "seed" argument. It has RNG. That's why we remove it.

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.

Restored and fixed 🤞

@JanuszL
Copy link
Copy Markdown
Contributor Author

JanuszL commented May 21, 2026

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [52151451]: BUILD STARTED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [52151451]: BUILD PASSED

Copy link
Copy Markdown
Contributor

@mzient mzient left a comment

Choose a reason for hiding this comment

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

Keep "seed" removed.

Comment thread dali/python/nvidia/dali/ops/_docs.py Outdated
Comment thread dali/python/nvidia/dali/ops/_docs.py Outdated
Comment thread dali/python/nvidia/dali/ops/_docs.py Outdated
Comment thread dali/python/nvidia/dali/ops/_docs.py
@JanuszL
Copy link
Copy Markdown
Contributor Author

JanuszL commented May 22, 2026

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [52221054]: BUILD STARTED

@JanuszL
Copy link
Copy Markdown
Contributor Author

JanuszL commented May 22, 2026

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [52221741]: BUILD STARTED

Comment on lines +476 to +478
for arg in signature_args:
if "seed" in arg:
signature_args.remove(arg)
Copy link
Copy Markdown
Collaborator

@rostan-t rostan-t May 22, 2026

Choose a reason for hiding this comment

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

Suggested change
for arg in signature_args:
if "seed" in arg:
signature_args.remove(arg)
signature_args = {arg for arg in signature_args if "seed" not in arg}

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.

Fixed

@JanuszL
Copy link
Copy Markdown
Contributor Author

JanuszL commented May 22, 2026

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [52225103]: BUILD STARTED

used_kwargs.remove("seed")
if "seed" in signature_args:
signature_args.remove("seed")
signature_args = {arg for arg in signature_args if "seed" not in arg}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P0 [Critical] Set comprehension produces a set, breaking inputs + signature_args for all random operators

{arg for arg in ...} is a set comprehension, not a list comprehension. After this line signature_args is a set, so inputs + signature_args on the very next effective statement (header = f"{fn_name}({', '.join(inputs + signature_args)})") raises TypeError: can only concatenate list (not "set") to list for every operator where _has_random_state_arg is True. All random dynamic operators (CoinFlip, GaussianNoise, Uniform, etc.) will fail to build at import time.

Suggested change
signature_args = {arg for arg in signature_args if "seed" not in arg}
signature_args = [arg for arg in signature_args if "seed" not in arg]

Fix in Claude Code

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.

Fixed

- Exposes batch_size and device as distinct dynamic operator wrapper
  parameters so they can be tracked as reserved kwargs. Add generated
  numpydoc entries for batch_size, device, rng, and seed when those
  arguments are present in dynamic operator signatures.

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
@JanuszL
Copy link
Copy Markdown
Contributor Author

JanuszL commented May 22, 2026

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [52230441]: BUILD STARTED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [52221741]: BUILD FAILED

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@JanuszL
Copy link
Copy Markdown
Contributor Author

JanuszL commented May 22, 2026

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [52240621]: BUILD STARTED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [52230441]: BUILD FAILED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [52240621]: BUILD PASSED

@JanuszL JanuszL merged commit 2fdb55a into NVIDIA:main May 22, 2026
7 checks passed
@JanuszL JanuszL deleted the document_batch branch May 22, 2026 17:16
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