Skip to content

Torchvision normalize#6278

Merged
mdabek-nvidia merged 50 commits intoNVIDIA:mainfrom
mdabek-nvidia:torchvision_normalize
Apr 9, 2026
Merged

Torchvision normalize#6278
mdabek-nvidia merged 50 commits intoNVIDIA:mainfrom
mdabek-nvidia:torchvision_normalize

Conversation

@mdabek-nvidia
Copy link
Copy Markdown
Collaborator

Category:

New feature

Description:

Torchvision's normalize operators implementation

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

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

mdabek-nvidia and others added 10 commits March 19, 2026 13:30
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Co-authored-by: Kamil Tokarski <kamiltokarski04@gmail.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-of-by: Marek Dabek <mdabek@nvidia.com>
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_normalize branch 2 times, most recently from 810618b to 52af0c6 Compare March 25, 2026 13:49
@mdabek-nvidia
Copy link
Copy Markdown
Collaborator Author

@greptileai please review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 25, 2026

Greptile Summary

This PR adds a Normalize operator and normalize functional to the DALI torchvision compatibility layer, mirroring torchvision.transforms.v2.Normalize. Both a class-based (Normalize) and functional (normalize) API are provided, with CHW/HWC layout detection handled consistently with the existing operator patterns in the codebase. Previously flagged issues (scalar hue validation in ColorJitter, scalar input crash in the functional normalize, and GaussianBlur bugs) have all been resolved.

Confidence Score: 5/5

Safe to merge — all previously raised P1 issues have been resolved and only minor style findings remain.

All P1 findings from prior review rounds are fixed. The two remaining findings are P2 style issues (a comment typo and a slightly inaccurate docstring) that do not affect correctness or runtime behaviour.

No files require special attention.

Vulnerabilities

No security concerns identified.

Important Files Changed

Filename Overview
dali/python/nvidia/dali/experimental/torchvision/v2/functional/normalize.py New functional normalize implementation; layout detection via string slicing is correct; minor comment typos ("Torchvison", "nomrlization").
dali/python/nvidia/dali/experimental/torchvision/v2/normalize.py New Normalize operator class; validation logic is correct; layout comparison uses established uint8 byte pattern; docstring slightly inaccurate about PIL Image rejection.
dali/test/python/torchvision/test_tv_normalize.py Good test coverage across CPU/GPU, single/multi-channel, batch shapes, mismatched lengths, and zero-std cases.
dali/python/nvidia/dali/experimental/torchvision/v2/color.py Correctly adds a non-negative guard for scalar hue before range expansion, fixing the previously flagged silent inverted-range bug.
dali/python/nvidia/dali/experimental/torchvision/init.py Adds Normalize to the public torchvision API surface.
dali/python/nvidia/dali/experimental/torchvision/v2/functional/init.py Exports normalize from the functional sub-package.
dali/python/nvidia/dali/experimental/torchvision/v2/functional/gaussian_blur.py Whitespace-only change (blank line added before return).

Sequence Diagram

sequenceDiagram
    participant Caller
    participant normalize as functional.normalize
    participant _normalize as functional._normalize
    participant Normalize as Normalize class
    participant ndd as ndd.normalize
    participant fn as fn.normalize

    Caller->>normalize: normalize(input, mean, std)
    normalize->>Normalize: verify_args(std, mean)
    normalize->>_normalize: _normalize(input, mean, std)
    _normalize->>_normalize: detect layout (CHW vs HWC)
    _normalize->>_normalize: reshape mean/std arrays
    _normalize->>ndd: ndd.normalize(input, mean, stddev)
    ndd-->>Caller: normalized tensor

    Caller->>Normalize: Normalize(mean, std)(input)
    Normalize->>Normalize: verify_args (via Operator.__init__)
    Normalize->>Normalize: _kernel(data_input)
    Normalize->>Normalize: detect layout via property("layout")[-1]
    Normalize->>fn: fn.normalize(data_input, mean, stddev)
    fn-->>Caller: normalized tensor
Loading

Reviews (14): Last reviewed commit: "Typo fix" | Re-trigger Greptile

Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/gaussian_blur.py Outdated
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/gaussian_blur.py Outdated
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/gaussian_blur.py Outdated
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/normalize.py Outdated
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_normalize branch from 6567dda to 160ec66 Compare March 25, 2026 14:00
@mdabek-nvidia
Copy link
Copy Markdown
Collaborator Author

@greptileai please re-review

@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_normalize branch 2 times, most recently from b4e11d2 to 6adc717 Compare March 25, 2026 17:56
@mdabek-nvidia mdabek-nvidia marked this pull request as ready for review March 25, 2026 17:56
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/normalize.py
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_normalize branch from 6adc717 to 64809e3 Compare March 31, 2026 08:50
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/color.py
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/color.py Outdated
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/gaussian_blur.py Outdated
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/gaussian_blur.py Outdated
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/normalize.py Outdated
Comment thread dali/test/python/torchvision/test_tv_gaussian_blur.py Outdated
Comment thread dali/test/python/torchvision/test_tv_normalize.py Outdated
@jantonguirao jantonguirao self-requested a review March 31, 2026 09:16
Comment thread dali/test/python/torchvision/test_tv_normalize.py Dismissed
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_normalize branch from f5ac5fa to c0f9a56 Compare April 3, 2026 09:16
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_normalize branch from c0f9a56 to e86e551 Compare April 3, 2026 12:21
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_normalize branch from 278022b to d08ca9b Compare April 7, 2026 07:00
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_normalize branch from 9f0e924 to cb5848f Compare April 7, 2026 08:52
@mdabek-nvidia
Copy link
Copy Markdown
Collaborator Author

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [47913207]: BUILD STARTED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [47913207]: BUILD PASSED

@mdabek-nvidia
Copy link
Copy Markdown
Collaborator Author

@greptileai please re-review

Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/color.py Outdated
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_normalize branch from ed8d250 to 53c08bb Compare April 9, 2026 08:59
@mdabek-nvidia mdabek-nvidia merged commit 8e15229 into NVIDIA:main Apr 9, 2026
5 of 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.

8 participants