-
Notifications
You must be signed in to change notification settings - Fork 746
Open
Description
🐛 Describe the bug
The example code from torchaudio.models.wav2vec2.utils.import_fairseq_model fails due to a shape mismatch between the extracted features and the reference features from the original Fairseq model.
Specifically, for an input of size [1, 16000]:
-
imported.extract_features(waveform)returns a list of 12 tensors shaped [1, 49, 768] -
original.feature_extractor(waveform)returns a tensor of shape [1, 49, 512] -
Attempting to compare the two using
torch.testing.assert_allclose()raises aValueError.
Minimal reproducing example
import os
import torch
import torchaudio
from urllib.request import urlretrieve
import fairseq
from torchaudio.models.wav2vec2.utils import import_fairseq_model
# Download Fairseq checkpoint if not already present
url_w2v = "https://dl.fbaipublicfiles.com/fairseq/wav2vec/wav2vec_small.pt"
CHECKPOINT_PATH = './pt-models/wav2vec_small.pt'
os.makedirs(os.path.dirname(CHECKPOINT_PATH), exist_ok=True)
if not os.path.isfile(CHECKPOINT_PATH):
print('Downloading wav2vec 2.0')
urlretrieve(url_w2v, CHECKPOINT_PATH)
print('Completed')
# Load original fairseq model and import into torchaudio
model, _, _ = fairseq.checkpoint_utils.load_model_ensemble_and_task([CHECKPOINT_PATH])
original = model[0]
imported = import_fairseq_model(original)
# Load waveform
waveform = torch.randn(1, 16000) # replace with any .wav file
# Extract features
features, _ = imported.extract_features(waveform)
# Get reference output from fairseq model
reference = original.feature_extractor(waveform).transpose(1, 2)
# Compare — this fails
torch.testing.assert_allclose(features, reference)
Observed error
>>> ValueError: only one element tensors can be converted to Python scalars
More details
type(features) # list
len(features) # 12
features[0].shape # torch.Size([1, 49, 768])
reference.shape # torch.Size([1, 49, 512])
Versions
Collecting environment information...
PyTorch version: 2.5.1+cu124
Is debug build: False
CUDA used to build PyTorch: 12.4
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.16 (main, Feb 12 2025, 14:50:02) [Clang 19.1.6 ] (64-bit runtime)
Python platform: Linux-6.1.0-32-amd64-x86_64-with-glibc2.36
Is CUDA available: True
CUDA runtime version: 0.2.1221
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA RTX A4000
Nvidia driver version: 570.133.20
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: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 32
On-line CPU(s) list: 0-31
Vendor ID: GenuineIntel
Model name: Intel(R) Core(TM) i9-14900K
CPU family: 6
Model: 183
Thread(s) per core: 2
Core(s) per socket: 24
Socket(s): 1
Stepping: 1
CPU(s) scaling MHz: 18%
CPU max MHz: 6000.0000
CPU min MHz: 800.0000
BogoMIPS: 6374.40
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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 896 KiB (24 instances)
L1i cache: 1.3 MiB (24 instances)
L2 cache: 32 MiB (12 instances)
L3 cache: 36 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-31
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Mitigation; Clear Register File
Vulnerability Retbleed: Not affected
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 BHI_DIS_S
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Versions of relevant libraries:
[pip3] Could not collect
[conda] No relevant packagesMetadata
Metadata
Assignees
Labels
No labels