Skip to content

Torchvision gaussian blur#6275

Merged
mdabek-nvidia merged 24 commits intoNVIDIA:mainfrom
mdabek-nvidia:torchvision_gaussian_blur
Apr 2, 2026
Merged

Torchvision gaussian blur#6275
mdabek-nvidia merged 24 commits intoNVIDIA:mainfrom
mdabek-nvidia:torchvision_gaussian_blur

Conversation

@mdabek-nvidia
Copy link
Copy Markdown
Collaborator

Category:

New feature

Description:

Implementation of Torchvision's GaussianBlur operator

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_gaussian_blur branch from 6056187 to 6ddc68a Compare March 24, 2026 14:25
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/color.py Fixed
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_gaussian_blur branch from 5521fe5 to ef0bf89 Compare March 24, 2026 14:31
@mdabek-nvidia
Copy link
Copy Markdown
Collaborator Author

mdabek-nvidia commented Mar 24, 2026

@greptileai please review

@mdabek-nvidia
Copy link
Copy Markdown
Collaborator Author

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [46880386]: BUILD STARTED

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 24, 2026

Greptile Summary

This PR adds a GaussianBlur operator (pipeline mode) and a gaussian_blur functional (dynamic mode) that mirror torchvision's v2.GaussianBlur API, including correct odd-kernel validation, uniform sigma sampling for range inputs, and DALI-typed input/output handling. It also cleans up type hints across the existing functional wrappers (centercrop, color, flips, resize) to use TensorLike/DeviceLike instead of torch.Tensor | PIL.Image. All previously flagged issues (inverted int-check, broken imports, tuple-sigma misinterpretation, missing odd-kernel guard) have been resolved.

Confidence Score: 5/5

Safe to merge; all prior blocking issues are resolved and remaining findings are minor test housekeeping.

All P0/P1 issues from previous review rounds have been addressed. The only remaining findings are P2 test-file style concerns (wrong comment shape, stale citation tokens, commented-out dead code). These do not affect runtime correctness or the operator contract.

dali/test/python/torchvision/test_tv_gaussian_blur.py — minor comment and dead-code cleanup needed.

Important Files Changed

Filename Overview
dali/python/nvidia/dali/experimental/torchvision/v2/gaussian_blur.py New GaussianBlur operator with correct validation, odd-kernel check, and uniform sigma sampling via fn.random.uniform for range inputs; all previously flagged issues resolved.
dali/python/nvidia/dali/experimental/torchvision/v2/functional/gaussian_blur.py Functional dynamic-mode wrapper; correctly calls verify_args, promotes scalar sigma to a tuple, uses ndd.random.uniform for range sampling, and extracts scalar for the degenerate equal-bounds case.
dali/test/python/torchvision/test_tv_gaussian_blur.py Comprehensive test coverage for PIL, tensor, and GPU paths; minor issues: wrong comment shape, stale citation artifacts, and commented-out test/assertions that should be restored or tracked.
dali/python/nvidia/dali/experimental/torchvision/init.py Registers GaussianBlur in the public all and module import; straightforward and correct.
dali/python/nvidia/dali/experimental/torchvision/v2/functional/init.py Adds gaussian_blur import and all entry; clean and correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Input["Input (PIL / torch.Tensor)"]
    AdjustInput["adjust_input decorator"]
    VerifyArgs["GaussianBlur.verify_args"]
    subgraph PipelineMode["Pipeline Mode"]
        SigmaRange1{"sigma range?"}
        RandomUniform1["fn.random.uniform(range=sigma)"]
        ScalarSigma1["sigma = sigma[0]"]
        FnGaussianBlur["fn.gaussian_blur"]
    end
    subgraph DynamicMode["Dynamic Mode"]
        SigmaRange2{"sigma range?"}
        RandomUniform2["ndd.random.uniform(range=sigma)"]
        ScalarSigma2["sigma = sigma[0]"]
        NddGaussianBlur["ndd.gaussian_blur"]
    end
    Output["Output (PIL / torch.Tensor)"]
    Input --> AdjustInput --> VerifyArgs
    VerifyArgs --> PipelineMode
    VerifyArgs --> DynamicMode
    SigmaRange1 -- yes --> RandomUniform1 --> FnGaussianBlur
    SigmaRange1 -- no --> ScalarSigma1 --> FnGaussianBlur
    SigmaRange2 -- yes --> RandomUniform2 --> NddGaussianBlur
    SigmaRange2 -- no --> ScalarSigma2 --> NddGaussianBlur
    FnGaussianBlur --> Output
    NddGaussianBlur --> Output
Loading

Reviews (12): Last reviewed commit: "Merge branch 'main' into torchvision_gau..." | 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/color.py
@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [46880386]: BUILD PASSED

@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_gaussian_blur branch from afc4838 to 455f51e Compare March 25, 2026 08:46
@mdabek-nvidia
Copy link
Copy Markdown
Collaborator Author

@greptileai please review

@mdabek-nvidia mdabek-nvidia marked this pull request as ready for review March 25, 2026 08:52
@mdabek-nvidia
Copy link
Copy Markdown
Collaborator Author

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [46954308]: BUILD STARTED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [46954308]: BUILD PASSED

