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 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.1.tar.gz (110.9 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.1-py3-none-any.whl (103.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: keep_npu-1.0.1.tar.gz
  • Upload date:
  • Size: 110.9 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.1.tar.gz
Algorithm Hash digest
SHA256 c82f5c536b642c8652a4e1c46bd6898f20caddae5001e4fb06c65f6f420a4e58
MD5 80ff01f8b9d7dc9c13af47bc89fe385d
BLAKE2b-256 65884204776d78125616df02dab3f89de975c82b16634e4d02c018ecd4bd20e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for keep_npu-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: keep_npu-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 103.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7bc818e2a4e2135b4e39e05424894b5ae2629a195044767691b62303dea1c408
MD5 d46c469c3c132a16d91778aaba5f0e9c
BLAKE2b-256 3da2edf8b712665a49cdef82bc73ba09d4ae31f9c90b4e5123c3c91a05899302

See more details on using hashes here.

Provenance

The following attestation bundles were made for keep_npu-1.0.1-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