Skip to main content

Ascend-variant-provider

A variant provider plugin for the Wheel Variant upcoming proposed standard that enables automatic detection and selection of Ascend NPU-optimized Python packages.

How it works

Variant Property Format

Variant Properties emitted follow a three-tuple structure

namespace :: feature :: value

Examples:

  • ascend :: npu_type :: 910b - Means: This wheel can be only used on Ascend A2 series.

Detection Process

  1. Initialization: The plugin uses Ascend npu-smi tool to query hardware information
  2. Hardware Detection: Identifies all Ascend NPUs and their types.
  3. Property Generation: Creates variant properties in the format ascend :: feature :: value

Usage

Test on Local

1. Prepare Your Project

Here we use python-helloworld to do the fast test, clone the source code

mkdir -p /workspace
cd /workspace
git clone https://github.com/dbarnett/python-helloworld.git

cd python-helloworld

Add variant configuration to your pyproject.toml:

# add below lines to the end of pyproject.toml

[variant.default-priorities]
namespace = ["ascend"]

[variant.providers.ascend]
requires = ["ascend-variant-provider>=0.0.1,<1.0.0"]
enable-if = "platform_system == 'Linux'"
plugin-api = "ascend_variant_provider.plugin:AscendVariantPlugin"

Build the wheel for python-helloworld

python -m build --wheel

2. Inject Property into Wheels

We use variantlib to add the property of Ascend NPU type into wheels.

Install variantlib from source

# we have to install from source at this time, because the version of `variantlib` on pypi is incompatible with `uv-wheelnext`

cd /workspace
git clone https://github.com/wheelnext/variantlib.git

cd variantlib
uv pip install --system .

variantlib --version
# variantlib version: 0.0.2

Install uv-wheelnext

# Linux

cd /workspace
curl -LSf https://astral.sh/uv/install.sh | INSTALLER_DOWNLOAD_URL=https://wheelnext.astral.sh sh

Now we can use variantlib to inject hardware information into the built wheel

mkdir -p /workspace/wheels
cd /workspace/wheels

variantlib make-variant \
    -f "/workspace/python-helloworld/dist/helloworld-0.1-py3-none-any.whl" \
    -o "./" \
    --pyproject-toml "/workspace/python-helloworld/pyproject.toml" \
    --property "ascend :: npu_type :: 910b" \
    --skip-plugin-validation

In the same way, we can inject 310p property into wheels

variantlib make-variant \
    -f "/workspace/python-helloworld/dist/helloworld-0.1-py3-none-any.whl" \
    -o "./" \
    --pyproject-toml "/workspace/python-helloworld/pyproject.toml" \
    --property "ascend :: npu_type :: 310p" \
    --skip-plugin-validation

3. Installation Test

Copy ascend_variant_provider-0.0.2-py3-none-any.whl into /workspace/wheels/

Use the following command to test installation

uv pip install --no-index --find-links ./ helloworld --system -vv

If you are running this command on Ascend A2 platform, you will see the key log like the following

TRACE Found namespace ascend with configs VariantProviderOutput { namespace: VariantNamespace("ascend"), features: {VariantFeature("npu_type"): [VariantValue("910b")]} }
TRACE Received variant metadata for: helloworld-0.1 @ file:///workspace/wheels
DEBUG Using variant wheel helloworld-0.1-py3-none-any-38edb458.whl
DEBUG Selecting: helloworld==0.1 [compatible] (helloworld-0.1-py3-none-any-38edb458.whl)

where helloworld-0.1-py3-none-any-38edb458.whl is injected 910b property

$ variantlib analyze-wheel -i  helloworld-0.1-py3-none-any-38edb458.whl

variantlib.commands.analyze_wheel - INFO - Filepath: `helloworld-0.1-py3-none-any-38edb458.whl` ... is a Wheel Variant - Label: `38edb458`
############################## Variant: `38edb458` #############################
ascend :: npu_type :: 910b
################################################################################

You can use ASCEND_VARIANT_PROVIDER_FORCE_NPU_TYPE to overwrite detection for functional test

export ASCEND_VARIANT_PROVIDER_FORCE_NPU_TYPE=310p

In this way, you can install the wheel with property of 310p

uv pip uninstall --system helloworld

uv pip install --no-index --find-links ./ helloworld --system -vv

Then, you will see 310p wheel is installed

TRACE Found namespace ascend with configs VariantProviderOutput { namespace: VariantNamespace("ascend"), features: {VariantFeature("npu_type"): [VariantValue("310p")]} }
TRACE Received variant metadata for: helloworld-0.1 @ file:///workspace/wheels
DEBUG Using variant wheel helloworld-0.1-py3-none-any-aabc2c9e.whl
DEBUG Selecting: helloworld==0.1 [compatible] (helloworld-0.1-py3-none-any-aabc2c9e.whl)

where helloworld-0.1-py3-none-any-aabc2c9e.whl

$ variantlib analyze-wheel -i  helloworld-0.1-py3-none-any-aabc2c9e.whl

variantlib.commands.analyze_wheel - INFO - Filepath: `helloworld-0.1-py3-none-any-aabc2c9e.whl` ... is a Wheel Variant - Label: `aabc2c9e`
############################## Variant: `aabc2c9e` #############################
ascend :: npu_type :: 310p
################################################################################

Metadata

Release files for ascend-variant-provider 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for ascend-variant-provider 0.0.2
File Interpreter ABI Platform
ascend_variant_provider-0.0.2-py3-none-any.whl Python 3 none any Details

Release files / ascend_variant_provider-0.0.2-py3-none-any.whl

Download URL ascend_variant_provider-0.0.2-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63bfe204bee6a0a92e4ac74e2bfcbf261ac9141bdbb5d0158b090380b045bb1c
BLAKE2b-256 checksum
How to use checksums
d0dab2f37ec481b04429a628ba68981a3277cdb0631675bd51bef11a1b30279f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.6

Security for ascend-variant-provider 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page