#4653·kornia

RandomMotionBlur3D crashes for B > 1 when kernel_size is a range (per-sample draw, per-call kernel)

Author: ducha-aikiCreated Sep 18, 2026Updated Sep 18, 2026

Summary

RandomMotionBlur3D with a kernel_size range crashes for almost every batch with B > 1: the generator draws one size per sample, and apply_transform does int(params["ksize_factor"].unique().item()).

python
import torch, kornia.augmentation as K
x = torch.rand(6, 1, 4, 5, 6); c = 0
for s in range(100):
    torch.manual_seed(s)
    try: K.RandomMotionBlur3D((3, 7), 35., 0.5, p=1.)(x)
    except RuntimeError: c += 1
print(c)   # 99 / 100: "a Tensor with 2 elements cannot be converted to Scalar"

B=2 crashes on 46/100 seeds; same_on_batch=True never crashes. The Args text promises the range is drawn "batch-wisely". The 2D twin was #1540 (closed).

Also: the range (3, 7) only ever draws 3 and 5 (300 seeds, B=1) — the 3D twin of #4599, whose body covers the 2D class only.

Expected

Draw one kernel size per call (as the docstring says and as the 2D class does), including the upper bound.

Measured on main @ c643312a3 merged with #4634 (docs-only), torch 2.14.0, CPU, macOS arm64. Found while reviewing #4634 (batch 6d of #4407).

Posted on behalf of @ducha-aiki by Claude (Fable 5.1).