MambaVision-B is a hybrid vision model combining Mamba (State Space Models) with self-attention for image classification, developed by NVIDIA. This repository provides an Ascend NPU-adapted inference pipeline that enables deployment on Huawei Ascend 910 hardware without requiring CUDA-dependent mamba_ssm kernels.
| Property | Value |
|---|---|
| Model | MambaVision-B-1K |
| Task | Image Classification (ImageNet-1K) |
| Parameters | 97.69M |
| Input | 224x224 RGB image |
| Output | 1000-class probability distribution |
| Original Framework | PyTorch + mamba_ssm (CUDA) |
| NPU Adaptation | Pure PyTorch selective scan (Ascend-compatible) |
| CANN Version | 8.5.1 |
| Ascend Hardware | Ascend 910 (Atlas 800 A2) |
MambaVision combines three architectural paradigms across 4 stages:
| Stage | Depth | Type | Resolution |
|---|---|---|---|
| 1 | 3 | ConvBlocks | 56x56 |
| 2 | 3 | ConvBlocks | 28x28 |
| 3 | 10 | Mamba SSM + Self-Attention | 14x14 |
| 4 | 5 | Mamba SSM + Self-Attention | 7x7 |
The key innovation is using Mamba selective scan (S6 SSM) in early blocks and transitioning to self-attention in later blocks within each transformer stage.
The original model relies on mamba_ssm.ops.selective_scan_interface.selective_scan_fn, a CUDA-optimized kernel incompatible with Ascend NPU. This adaptation replaces it with a pure PyTorch implementation of the selective scan algorithm that works on CPU, CUDA, and Ascend NPU.
mamba_ssm CUDA kernel with selective_scan_pytorch() -- a pure PyTorch sequential scan implementing the S6 recurrencegamma_1/gamma_2 to model g_1/g_2 (layer scale parameters)torch_npu# Ascend NPU environment
torch >= 2.9.0
torch_npu >= 2.9.0
CANN >= 8.5.1
# Dependencies
pip install torchvision timm einops pillowpip install modelscope
modelscope download --model nv-community/MambaVision-B-1K# NPU inference
python inference.py --device npu
# CPU inference
python inference.py --device cpu
# With custom image
python inference.py --device npu --image /path/to/image.jpg# Compare NPU vs CPU precision
python accuracy_test.py
# With custom tolerance
python accuracy_test.py --tolerance 0.01# NPU benchmark
python benchmark.py --device npu:0
# Custom runs
python benchmark.py --warmup 20 --runs 200| Metric | Value | Threshold | Status |
|---|---|---|---|
| Mean Absolute Error | 4.2x10^{-7} | < 1x10^{-2} | PASS |
| Max Absolute Error | 1.61x10^{-4} | -- | -- |
| Max Relative Error | 2.15x10^{-3} | -- | -- |
| SNR | 71.40 dB | -- | -- |
| Cosine Similarity | 1.00000000 | > 0.9999 | PASS |
| Top-1 Match | True | -- | PASS |
| Top-5 Overlap | 5/5 | -- | PASS |
| Metric | Value |
|---|---|
| Mean Latency | 192.54 ms |
| Min Latency | 185.99 ms |
| Max Latency | 195.33 ms |
| Throughput | 5.19 FPS |
| NPU Memory | 0.40 GB / 65.79 GB |
Input: COCO val2017/000000039769.jpg (two cats on a couch)
Rank Class Confidence
1 tabby, tabby cat 0.2825
2 Egyptian cat 0.1323
3 tiger cat 0.1202
4 remote control, remote 0.0532
5 cellular telephone 0.0026mambavision-npu/
|-- inference.py # Main inference script (NPU/CPU)
|-- accuracy_test.py # Accuracy verification (NPU vs CPU)
|-- benchmark.py # Performance benchmark
|-- README.md # This document
|-- results/
|-- accuracy.json # Accuracy test results
|-- benchmark.json # Performance benchmark results
|-- run_log.txt # Full execution log
|-- accuracy_verification.json # Verification details@misc{hatamizadeh2025mambavision,
title={MambaVision: A Hybrid Mamba-Transformer Vision Backbone},
author={Ali Hatamizadeh and Jan Kautz},
year={2025},
eprint={2407.08083},
archivePrefix={arXiv},
primaryClass={cs.CV}
}Apache 2.0 -- see LICENSE in the original NVIDIA repository.
Adapted for Huawei Ascend NPU by implementing pure PyTorch selective scan. Tested on Ascend 910 with CANN 8.5.1 and torch_npu 2.9.0.