- 
                Notifications
    
You must be signed in to change notification settings  - Fork 647
 
Fill gaps in dynamic mode documentation - Tensor, Batch and Readers. #6080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Michal Zientkiewicz <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR enhances the Dynamic Mode documentation by adding comprehensive docstrings to Tensor, Batch, and Reader classes. The PR also includes minor refactoring improvements.
Key Changes:
- Documentation: Added detailed class-level and method-level docstrings for 
TensorandBatchclasses, explaining their purpose, properties, and methods. Added docstrings forReader.run()andReader.next_epoch()methods. - API Cleanup: Renamed 
assign()to_assign()in bothTensorandBatchclasses to make it private, as it was an internal implementation detail not meant for public use. - Performance Optimization: Modified 
Batch.evaluate()andTensor.evaluate()to checkif self._backend is Nonebefore entering theEvalContextcontext manager, avoiding unnecessary context creation when the batch/tensor is already evaluated. - Code Cleanup: Removed unused 
dataproperty fromTensorclass. 
Issues Found:
- 5 spelling/grammar typos in the new docstrings that should be corrected
 
Confidence Score: 4/5
- This PR is safe to merge after fixing the typos in docstrings
 - The changes are primarily documentation additions with minor refactoring. The logic changes (privatizing 
assignmethod and reordering context manager checks) are safe improvements. The only issues are spelling/grammar typos in documentation that should be fixed before merge. Existing tests apply according to PR description. - All files need minor typo corrections in docstrings before merge
 
Important Files Changed
File Analysis
| Filename | Score | Overview | 
|---|---|---|
| dali/python/nvidia/dali/experimental/dynamic/_batch.py | 4/5 | Added comprehensive docstrings for Batch class and methods; renamed assign to _assign (privatized); optimized evaluate() by checking _backend before entering context manager; contains 3 typos in docstrings | 
| dali/python/nvidia/dali/experimental/dynamic/_tensor.py | 4/5 | Added comprehensive docstrings for Tensor class and properties; renamed assign to _assign (privatized); removed unused data property; contains 2 typos in docstrings | 
| dali/python/nvidia/dali/experimental/dynamic/ops.py | 5/5 | Added docstrings to Reader.run() and Reader.next_epoch() methods; no logic changes, documentation only | 
Sequence Diagram
sequenceDiagram
    participant User
    participant Batch
    participant EvalContext
    participant Backend
    Note over Batch,Backend: Before (Original Implementation)
    User->>Batch: evaluate()
    Batch->>EvalContext: with _EvalContext.get()
    activate EvalContext
    EvalContext->>Batch: enter context
    Batch->>Batch: check if self._backend is None
    alt backend is None
        Batch->>Backend: _invocation_result.value(ctx)
        Backend-->>Batch: return backend
    end
    EvalContext->>Batch: exit context
    deactivate EvalContext
    Batch-->>User: return self
    Note over Batch,Backend: After (Optimized Implementation)
    User->>Batch: evaluate()
    Batch->>Batch: check if self._backend is None
    alt backend is None
        Batch->>EvalContext: with _EvalContext.get()
        activate EvalContext
        EvalContext->>Batch: enter context
        Batch->>Backend: _invocation_result.value(ctx)
        Backend-->>Batch: return backend
        EvalContext->>Batch: exit context
        deactivate EvalContext
    end
    Batch-->>User: return self
    Note over Batch: Performance Improvement: Context only created when needed
    3 files reviewed, 5 comments
| 
           Check out this pull request on   See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB  | 
    
Signed-off-by: Michal Zientkiewicz <[email protected]>
| 
           CI MESSAGE: [37814741]: BUILD STARTED  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR enhances the documentation of DALI's Dynamic Mode API, focusing on Tensor, Batch, and Reader classes by adding comprehensive docstrings for classes, methods, and properties.
