torchao-ascend:基于 TorchAO 量化生态的昇腾 NPU 适配项目

Ascend Extension for TorchAO

Branch5Tags1
FilesLast commitLast update
24 days ago
2 months ago
19 days ago
19 days ago
18 days ago
18 days ago
2 months ago
2 months ago
2 months ago
19 days ago
20 days ago
20 days ago
20 days ago
2 months ago
2 months ago
20 days ago
20 days ago
20 days ago
20 days ago
20 days ago
20 days ago
2 months ago
20 days ago
22 days ago
2 months ago

Ascend for TorchAO

An Ascend NPU adaptation plugin for torchao

简体中文 | English

Supported Versions · Build and Installation · Quick Start · Contributing Guide · Community

python pytorch torchao platform repo


Introduction

Ascend for TorchAO (torchao-ascend) is an Ascend NPU adaptation plugin for the quantization ecosystem torchao. It enables torchao's quantization schemes (FP8 / Blockwise FP8 / MX series) as well as the Ascend-native HiFloat8 (HIF8) data type to run on Ascend NPUs, supporting both quantized training and inference scenarios.

What's New

  • 📢 [2026-09-01] torchao-ascend 0.18.0 has completed adaptation development. It supports torchao 0.18.x and PyTorch 2.11+, covers the FP8 / Blockwise FP8 / MXFP8 / HiFloat8 quantization schemes, and provides quantized training and inference capabilities.

Supported Versions

The following versions are currently supported:

  • Python >= 3.10
  • PyTorch >= 2.11.0
  • torchao >= 0.18.0, < 0.19.0
  • CANN >=9.2.0

For the compatibility between torch_npu and CANN, refer to the TorchNPU version compatibility table.

Build and Installation

Download the master branch code

Run the following commands to download the master branch code and enter the TorchAONPU plugin root directory:

git clone https://gitcode.com/Ascend/torchao-ascend.git
cd torchao-ascend

Install environment dependencies

Install PyTorch

Run the following command to install PyTorch 2.11.0:

pip install torch==2.11.0 --index-url https://download.pytorch.org/whl/cpu

Install TorchNPU

Run the following command to install TorchNPU 2.11.0:

pip install torch-npu==2.11.0

Install torchao-ascend

Both editable installation from source and building a wheel for installation are supported:

Option 1: Editable installation

Suitable for local development and debugging:

pip install -e .

Option 2: Build a wheel and install

Suitable for production deployment. First build the wheel, then install the generated wheel:

bash ci/build.sh
pip install dist/*.whl

Building requires Python >= 3.10. To specify an interpreter:

bash ci/build.sh --python=3.10

To skip the build isolation environment (use dependencies from the current environment):

bash ci/build.sh --no-isolation

The generated wheel is located in the dist/ directory.

Quick Start

MXFP8 inference example

import torch

from torchao.prototype.mx_formats import MXDynamicActivationMXWeightConfig
from torchao.quantization import quantize_

model = model.to("npu").eval()
quantize_(
    model,
    MXDynamicActivationMXWeightConfig(
        activation_dtype=torch.float8_e4m3fn,
        weight_dtype=torch.float8_e4m3fn,
        block_size=32,
    ),
)

with torch.no_grad():
    output = model(input_tensor.to("npu"))

HiFloat8 training example

import torch
from torchao.quantization import quantize_
from torchao.hifloat8 import HiFloat8LinearConfig, linear_filter_fn

model = model.to("npu").train()
quantize_(model, HiFloat8LinearConfig(), filter_fn=linear_filter_fn)

optimizer = torch.optim.AdamW(model.parameters(), lr=1e-4)
loss = model(input_tensor.to("npu")).sum()
loss.backward()
optimizer.step()

For more examples (inference, custom filter_fn quantization scope, MoE expert grouped GEMM training, etc.), see the HiFloat8 usage guide (in Chinese).

Model Support Overview

torchao-ascend currently supports low-precision training for a variety of mainstream open-source models. For details, see the model training support guide (in Chinese).

Feature Support Overview

This table shows the feature support status of torchao-ascend across different hardware devices, quantization data types, and training modes.

Hardware weight activation QAT quantized training quantized inference
Ascend950DT mxfp8 bf16 ✅
Ascend950DT mxfp4 mxfp8 ✅(moe)
Ascend950DT hifp8 hifp8 ✅ ✅
Ascend950DT hifp4 hifp8
Ascend950DT mxfp8 mxfp8 ✅ ✅(dense),(moe)
Ascend950DT mxfp4 mxfp4 ✅
Ascend950DT fp8 fp8

The linked workflow documents are currently available in Chinese only.

Environment Variables

TorchAONPU reuses PyTorch's device-backend auto-loading channel. It is activated automatically the first time import torchao is executed in an NPU environment, without requiring an explicit import torchao_npu. To disable auto-activation, see the environment variable list (in Chinese).

Community

Ascend for TorchAO is built on the Ascend and torchao open-source ecosystems, providing quantization adaptation capabilities for the Ascend NPU platform. You are welcome to join the discussion and contribute in the following ways:

  • If you run into any problems or have suggestions, please submit an Issue and we will respond as soon as possible.
  • Pull Requests are welcome. For code standards and the submission process, see the Contributing Guide.
  • For more Ascend developer tools and documentation, visit the Ascend community.

Thank you for your support.

Security Notes

For system security hardening, recommended runtime users, and file permission control of Ascend for TorchAO, see the Security Notes.

Disclaimer

This plugin is for debugging and development purposes only. Users must ensure the security of the commands they enter and properly control access to the data generated during use. By using this plugin, you agree to and accept the above statements.

License

The open-source license of this project is subject to the License statement maintained in this repository.

Acknowledgements

Thanks for every PR from the community — contributions to Ascend for TorchAO are welcome!

Introduction

Ascend Extension for TorchAO

Customize your domain