Files
yanlonghuandyanlonghu a9ad517549 fix(npu): enable expandable prefill allocations and handle pinned-memory exhaustion during suspend (#4131)
## Summary

Follow up on #3667 by requiring [torch-npu-memory-saver
0.1.7](https://pypi.org/project/torch-npu-memory-saver/0.1.7/) in both
the NPU kernel backend and the Ascend extra. Update the installation
hint, serving guide, and exact-version packaging test. The allocator
continues to use ABI 5.

## Why TokenSpeed NPU workers need 0.1.7

- **Prefill fragmentation.** Version 0.1.6 required
`expandable_segments:False` for the entire worker. Ordinary prefill
activations with varying shapes could therefore accumulate unusable
gaps, and enabling expandable segments caused Saver initialization to
fail. With 0.1.7 operators can start the worker with
`PYTORCH_NPU_ALLOC_CONF=expandable_segments:True`. Expansion is disabled
only around Saver-managed allocations and ACL graph capture, then
restored for ordinary allocations. The default in the launch example
stays unchanged.
- **Concurrent suspend and pinned host memory.** A Prefill/Decode pair
backing up weights or other managed bytes at the same time can exhaust
pinned host memory. Previously `aclrtMallocHost` error `207001` aborted
suspend. The new allocator logs a warning, falls back to pageable host
memory for that allocation, and completes the synchronous copy before
unmapping the device pages. Other ACL errors still propagate.
- **Failed allocator restore with waiting callers.** If PTA fails to
restore the expandable-segment setting, a thread that already passed the
initial health check may be waiting on the pool lock. Version 0.1.7
checks again after acquiring that lock. Queued `assert_active`, `pause`,
and `resume` raise a worker-restart error before changing pool state.

The implementation and platform wheel are in the [standalone library
release](https://github.com/yanlonghu/torch_npu_memory_saver/releases/tag/v0.1.7).
This TokenSpeed PR selects that release on Ascend.

## Validation

- Installed 0.1.7 by name from PyPI on A2. Independently installed the
published CPython 3.12/Linux AArch64/CANN 9.0.0 wheel after downloading
it from the GitHub release and checking its SHA-256.
- Ran the current TokenSpeed NPU adapter's four real-device cases with
expandable segments enabled and disabled (8 passes). The three
standalone NPU device cases and all three queued-failure cases passed on
the installed wheel.
- Ran Qwen3 TP2 with the release wheel in the established protocol-3
integration fixture. CPU-backed partial update and full discard/refill
passed. The refilled instance and cold start with the new checkpoint
matched at all 24 output token positions (maximum absolute logprob
difference 0).
- All 31 kernel setup tests passed in isolation, covering
backend-specific package metadata. CUDA/ROCm execution was not tested on
hardware.
- On A3 (CANN 8.5 / CPython 3.11), built and installed a separate
platform wheel from the checksum-verified PyPI sdist. The three
queue-failure cases and three device tests passed.
- LongCat Lite P8+D8 on A3, using the CANN 8.5 wheel built from the
published 0.1.7 sdist: all 16 ranks loaded the matched wheel and native
library. Prefill and Decode suspended and resumed concurrently. All
seven ordinary prefill activation samples (four before suspend and three
after resume) belonged to expandable segments in the default pool. Five
prompts matched across suspend/resume at all 40 output token positions,
with zero absolute logprob difference.

Signed-off-by: yanlonghu <19688573+yanlonghu@users.noreply.github.com>
Co-authored-by: yanlonghu <19688573+yanlonghu@users.noreply.github.com>
2026-12-03 15:41:57 +08:00
..