Key Changes:
- Added extensive class-level and method-level documentation for 
TensorandBatchobjects, explaining lazy evaluation, device handling, and data ownership - Documented 
Readermethods (runandnext_epoch) with clear usage notes about iterator behavior - Made 
assignmethod private (renamed to_assign) in bothTensorandBatchclasses - Removed unused 
dataproperty fromTensorclass - Optimized 
evaluate()methods by checkingif self._backend is Nonebefore enteringEvalContext, reducing overhead for already-evaluated objects - Fixed multiple typos across C++ headers and documentation ("Rreturns" → "Returns", "specied" → "specified", "consectutive" → "consecutive", etc.)
 
Documentation Improvements:
- Properties now have docstrings explaining their purpose and return values
 - Methods include parameter descriptions and usage examples (e.g., 
Batch.shapeexample) - Added warnings about direct constructor usage, directing users to factory functions
 - Clarified batch dimension semantics (N dimension not included in 
ndimorlayout) 
Confidence Score: 5/5
- This PR is safe to merge with minimal risk - it primarily adds documentation with minor refactoring
 - The changes are primarily documentation additions with minimal code changes. The refactoring (renaming 
assignto_assign, removing unuseddataproperty, and optimizingevaluate()nesting) are safe improvements. The optimization inevaluate()is beneficial as it avoids entering the context manager when unnecessary. All changes maintain backward compatibility for public APIs. - No files require special attention
 
Important Files Changed
File Analysis
| Filename | Score | Overview | 
|---|---|---|
| dali/python/nvidia/dali/experimental/dynamic/_batch.py | 5/5 | Adds comprehensive docstrings for Batch class and methods, renames assign to _assign (private), and optimizes evaluate() by checking _backend before entering context | 
| dali/python/nvidia/dali/experimental/dynamic/_tensor.py | 5/5 | Adds comprehensive docstrings for Tensor class and properties, renames assign to _assign (private), removes unused data property, and optimizes evaluate() similarly to Batch | 
| dali/python/nvidia/dali/experimental/dynamic/ops.py | 5/5 | Adds docstrings for Reader methods (run and next_epoch) to improve API documentation | 
Sequence Diagram
sequenceDiagram
    participant User
    participant Tensor
    participant Batch
    participant EvalContext
    participant Backend
    
    User->>Tensor: Create tensor/batch with data
    Note over Tensor: Stores data or lazy invocation
    
    User->>Tensor: Access property (shape, dtype, etc.)
    alt Property available without evaluation
        Tensor-->>User: Return cached/inferred value
    else Requires evaluation
        Tensor->>Tensor: evaluate()
        Note over Tensor: Check if _backend is None (NEW)
        alt _backend already exists
            Tensor-->>User: Return property from backend
        else _backend is None
            Tensor->>EvalContext: Enter context
            EvalContext->>Backend: Execute lazy operation
            Backend-->>Tensor: Return computed backend
            Tensor-->>User: Return property
        end
    end
    
    Note over Tensor,Batch: assign() renamed to _assign() (private)
    6 files reviewed, no comments
| 
           CI MESSAGE: [37814741]: BUILD FAILED  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the functions that call (or might call) evaluate on a tensor or batch be documented?
| A Batch can contain: | ||
| * a single buffer and shape, owner by DALI, representing consecutive tensors | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * a single buffer and shape, owner by DALI, representing consecutive tensors | |
| * a single buffer and shape, owned by DALI, representing consecutive tensors | 
| return type_name | ||
| 
               | 
          ||
| 
               | 
          ||
| class Reader(Operator): | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class should override __call__ in order to add docstring.
Category:
Refactoring (Redesign of existing code that doesn't affect functionality)
Other (e.g. Documentation, Tests, Configuration)
Description:
This PR extends the documentation of Dynamic Mode.
It also hides the
assignfunction in Tensor/Batch and makes re-evaluation of batches cheaper by switching nesting order.The unused
dataproperty of the Tensor class has been removed (it's no longer necessary as we have__array__and__cuda_array_interface__properties).Additional information:
Some unrelated typos in comments and documentation were fixed as they were identical to the ones I made in this PR.
Affected modules and functionalities:
Key points relevant for the review:
Tests:
Tensor and Batch tests.
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A