Skip to main content

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_npu installation

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 reads Ascend's total NPU utilization (including AI Core and AI Vector work) and 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

keep_npu-1.0.2.tar.gz (111.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keep_npu-1.0.2-py3-none-any.whl (103.8 kB view details)

Uploaded Python 3

File details

Details for the file keep_npu-1.0.2.tar.gz.

File metadata

  • Download URL: keep_npu-1.0.2.tar.gz
  • Upload date:
  • Size: 111.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for keep_npu-1.0.2.tar.gz
Algorithm Hash digest
SHA256 c87db5d671868d9bb918b744e02b068e1bf4d5a9fc5fe87f1bce35531d353fa9
MD5 d75cb306426947de46ccaf2bb4f31315
BLAKE2b-256 86fda24a336813f4c413b7eca3c0bf81c284966bd311c5939cc5fcf42d39ec17

See more details on using hashes here.

Provenance

The following attestation bundles were made for keep_npu-1.0.2.tar.gz:

Publisher: publish-pypi.yml on pzheng460/keep-npu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file keep_npu-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: keep_npu-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 103.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for keep_npu-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0b57c473f367e847ac8cd53028233b32365a7f94b4a4238a82e57cb5ed43049a
MD5 2a40b6cae1363e9f704058bfe8205a8e
BLAKE2b-256 9e859a40df799587daed60456ea19bc09388a064fee16b16f0b4cc0ed91547fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for keep_npu-1.0.2-py3-none-any.whl:

Publisher: publish-pypi.yml on pzheng460/keep-npu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page