Skip to content

Move dynamic API class constructor docs to class-level docstrings#6273

Open
JanuszL wants to merge 2 commits intoNVIDIA:mainfrom
JanuszL:dynamic_api_docstrings
Open

Move dynamic API class constructor docs to class-level docstrings#6273
JanuszL wants to merge 2 commits intoNVIDIA:mainfrom
JanuszL:dynamic_api_docstrings

Conversation

@JanuszL
Copy link
Copy Markdown
Contributor

@JanuszL JanuszL commented Mar 23, 2026

  • Follows the numpy docstring convention by placing Parameters sections
    in class-level docstrings instead of init docstrings. This ensures
    Sphinx autodoc renders constructor arguments correctly in the API
    reference (e.g. Batch arguments were previously not shown)
  • Replaces :meth: cross-references with :func: for all module-level
    functions (batch, as_batch, tensor, as_tensor, stream, device,
    set_current_stream, set_default_stream, get_current_stream,
    get_default_stream, io.file.read, decoders.image).
  • Updates: Batch, Tensor, ThreadPool, Stream, Device, EvalContext, RNG

Category:

Other (e.g. Documentation, Tests, Configuration)

Description:

  • Follows the numpy docstring convention by placing Parameters sections
    in class-level docstrings instead of init docstrings. This ensures
    Sphinx autodoc renders constructor arguments correctly in the API
    reference (e.g. Batch arguments were previously not shown)
  • Replaces :meth: cross-references with :func: for all module-level
    functions (batch, as_batch, tensor, as_tensor, stream, device,
    set_current_stream, set_default_stream, get_current_stream,
    get_default_stream, io.file.read, decoders.image).
  • Updates: Batch, Tensor, ThreadPool, Stream, Device, EvalContext, RNG

Additional information:

Affected modules and functionalities:

  • Batch, Tensor, ThreadPool, Stream, Device, EvalContext, RNG in dynamic mode

Key points relevant for the review:

  • text of docstrings

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: DALI-4630

@JanuszL
Copy link
Copy Markdown
Contributor Author

JanuszL commented Mar 23, 2026

!build

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 23, 2026

Greptile Summary

This PR is a pure documentation improvement for the DALI dynamic API module. It follows the numpy docstring convention by relocating constructor parameter documentation from __init__ docstrings to class-level docstrings, which is required for Sphinx autodoc to correctly render constructor arguments (e.g. Batch parameters were previously invisible in the generated API reference). Additionally, all Sphinx cross-references to module-level functions (batch, as_batch, tensor, as_tensor, stream, device, and the stream management functions) are corrected from :meth: to :func:, which is the proper role for module-level callables.

Key changes:

  • Batch, Tensor, Stream, Device, EvalContext, ThreadPool: Constructor Parameters sections moved from __init__ docstrings to class-level docstrings; __init__ docstrings removed.
  • ThreadPool: Class-level docstring created for the first time; formerly separate "Args" and "Keyword Args" blocks consolidated into a single numpy-style "Parameters" section.
  • Stream: Class-level docstring gains a full Parameters section (the old __init__ docstring was only a one-liner warning).
  • RNG: Redundant __init__ one-liner removed; the class docstring already contained a complete Parameters section for seed.
  • _imread.py: Two :meth: cross-references corrected to :func: in function-level docstrings.
  • No functional code is modified; all changes are limited to docstring text and Sphinx markup.

Confidence Score: 5/5

Safe to merge — purely documentation restructuring with no functional code changes.

All eight changed files contain only docstring edits and Sphinx cross-reference fixes (:meth::func:). No logic, signatures, or runtime behaviour is altered. The numpy-convention migration is internally consistent across all affected classes, and the RNG class correctly retains its seed parameter documentation at the class level before the __init__ docstring is removed.

No files require special attention.

Important Files Changed

