fix(runtime): bind NPU device before Mooncake transport setup#1
Draft
curnane-lab wants to merge 1 commit into
Draft
fix(runtime): bind NPU device before Mooncake transport setup#1curnane-lab wants to merge 1 commit into
curnane-lab wants to merge 1 commit into
Conversation
The disaggregated capture producer builds the Mooncake store at run-assembly time and deliberately never runs init_distributed (to avoid initializing an accelerator just to publish feature refs). On Ascend, MooncakeDistributedStore.setup() installs the AscendDirectTransport, which calls aclrtGetDevice and fails with ACL_ERROR_RT_CONTEXT_NULL (107002) because the process has no bound NPU context, aborting the run before training starts. Bind the local NPU (via the existing rank-aware _bind_local_device) right before the real store setup. Detection tolerates a producer that has not yet imported torch_npu by activating it only when Ascend visible-device env vars are set. CUDA/CPU paths are unaffected: CUDA's transport needs no explicit device and the producer still avoids initializing CUDA. Co-authored-by: curnane-lab <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Launching an online disaggregated training run on Ascend NPU (e.g.
specforge train -c examples/configs/qwen3.5-4b-domino-online-npu.yaml) aborts during startup with:Ascend error
107002isACL_ERROR_RT_CONTEXT_NULL— no device context has been established for the calling process. The failing process is the disaggregated capture producer (specforge/cli.py:126), which deliberately skipsinit_distributed()so it never initializes an accelerator "merely to publish feature refs". On Ascend, however,MooncakeDistributedStore.setup()installs theAscendDirectTransport, which callsaclrtGetDevice; with no NPU bound to the process, that call fails and the whole run dies before training starts.(The trainer/consumer role already binds its NPU in
init_distributedbefore building the store, so it was unaffected — but the producer failure tears the job down.)Modifications
_bind_transport_device()inspecforge/runtime/data_plane/mooncake_store.py, called inside_connect_store()immediately beforeMooncakeDistributedStore.setup(), so the local NPU context exists before the Ascend transport is installed.specforge.distributed._bind_local_device(readsLOCAL_RANK/RANK), so every rank pins the transport to its own NPU and the call is idempotent with the trainer's earlier binding.set_device, and the producer intentionally avoids initializing CUDA, so CUDA/CPU paths are left untouched._ascend_runtime_available()to robustly detect Ascend on a producer that has not yet importedtorch_npu(soget_device_type()still reportscpu). It only activatestorch_npuwhen Ascend visible-device env vars (ASCEND_RT_VISIBLE_DEVICES/ASCEND_VISIBLE_DEVICES) are set, avoiding a spurioustorch_npuimport on CUDA/CPU hosts, and degrades gracefully if the import or availability check fails.torch_npuis not yet active, the env-gatedtorch_npuactivation, and that_connect_storebinds the device beforesetup().Related Issues
Fixes the Ascend NPU online disaggregated launch failure (
Mooncake setup failed (status -600)/aclrtGetDevice107002).Accuracy Test
Not applicable — no model/kernel/architecture changes; this only fixes device-context binding ordering in the data-plane transport setup.
Benchmark & Profiling
Not applicable — no steady-state performance impact; the added binding runs once during store construction.
Checklist
black,isort,autoflakeclean)tests/test_runtime/test_mooncake_store.py::TestMooncakeTransportDeviceBinding)