vision
vision copied to clipboard
torchvision causes av frame generation to hang
🐛 Describe the bug
Using torchvision with av with video threading mode of AUTO or FRAME causes a hang. Note, you don't even need to use torchvision, just importing it causes the issue.
Minimal reproducing example:
from pathlib import Path
import sys
import av
# Comment this out and it doesn't hang
import torchvision.transforms.v2.functional
THIS_DIR = Path(__file__).parent
vids = THIS_DIR.glob('*.mp4')
for vid in vids:
print('VID:', vid)
sys.stdout.flush()
with av.open(vid, mode='r') as container:
assert len(container.streams.video) == 1
# Comment this out and it doesn't hang
container.streams.video[0].thread_type = 'AUTO'
for i, frame in enumerate(container.decode(video=0)):
print('Frame:', frame)
sys.stdout.flush()
if i == 2:
break
The keys here are (1) you have to import torchvision - if you don't it works fine (2) you have to specify thread_type = 'AUTO' or thread_type = 'FRAME' or it doesn't hang and (3) you have to stop decoding the video before you reach the end - if you decode all frames it's fine.
What happens is it hits the break line but doesn't actually break. I will also report this to pyav and come back and link the bug here as it's not clear whose bug it is.
I think this will happen on just about any video but, if not, I'm happy to provide the mp4 files that are exhibiting the bug for me.
Versions
PyTorch version: 2.6.0+cu118 Is debug build: False CUDA used to build PyTorch: 11.8 ROCM used to build PyTorch: N/A
OS: Debian GNU/Linux 12 (bookworm) (x86_64) GCC version: (Debian 12.2.0-14) 12.2.0 Clang version: Could not collect CMake version: version 3.25.1 Libc version: glibc-2.36
Python version: 3.10.6 (main, Sep 23 2024, 14:30:29) [GCC 12.2.0] (64-bit runtime) Python platform: Linux-6.1.0-32-amd64-x86_64-with-glibc2.36 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: Quadro P520 Nvidia driver version: 535.216.01 cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True
CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 8 On-line CPU(s) list: 0-7 Vendor ID: GenuineIntel Model name: Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz CPU family: 6 Model: 142 Thread(s) per core: 2 Core(s) per socket: 4 Socket(s): 1 Stepping: 12 CPU(s) scaling MHz: 67% CPU max MHz: 4900.0000 CPU min MHz: 400.0000 BogoMIPS: 4599.93 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 128 KiB (4 instances) L1i cache: 128 KiB (4 instances) L2 cache: 1 MiB (4 instances) L3 cache: 8 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-7 Vulnerability Gather data sampling: Mitigation; Microcode Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Mitigation; Enhanced IBRS Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop Vulnerability Srbds: Mitigation; Microcode Vulnerability Tsx async abort: Not affected
Versions of relevant libraries: [pip3] numpy==2.2.4 [pip3] nvidia-cublas-cu11==11.11.3.6 [pip3] nvidia-cuda-cupti-cu11==11.8.87 [pip3] nvidia-cuda-nvrtc-cu11==11.8.89 [pip3] nvidia-cuda-runtime-cu11==11.8.89 [pip3] nvidia-cudnn-cu11==9.1.0.70 [pip3] nvidia-cufft-cu11==10.9.0.58 [pip3] nvidia-curand-cu11==10.3.0.86 [pip3] nvidia-cusolver-cu11==11.4.1.48 [pip3] nvidia-cusparse-cu11==11.7.5.86 [pip3] nvidia-nccl-cu11==2.21.5 [pip3] nvidia-nvtx-cu11==11.8.86 [pip3] torch==2.6.0+cu118 [pip3] torchvision==0.21.0+cu118 [pip3] triton==3.2.0 [conda] Could not collect