Skip to content

Torchvision custom operator documentation - #6490

Open
mdabek-nvidia wants to merge 2 commits into
NVIDIA:mainfrom
mdabek-nvidia:docs_torchvision_custom_operator
Open

mdabek-nvidia wants to merge 2 commits into
NVIDIA:mainfrom
mdabek-nvidia:docs_torchvision_custom_operator

Conversation

@mdabek-nvidia

Copy link
Copy Markdown
Collaborator

Category:

Other (Documentation)

Description:

Adding Implementing custom operator chapter to Torchvision documentation

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

Check if new chapter could be clearly understood and if user is able to implement a custom operator based on this information.

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-4809

Signed-off-by: Marek Dabek <mdabek@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@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

Signed-off-by: Marek Dabek <mdabek@nvidia.com>
@greptile-apps

greptile-apps Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

The PR is not ready to merge because both custom-operator examples fail when followed or executed, and an explicit documentation typo rule remains violated.

Findings

  1. P1 Custom operator cannot run ▶
  2. P1 Functional example returns None ▶
  3. P2 Guidance relies on private APIs ▶
  4. P2 Correct documentation typo ▶
Summary

This PR adds an object-oriented TrimBorder walkthrough, an abbreviated explanation of the Torchvision Operator base class, and a functional Dynamic Mode example. However, neither example is currently executable from the notebook, and the guidance exposes private implementation classes as extension points.

  • Adds documentation for implementing custom Torchvision-compatible transformations.
  • Demonstrates preprocessing, slicing, validation rules, and Dynamic Mode input adjustment.
  • Requires corrections to imports/helpers and a real functional implementation before the chapter can serve as a working recipe.

Reviews (1) · Last reviewed commit: "Black fixes"

Comment on lines +935 to +936
"class TrimBorder(Operator):\n",
" preprocess_data = get_HWC_from_layout_pipeline\n",

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.

P1 Custom operator cannot run

Running the notebook reaches class TrimBorder(Operator) without defining or importing Operator, so the example immediately raises NameError. The later code also uses unimported get_HWC_from_layout_pipeline, dali, and fn, and calls _stack_int64, which has no definition in the notebook or repository. Add the required imports and use a defined helper such as the fn.stack pattern used by existing operators so readers can run the documented implementation.

Comment on lines +1068 to +1076
"@adjust_input\n",
"def crop(\n",
" inpt: TensorLike | ndd.Batch,\n",
" top: int | float,\n",
" left: int | float,\n",
" height: int | float,\n",
" width: int | float,\n",
" device: DeviceLike = \"cpu\",\n",
") -> ndd.Tensor | ndd.Batch: ..."

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.

P1 Functional example returns None

This example uses names that the notebook does not import, and its ... body returns None. Once the imports are resolved, adjust_input unconditionally calls .evaluate() on that result, causing an AttributeError instead of applying a crop. Show and return the actual Dynamic Mode operation, as the existing crop implementation does with ndd.slice, so readers receive a usable example.

"id": "498db99a",
"metadata": {},
"source": [
"A minimal custom operator only needs to implement `_kernel`, which contains the transformation's logic. If the operator takes configuration parameters, implement `__init__` as well. To validate those parameters, provide `arg_rules` — either existing validators or custom ones deriving from `_ArgumentValidateRule`. If the input itself needs validation (for example, restricting the supported number of channels), list the corresponding rules in `input_rules`. Finally, if additional data processing is needed outside of the DALI pipeline, set `preprocess_data` to a processing function. When in doubt, check how the existing operators are implemented."

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.

P2 Guidance relies on private APIs

The chapter tells users to derive validators from _ArgumentValidateRule, but that underscore-prefixed class, _DataValidateRule, and Operator are not exported by the public Torchvision package. This makes custom operators depend on private implementation details that may change without compatibility guarantees. Either expose a supported extension API or avoid presenting these private classes as user-facing extension points.

" \"\"\"\n",
" type(self).verify_data(data_input)\n",
"\n",
" # Original input is transfered to GPU, before being preprocess_data.\n",

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.

P2 Correct documentation typo

The new comment spells “transferred” as “transfered.” The repository's fix-typos directive requires typos in documentation and comments to be corrected before merging.

Suggested change
" # Original input is transfered to GPU, before being preprocess_data.\n",
" # Original input is transferred to GPU, before being preprocess_data.\n",

Rule Used: Fix typos in identifiers, comments, error messages, and docs. Common ones spotted in DALI history: sequenece, Allready, Whtether, milliseoncds, on-pair, Succesful, poitner, funciton, syncrhonized, deleteion, retruned, `worskpace... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@jantonguirao jantonguirao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The P1 items flagged by greptile should be fixed before merging:

  • Missing imports / undefined _stack_int64 in the TrimBorder example (line 936)
  • The crop functional example returns None/Ellipsis, which breaks adjust_input (line 1076)

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.

3 participants