weixin_62994174/cogenav
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

CoGenAV-Ascend: NPU-Adapted Audio-Visual Representation Learning

CoGenAV on Huawei Ascend NPU — contrastive-generative audio-visual representation learning for speech recognition, enhancement, and separation.

Model Overview

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.

PropertyValue
ArchitectureTransformer Encoder + ResNet Frontend + Delta Upsampler + Feature Adaptation
Parameters (Base)123.6M
FrameworkPyTorch 2.9.0
NPU Backendtorch_npu 2.9.0
CANN Version8.5.1
Original ModelCoGenAV on ModelScope
PaperarXiv:2505.03186

Supported Tasks

TaskAbbreviationDescription
Audio-Visual Speech RecognitionAVSRSpeech recognition using both audio and visual cues
Visual Speech RecognitionVSRLip-reading only speech recognition
Audio-Visual Speech EnhancementAVSEDenoising speech using visual guidance
Audio-Visual Speech SeparationAVSSSeparating mixed speakers using visual cues

NPU Adaptation

The model has been adapted to run natively on Huawei Ascend NPU (Atlas 800 A2/A3) with:

  • Self-contained inference: No fairseq dependency — replaced with pure PyTorch ops that work on NPU
  • Weight compatibility: Automatic fairseq weight_norm → raw weight conversion
  • Precision preservation: FP32 inference with sub-0.4% error vs CPU

Adaptation Strategy

OriginalNPU Adaptation
fairseq TransformerEncoderPure PyTorch TransformerEncoder with matching weight layout
fairseq LayerNormCustom LayerNorm using F.layer_norm with weight/bias params
fairseq weight_norm Conv1dRaw nn.Conv1d with automatic weight conversion
MultiheadAttentionCustom Q/K/V projection attention module

Quick Start

Requirements

pip install torch==2.9.0 torch_npu==2.9.0 numpy

Inference

import 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

CLI Usage

# 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

Input Modes

ModeVideoAudioUse Case
cogenav_avRequiredRequiredAVSR, full multimodal
cogenav_vRequiredNoneVSR, lip-reading only
cogenav_aNoneRequiredAudio-only speech

Evaluation Results

Accuracy (NPU vs CPU Reference)

All evaluations use random inputs for baseline verification. NPU inference compared against CPU reference with tolerance < 1%.

Input ModeMean Relative ErrorMax Absolute ErrorStatus
cogenav_av (Audio+Video)0.30%0.021PASSED
cogenav_v (Video only)0.30%0.021PASSED
cogenav_a (Audio only)0.39%0.022PASSED

Performance Benchmark

Hardware: Ascend 910 NPU (Atlas 800) CANN: 8.5.1 torch_npu: 2.9.0.post1

Input ModeMean Latency (ms)Median Latency (ms)Throughput (samples/s)
cogenav_av58.0558.0417.23
cogenav_v57.9958.0317.24
cogenav_a15.1115.1066.18

NPU vs CPU Speedup

MetricValue
NPU Inference (av)283 ms
CPU Inference (av)15,774 ms
Speedup55.7x

Project Structure

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 file

License

This model is released under the Apache 2.0 license. See the original ModelScope page for details.

Citation

@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.