[NPU] reduce_sum_across_dp_group builds the all_reduce tensor on CPU when CUDA is unavailable
Maintainers usually reply within 4 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- distributed-systems
Research direction
Start in xtuner/v1/datasets/dataloader.py at reduce_sum_across_dp_group(), then inspect its callers through Dataloader.get_state_dict(). Reproduce the two-rank collective on an accelerator-backed process group and verify completion when the tensor uses the mesh device; done means both ranks report the expected reduced value without a CPU-backend error.
Written by the indexing model from the issue text.
Description
What happens
On a host without CUDA (for example an Ascend NPU host, where torch.cuda.is_available() is False), reduce_sum_across_dp_group() in xtuner/v1/datasets/dataloader.py builds the tensor for the DP all_reduce on CPU:
if torch.cuda.is_available():
device = torch.device(f"cuda:{torch.cuda.current_device()}")
else:
device = torch.device("cpu")
tensor = torch.tensor([local_value], dtype=torch.int64, device=device)
dist.all_reduce(tensor, op=dist.ReduceOp.SUM, group=dp_mesh.get_group())
The process group comes from dp_mesh, i.e. it is an NCCL/HCCL group on the accelerator, so handing it a CPU tensor fails.
Real-machine evidence
Ascend 910B4, torch 2.15.0.dev + torch_npu, 2 processes via torchrun, real HCCL process group, reduce_sum_across_dp_group(DeviceMesh("npu", [0, 1]), 3) with the unmodified file:
[rank0] current npu device=0 mesh.device_type=npu
[rank0] RAISED RuntimeError: No backend type associated with device type cpu
[rank1] current npu device=1 mesh.device_type=npu
[rank1] RAISED RuntimeError: No backend type associated with device type cpu
This is not an exotic path: it is reached from Dataloader.get_state_dict(), which is used when saving/restoring dataloader state, so on Ascend the dataloader state cannot be written at all.
Proposed fix
dp_mesh is guaranteed non-None at that point (the early return above handles None), and it already carries the device type of the collective, so use it instead of assuming CUDA:
device = torch.device(dp_mesh.device_type)
That is device-agnostic (cuda / npu / xpu / cpu) and keeps a CPU mesh working. I have the fix ready and verified on the same 2-rank HCCL setup (RESULT=6 expected=6 on both ranks) - opening a PR right after this.
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 466
- Avg merge
- 5d 8h
- Merged PRs (30d)
- 44
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from InternLM/xtuner
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Maintainers usually reply within 4 days
-
enhancement good first issue
Difficulty 3/5 1-2 days Newbie friendliness 62/100
InternLM/xtuner#2246 · 3 comments ·
Maintainers usually reply within 4 days
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
InternLM/xtuner#2134 · 1 reaction ·
Maintainers usually reply within 4 days
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
InternLM/xtuner#2118 · 6 comments ·
Maintainers usually reply within 4 days
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
Maintainers usually reply within 4 days
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Techiebutler/freeframe#687 ·
Maintainers usually reply within 1 day
-
Parse truncated verbose GC logs up to the first XML errorPossibly taken A pull request linked to this issue is open or already merged. Openbug verbose GC
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
IBM/javacore-analyser#677 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 2 days
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
NousResearch/hermes-agent#163932 · 1 comment ·
Maintainers usually reply within 1 day
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's filePossibly taken @Beehtrix claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zilliztech/memsearch#907 · 1 comment ·
Maintainers usually reply within 1 day