@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_gaussian_blur branch 2 times, most recently from ea898cb to abdd2e6 Compare March 25, 2026 17:42
@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [47327945]: BUILD PASSED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [47329835]: BUILD PASSED

mdabek-nvidia and others added 5 commits April 1, 2026 10:37
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Center crop operators implementation

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>
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_gaussian_blur branch from 26edf14 to 946223a Compare April 2, 2026 07:51
Signed-off-by: Marek Dabek <mdabek@nvidia.com>

if not isinstance(kernel_size, (int, Sequence)):
raise ValueError(
f" Kernel size should be an int or a sequenece of ints, got {kernel_size}"
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.

Suggested change
f" Kernel size should be an int or a sequenece of ints, got {kernel_size}"
f"Kernel size should be an int or a sequence of ints, got {kernel_size}"


if isinstance(kernel_size, Sequence) and any(not isinstance(v, int) for v in kernel_size):
raise ValueError(
f" Kernel size should be an int or a sequenece of ints, got {kernel_size}"
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.

Suggested change
f" Kernel size should be an int or a sequenece of ints, got {kernel_size}"
f"Kernel size should be an int or a sequence of ints, got {kernel_size}"

kernel_size: int | Sequence[int],
sigma: int | float | Sequence[float] = (0.1, 2.0),
device: Literal["cpu", "gpu"] = "cpu",
) -> Image.Image | torch.Tensor:
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.

should these types annotations match the actual function body (ndd typesor what happens after annotating withadjust_input`?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Answering both comments, the one I am responding to and to @rostan-t 's one .
The logic for annotations (here and in every other functional API call) is that it is additional information for users to what is being supported by the API, especially that every input is converted to ndd.Tensor or ndd.Batch by the adjust_input operator.

dali_blur = Compose([GaussianBlur(kernel_size=kernel_size, sigma=sigma)])
_ = dali_blur(tens)

""" Both do not raise ValueError
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.

why do we have this commented out?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The expectation was that invalid kernel/sigma will cause a ValueError exception, but it did not even in the original code. I am keeping it as a documentation of an oddity.

Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/functional/centercrop.py Outdated
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/functional/gaussian_blur.py Outdated
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/functional/gaussian_blur.py Outdated
Comment thread dali/python/nvidia/dali/experimental/torchvision/v2/functional/gaussian_blur.py Outdated
Comment thread dali/test/python/torchvision/test_tv_gaussian_blur.py
rostan-t and others added 5 commits April 2, 2026 11:38
…VIDIA#6262)

* Improve call stack depth handling for error tracebacks in dynamic mode
* Rework exception_tester to automatically infer expected line and message
---------

Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Add uniform_sample option to VideoReaderDecoder

  Adds a `uniform_sample` argument that samples exactly `sequence_length`                                                               
  frames uniformly across the full video (or ROI) using linspace with
  std::round rounding. Each video produces one sample per epoch; `stride`                                                               
  and `step` are ignored (with a DALI_WARN if `pad_mode` is also set).                                                                
  `sequence_length` must be >= 1 when `uniform_sample=True`.                                                                            
                                                                                                                                        
  To avoid a per-sample heap allocation, VideoSampleDesc::frame_idxs_                                                                   
  changes from std::vector<int> to span<const int>. Owned storage moves                                                                 
  to all_frame_idxs_ (vector<vector<int>>) in the loader, which is                                                                      
  populated once in PrepareMetadataImpl and stable for the loader's                                                                     
  lifetime. The copy in ReadSample becomes a cheap 16-byte span copy.                                                                   
  all_frame_idxs_ is declared before samples_ so its lifetime encloses                                                                  
  the spans, preventing dangling references on destruction.                                                                             
                                                                                                                                        
  New tests:                                                                                                                            
  - test_uniform_sample_basic: verifies frame indices match expected linspace                                                           
  - test_uniform_sample_file_list_roi: ROI with non-zero start_frame via file_list                                                      
  - test_uniform_sample_sequence_length_zero_raises: sequence_length=0 raises                                                           
  - test_uniform_sample_stride_step_ignored: stride/step have no effect                                                                 
                                                                                                                                        
  Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>
- cudaDeviceSynchronize returns cudaErrorStreamCaptureUnsupported when any
  stream on the device is being captured. DLTensorGraveyard now puts pending
  deletions back in the queue and retries after a short wait instead of
  propagating the error.

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
* Torchvision ColorJitter and Grayscale implementations

Signed-off-by: Marek Dabek <mdabek@nvidia.com>
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_gaussian_blur branch 3 times, most recently from 9a2fbb5 to 73b0d56 Compare April 2, 2026 11:10
Signed-off-by: Marek Dabek <mdabek@nvidia.com>
@mdabek-nvidia mdabek-nvidia force-pushed the torchvision_gaussian_blur branch from 73b0d56 to 52c9006 Compare April 2, 2026 11:14
@mdabek-nvidia
Copy link
Copy Markdown
Collaborator Author

!build

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [47536002]: BUILD STARTED

@dali-automaton
Copy link
Copy Markdown
Collaborator

CI MESSAGE: [47536002]: BUILD PASSED

@mdabek-nvidia mdabek-nvidia merged commit fa4e029 into NVIDIA:main Apr 2, 2026
7 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