Filename Overview
dali/python/nvidia/dali/experimental/dynamic/_batch.py Moves __init__ docstring (Parameters, warning) to class-level docstring; fixes :meth::func: for batch/as_batch; period added to invocation_result description
dali/python/nvidia/dali/experimental/dynamic/_device.py Moves __init__ docstring to class level; converts "Args"/"Keyword Args" style to numpy "Parameters" style; fixes :meth:device:func:device
dali/python/nvidia/dali/experimental/dynamic/_eval_context.py Moves __init__ docstring to class level; changes cuda_stream bullet list to numbered list; fixes all :meth::func: for module-level stream functions; "cuda_stream" → "CUDA stream" in description
dali/python/nvidia/dali/experimental/dynamic/_imread.py Updates two :meth: cross-references to :func: for io.file.read and decoders.image in function docstrings
dali/python/nvidia/dali/experimental/dynamic/_stream.py Moves __init__ docstring to class level with full Parameters section (previously only a one-liner); fixes :meth::func: for all stream-related module functions
dali/python/nvidia/dali/experimental/dynamic/_tensor.py Moves __init__ docstring (Parameters, warning) to class-level docstring; fixes :meth:tensor/:meth:as_tensor:func:
dali/python/nvidia/dali/experimental/dynamic/_thread_pool.py Adds new class-level docstring with Parameters section; removes __init__ docstring; merges previously separate "Args" and "Keyword Args" blocks into a single "Parameters" section
dali/python/nvidia/dali/experimental/dynamic/random.py Removes the brief __init__ docstring; the class-level docstring already contains a full Parameters section documenting seed

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Sphinx autodoc processes class"] --> B{Where is the Parameters section?}
    B -->|"Before: __init__ docstring"| C["❌ Parameters hidden\n(autodoc skips __init__ by default)"]
    B -->|"After: class-level docstring"| D["✅ Parameters visible in API reference"]
    D --> E["cross-references :meth: → :func:"]
    E --> F["Correct Sphinx roles for module-level callables"]
Loading

Reviews (3): Last reviewed commit: "review fixes" | Re-trigger Greptile

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [46787934]: BUILD STARTED

- Follows the numpy docstring convention by placing Parameters sections
  in class-level docstrings instead of __init__ docstrings. This ensures
  Sphinx autodoc renders constructor arguments correctly in the API
  reference (e.g. Batch arguments were previously not shown)
- Replaces :meth: cross-references with :func: for all module-level
  functions (batch, as_batch, tensor, as_tensor, stream, device,
  set_current_stream, set_default_stream, get_current_stream,
  get_default_stream, io.file.read, decoders.image).
- Updates: Batch, Tensor, ThreadPool, Stream, Device, EvalContext, RNG

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
@JanuszL JanuszL force-pushed the dynamic_api_docstrings branch from 2dafdb0 to 74c9a86 Compare March 23, 2026 15:15
@JanuszL
Copy link
Copy Markdown
Contributor Author

JanuszL commented Mar 23, 2026

@greptileai - please re-review

@JanuszL
Copy link
Copy Markdown
Contributor Author

JanuszL commented Mar 23, 2026

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [46789476]: BUILD STARTED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [46789476]: BUILD PASSED

This class wraps a CUDA stream object. It can be either a stream created by DALI or a
compatible object created by a third-party library.

.. note::
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.

Inconsistency with _batch.py and _tensor.py: those classes use .. warning:: for the "don't construct directly" guidance, but Stream (and Device) use .. note:: here. Stream's phrasing — "Do not construct this class directly" — is actually more imperative than what Batch/Tensor say, so if anything it warrants .. warning:: too. Worth making this consistent across all four classes.

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


The device can be either CPU or (specific) GPU.

.. note::
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.

This was a .. warning:: in the old __init__ docstring and has been downgraded to .. note:: here, while Batch and Tensor keep .. warning:: for the same kind of guidance. Consider keeping .. warning:: for consistency, or align all four classes to .. note:: if the softer tone is intentional.

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

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

JanuszL commented Mar 31, 2026

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [47354403]: BUILD STARTED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [47354403]: BUILD 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