CoGenAV on Huawei Ascend NPU — contrastive-generative audio-visual representation learning for speech recognition, enhancement, and separation.
CoGenAV (Contrastive-Generative Audio-Visual Representation Learning) is a multimodal framework that learns efficient audio-visual representations through synchronized alignment of speech, lip movements, and text.
| Property | Value |
|---|---|
| Architecture | Transformer Encoder + ResNet Frontend + Delta Upsampler + Feature Adaptation |
| Parameters (Base) | 123.6M |
| Framework | PyTorch 2.9.0 |
| NPU Backend | torch_npu 2.9.0 |
| CANN Version | 8.5.1 |
| Original Model | CoGenAV on ModelScope |
| Paper | arXiv:2505.03186 |
| Task | Abbreviation | Description |
|---|---|---|
| Audio-Visual Speech Recognition | AVSR | Speech recognition using both audio and visual cues |
| Visual Speech Recognition | VSR | Lip-reading only speech recognition |
| Audio-Visual Speech Enhancement | AVSE | Denoising speech using visual guidance |
| Audio-Visual Speech Separation | AVSS | Separating mixed speakers using visual cues |
The model has been adapted to run natively on Huawei Ascend NPU (Atlas 800 A2/A3) with:
| Original | NPU Adaptation |
|---|---|
fairseq TransformerEncoder | Pure PyTorch TransformerEncoder with matching weight layout |
fairseq LayerNorm | Custom LayerNorm using F.layer_norm with weight/bias params |
| fairseq weight_norm Conv1d | Raw nn.Conv1d with automatic weight conversion |
| MultiheadAttention | Custom Q/K/V projection attention module |
pip install torch==2.9.0 torch_npu==2.9.0 numpyimport torch
import torch_npu
from models.cogenav import CoGenAV
# Load model on NPU
device = torch.device("npu:0")
model = CoGenAV(cfg_file="config/base.yaml", model_tensor="weights/base_cogen.pt")
model = model.to(device)
model.eval()
# Prepare input
video = torch.randn(1, 96, 96, 1, 750).to(device) # [B, H, W, C, T]
audio = torch.randn(1, 80, 3000).to(device) # [B, mel_bins, T]
# Run inference
with torch.no_grad():
output = model(video, audio) # [B, T', D]
features = output.permute(0, 2, 1) # [B, D, T'] for downstream tasks# Full evaluation with accuracy verification
python inference.py --mode eval --model_size base --input_type cogenav_av
# Simple inference
python inference.py --mode infer --model_size base --input_type cogenav_v
# With real video/audio inputs
python inference.py --mode infer --video_path /path/to/video.mp4 --audio_path /path/to/audio.wav| Mode | Video | Audio | Use Case |
|---|---|---|---|
cogenav_av | Required | Required | AVSR, full multimodal |
cogenav_v | Required | None | VSR, lip-reading only |
cogenav_a | None | Required | Audio-only speech |
All evaluations use random inputs for baseline verification. NPU inference compared against CPU reference with tolerance < 1%.
| Input Mode | Mean Relative Error | Max Absolute Error | Status |
|---|---|---|---|
cogenav_av (Audio+Video) | 0.30% | 0.021 | PASSED |
cogenav_v (Video only) | 0.30% | 0.021 | PASSED |
cogenav_a (Audio only) | 0.39% | 0.022 | PASSED |
Hardware: Ascend 910 NPU (Atlas 800) CANN: 8.5.1 torch_npu: 2.9.0.post1
| Input Mode | Mean Latency (ms) | Median Latency (ms) | Throughput (samples/s) |
|---|---|---|---|
cogenav_av | 58.05 | 58.04 | 17.23 |
cogenav_v | 57.99 | 58.03 | 17.24 |
cogenav_a | 15.11 | 15.10 | 66.18 |
| Metric | Value |
|---|---|
| NPU Inference (av) | 283 ms |
| CPU Inference (av) | 15,774 ms |
| Speedup | 55.7x |
cogenav/
├── inference.py # Main NPU inference script with evaluation
├── test_npu_load.py # NPU loading and functionality test
├── fairseq_compat.py # NPU-compatible fairseq replacements
├── config_loader.py # YAML config loader (omegaconf fallback)
├── models/
│ ├── cogenav.py # CoGenAV model definition (NPU-adapted)
│ ├── resnet.py # ResNet video encoder
│ └── sepformer.py # SepFormer for AVSE/AVSS
├── config/
│ ├── base.yaml # Base model config (123M params)
│ └── large.yaml # Large model config
├── weights/
│ ├── base_cogen.pt # Base model weights
│ └── large_cogen.pt # Large model weights
└── README.md # This fileThis model is released under the Apache 2.0 license. See the original ModelScope page for details.
@article{cogenav2025,
title={CoGenAV: Contrastive-Generative Audio-Visual Representation Learning},
journal={arXiv:2505.03186},
year={2025}
}NPU adaptation by AtomGit community. Adapted for Huawei Ascend NPU with torch_npu 2.9.0 + CANN 8.5.1.