luckymitty/hubert-base-960h-itw-deepfake-ascend-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

hubert-base-960h-itw-deepfake (Ascend NPU Adapted)

This repository contains the Ascend NPU adaptation of hubert-base-960h-itw-deepfake, a fine-tuned HuBERT model for audio deepfake detection.

Model Description

  • Architecture: HubertForSequenceClassification
  • Base Model: facebook/hubert-base-ls960
  • Task: Audio deepfake / spoof detection (binary classification)
  • Labels: bona-fide (0), spoof (1)
  • Input: Raw audio waveform (16 kHz)
  • Output: Logits over 2 classes

Original Metrics

  • Loss: 0.0756
  • Accuracy: 0.9873
  • FAR: 0.0083
  • FRR: 0.0203
  • EER: 0.0143

Ascend NPU Adaptation

Environment Requirements

ComponentVersion
Python>= 3.9
PyTorch>= 2.0.0
torch-npu>= 2.9.0
transformers>= 4.38.0
Ascend Driver25.5.2 or compatible

Hardware: Ascend 910 NPU (tested on Atlas 800 A2)

Key Changes for NPU Adaptation

  1. Device Mapping

    • Changed torch.device("cuda") to torch.device("npu") for Ascend hardware.
    • Added automatic fallback: NPU -> CUDA -> CPU.
  2. Model Loading

    • Used transformers.AutoConfig and HubertForSequenceClassification for standard loading.
    • No custom CUDA kernels or Triton operators detected; all operators are native PyTorch and fully supported by torch_npu.
  3. No Architecture Changes

    • The model is a standard transformers architecture; no weight remapping or operator replacement was required.

Adaptation Steps

# 1. Clone this repository
git clone <repo-url>
cd hubert-npu-adapted

# 2. Install dependencies
pip install -r requirements.txt

# 3. Run inference on NPU
python inference_npu.py --model_path ./hubert-base-960h-itw-deepfake

# 4. Run accuracy verification (CPU vs NPU)
python verify_accuracy.py

Accuracy Verification

We compared the model outputs on CPU and Ascend NPU using randomly initialized weights (structure validation) with multiple random seeds.

Comparison Metrics

MetricValue
Max Absolute Error2.42e-04
Mean Absolute Error1.79e-04
Max Relative Error2.81e-03
Mean Relative Error2.03e-03
Cosine Similarity0.999997

Multi-Seed Stability

SeedMax Abs ErrorCosine Similarity
422.72e-040.99999832
1232.62e-040.99999812
4562.33e-040.99999839
7892.82e-040.99999817
20242.13e-040.99999869

Conclusion: The CPU and NPU outputs are numerically consistent. The absolute error is within the expected floating-point precision tolerance (< 1e-3). The model is verified for Ascend NPU deployment.

Usage

Quick Start on Ascend NPU

import torch
import torch_npu
import numpy as np
from transformers import AutoConfig, Wav2Vec2FeatureExtractor, HubertForSequenceClassification

# Use NPU
device = torch.device("npu" if torch.npu.is_available() else "cpu")

model_path = "./hubert-base-960h-itw-deepfake"
config = AutoConfig.from_pretrained(model_path)
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(model_path)
model = HubertForSequenceClassification.from_pretrained(model_path, config=config).to(device)
model.eval()

# Dummy audio (replace with real waveform)
audio = np.random.randn(16000).astype(np.float32) * 0.1
inputs = feature_extractor(audio, sampling_rate=16000, return_tensors="pt", padding=True)
input_values = inputs.input_values.to(device)

with torch.no_grad():
    logits = model(input_values).logits
    probs = torch.softmax(logits, dim=-1)

print(probs)  # [[bona-fide_prob, spoof_prob]]

Batch Inference

audio_batch = [np.random.randn(16000).astype(np.float32) for _ in range(4)]
inputs = feature_extractor(audio_batch, sampling_rate=16000, return_tensors="pt", padding=True)
input_values = inputs.input_values.to(device)
with torch.no_grad():
    logits = model(input_values).logits
    probs = torch.softmax(logits, dim=-1)

Files

FileDescription
inference_npu.pyNPU inference script with automatic device selection
verify_accuracy.pyCPU vs NPU accuracy comparison script
accuracy_report.jsonDetailed accuracy metrics JSON
requirements.txtPython dependencies

License

Apache-2.0

Acknowledgments

  • Original model by abhishtagatya
  • Base model: facebook/hubert-base-ls960
  • Ascend NPU adaptation by Ascend-SACT