Skip to content

Cleanup after instance cache rework.#6209

Merged
mzient merged 5 commits intoNVIDIA:mainfrom
mzient:instance_cache_cleanup
Feb 23, 2026
Merged

Cleanup after instance cache rework.#6209
mzient merged 5 commits intoNVIDIA:mainfrom
mzient:instance_cache_cleanup

Conversation

@mzient
Copy link
Copy Markdown
Contributor

@mzient mzient commented Feb 13, 2026

Category:

Refactoring (Redesign of existing code that doesn't affect functionality)

Description:

This PR addresses low priority issues found in #6206 review.

Additional information:

Affected modules and functionalities:

Invocation

Key points relevant for the review:

weakref.finalize usage

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

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [43973595]: BUILD STARTED

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Feb 13, 2026

Greptile Overview

Greptile Summary

This PR addresses code cleanup issues identified in the review of PR #6206, focusing on proper resource management and documentation improvements.

Key changes:

  • Replaced __del__ finalizer with weakref.finalize in Invocation class to prevent circular references between invocation and operator instances during caching
  • Added comprehensive docstring to _process_params explaining its role as a class method for operator instance caching
  • Removed unused _reset_backend method from Operator class
  • Fixed typo "parmaeters" → "parameters" (addressed in separate commit)

Confidence Score: 5/5

  • This PR is safe to merge with no risk - it contains well-tested refactoring improvements
  • The changes are straightforward cleanup and refactoring work that addresses legitimate issues from previous review. The weakref.finalize pattern is used correctly following established patterns in the codebase (pipeline.py:992), and existing tests already validate the functionality
  • No files require special attention

Important Files Changed

Filename Overview
dali/python/nvidia/dali/experimental/dynamic/_invocation.py Replaced __del__ with weakref.finalize to avoid circular references in operator caching, following the pattern from pipeline.py:992
dali/python/nvidia/dali/experimental/dynamic/_ops.py Added docstring explaining _process_params as a class method for operator caching; removed unused _reset_backend method

Last reviewed commit: da3b5bb

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

def __del__(self):
self._return_op_to_cache()
if hasattr(self._operator, "_cache"):
self._return_op_to_cache = weakref.finalize(self, self._return_op_to_cache_impl)
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.

passing self._return_op_to_cache_impl creates a circular reference - the bound method holds a reference to self, preventing the finalizer from running. need to extract the cache, keyname, and operator instance before creating the finalizer, then pass them as separate arguments to a lambda or standalone function (see how pipeline.py:992 uses lambda with separate args)

Comment thread dali/python/nvidia/dali/experimental/dynamic/_ops.py Outdated
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [43975029]: BUILD STARTED

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@classmethod
def _process_params(cls, backend, op_device, batch_size, *raw_args, **raw_kwargs):
"""
Processes run-time parameters passed to the operator to ones that can be consumed DALI
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.

typo: 'parmaeters' should be 'parameters'

Suggested change
Processes run-time parameters passed to the operator to ones that can be consumed DALI
Processes run-time parameters passed to the operator to ones that can be consumed DALI

Comment thread dali/python/nvidia/dali/experimental/dynamic/_invocation.py Fixed
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [43976464]: BUILD STARTED

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [43973595]: BUILD PASSED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [43976464]: BUILD FAILED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [43976464]: BUILD PASSED

@mzient mzient merged commit 1d6d57f into NVIDIA:main Feb 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.

5 participants