KeepNPU is a polite NPU keeper with CLI, service, and MCP interfaces
Project description
KeepNPU
KeepNPU is a small, polite Huawei Ascend NPU keeper for shared machines. It
matches KeepGPU's CLI, service, REST/JSON-RPC, MCP, and dashboard workflows,
using torch_npu and npu-smi for Ascend devices.
It allocates only when utilization backoff permits, keeps the requested device memory signal lightweight, and releases cleanly on exit.
Requirements
- Python 3.9–3.13
- Huawei Ascend driver and CANN runtime
- A mutually compatible PyTorch and
torch_npuinstallation
Load the CANN environment before using KeepNPU when your system does not do so automatically:
source /usr/local/Ascend/ascend-toolkit/latest/bin/setenv.bash
Install
python -m pip install keep-npu
torch and torch_npu are deliberately not installed as package dependencies:
their versions must match the server's CANN and driver stack.
To install the latest unreleased revision directly from GitHub:
python -m pip install 'keep-npu @ git+https://github.com/pzheng460/keep-npu.git'
Blocking mode
Keep all visible NPUs, or select torch-visible ordinals with --npu-ids:
keep-npu --vram 1GiB --interval 60
keep-npu --npu-ids 0,2 --vram 512MiB --interval 30
Press Ctrl+C to release memory. The default utilization threshold is 25%;
KeepNPU backs off while a device is busier than that or telemetry is unknown.
Use --busy-threshold -1 only when you intentionally want to disable backoff.
Service and dashboard
Run the local HTTP service in the foreground:
keep-npu serve --host 127.0.0.1 --port 8765
Open http://127.0.0.1:8765/ for the dashboard. Non-blocking CLI workflows use
the same service and auto-start it on localhost by default:
keep-npu list-npus
keep-npu start --npu-ids 0 --vram 1GiB --interval 60
keep-npu status
keep-npu stop --job-id JOB_ID
keep-npu stop --all
keep-npu service-stop
The service exposes GET /health, GET /api/npus, and session CRUD under
/api/sessions. JSON-RPC is available at the exact /rpc endpoint, including
MCP-shaped tools/list and tools/call messages. As in KeepGPU 1.0, HTTP mode
is not a Streamable HTTP MCP endpoint; standards-based MCP transport is stdio.
MCP server
For a local MCP client using stdio:
keep-npu-mcp-server --mode stdio
For HTTP transport:
keep-npu-mcp-server --mode http --host 127.0.0.1 --port 8765
The MCP tools are start_keep, stop_keep, status, and list_npus.
Ascend device semantics
--npu-ids always addresses the visible ordinal used by torch.npu, after
ASCEND_RT_VISIBLE_DEVICES filtering. list-npus additionally reports the
physical ID when it can be derived safely. Memory comes from torch.npu with
best-effort npu-smi telemetry; unavailable values are returned as null
instead of being guessed.
See KeepGPU compatibility for the exact public-name mapping and intentional Ascend differences.
Development
python -m pip install -e '.[dev]'
PYTHONPATH=src python -m pytest
cd web/dashboard && npm ci && npm test -- --run && npm run build
Hardware tests use the ascend pytest marker and conservative memory sizes.
The original standalone keep_npu_alive.py entry point remains available for
backward compatibility.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keep_npu-1.0.0.tar.gz.
File metadata
- Download URL: keep_npu-1.0.0.tar.gz
- Upload date:
- Size: 111.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
895935f980ce881b4cc916429eff7a057a1425a53f5692348625282b483dc041
|
|
| MD5 |
e63fef58a930e827854b50cceefee479
|
|
| BLAKE2b-256 |
e5ffd81bf664e6c116df4fb66d1ea75358b3763bff057101fe878cdb29e81c40
|
Provenance
The following attestation bundles were made for keep_npu-1.0.0.tar.gz:
Publisher:
publish-pypi.yml on pzheng460/keep-npu
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keep_npu-1.0.0.tar.gz -
Subject digest:
895935f980ce881b4cc916429eff7a057a1425a53f5692348625282b483dc041 - Sigstore transparency entry: 2209899129
- Sigstore integration time:
-
Permalink:
pzheng460/keep-npu@d5448aebf768d0170880043d98c24c8158819dc7 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/pzheng460
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@d5448aebf768d0170880043d98c24c8158819dc7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file keep_npu-1.0.0-py3-none-any.whl.
File metadata
- Download URL: keep_npu-1.0.0-py3-none-any.whl
- Upload date:
- Size: 103.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a158bc75cfef42de3c14ba5f8bcc44746ba61ef6d349fe0927fa984681c51cdf
|
|
| MD5 |
250e23dbdfbdc9e6a4e78ae517046ec2
|
|
| BLAKE2b-256 |
bbf015782a031aec8549083ce8c386df59059e290b9c0f8e20e67453b0714a0e
|
Provenance
The following attestation bundles were made for keep_npu-1.0.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on pzheng460/keep-npu
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keep_npu-1.0.0-py3-none-any.whl -
Subject digest:
a158bc75cfef42de3c14ba5f8bcc44746ba61ef6d349fe0927fa984681c51cdf - Sigstore transparency entry: 2209899155
- Sigstore integration time:
-
Permalink:
pzheng460/keep-npu@d5448aebf768d0170880043d98c24c8158819dc7 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/pzheng460
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@d5448aebf768d0170880043d98c24c8158819dc7 -
Trigger Event:
release
-
Statement type: