ColossalAI icon indicating copy to clipboard operation
ColossalAI copied to clipboard

[booster] TorchFSDPPlugin hardcodes torch.cuda.current_device(), breaking non-CUDA accelerators

Open JazyJiang opened this issue 1 month ago • 1 comments

Is there an existing issue for this bug?

  • [x] I have searched the existing issues

The bug has not been fixed in the latest main branch

  • [x] I have checked the latest main branch (cb3b2234)

Describe the bug

TorchFSDPPlugin.configure() passes torch.cuda.current_device() as the FSDP device_id:

# colossalai/booster/plugin/torch_fsdp_plugin.py:540
fsdp_model = TorchFSDPModel(model, device_id=torch.cuda.current_device(), **self.fsdp_kwargs)

On a PyTorch build without CUDA, booster.boost() fails before FSDP is even constructed, so the plugin cannot be used at all.

Expected behaviour: the plugin selects the current device through colossalai.accelerator, the way LowLevelZeroPlugin already does, so it works on whichever accelerator the framework has detected.

This is the only torch.cuda call left under colossalai/booster/plugin, and colossalai.accelerator already detects this machine correctly (get_accelerator().name == "npu"). On the same commit and machine, TorchDDPPlugin and LowLevelZeroPlugin (stage 1 and 2) already run forward/backward/optimizer step, so the problem is specific to this plugin.

Fixing this line is necessary but not sufficient. With it fixed, configure() then fails one step later at optimizer.__init__(fsdp_model.parameters(), **optimizer.defaults) with TypeError: AdamW.__init__() got an unexpected keyword argument 'decoupled_weight_decay'. That is a torch 2.13 change and reproduces on CUDA as well, so it will be filed separately.

Minimal reproducible script

# repro.py
# python -m torch.distributed.run --nproc_per_node 1 repro.py
import torch
import torch_npu  # or whichever non-CUDA accelerator backend

import colossalai
from colossalai.booster import Booster
from colossalai.booster.plugin import TorchFSDPPlugin
from transformers import LlamaConfig, LlamaForCausalLM

colossalai.launch_from_torch()
model = LlamaForCausalLM(
    LlamaConfig(
        vocab_size=1024, hidden_size=128, intermediate_size=256,
        num_hidden_layers=2, num_attention_heads=4, num_key_value_heads=4,
    )
)
optimizer = torch.optim.AdamW(model.parameters(), lr=1e-3)
Booster(plugin=TorchFSDPPlugin()).boost(model, optimizer)

Error message and logs

Traceback (most recent call last):
  File "repro.py", line 18, in <module>
    Booster(plugin=TorchFSDPPlugin()).boost(model, optimizer)
  File "colossalai/booster/booster.py", line 154, in boost
  File "colossalai/booster/plugin/torch_fsdp_plugin.py", line 540, in configure
    fsdp_model = TorchFSDPModel(model, device_id=torch.cuda.current_device(), **self.fsdp_kwargs)
  File "torch/cuda/__init__.py", line 1205, in current_device
    _lazy_init()
  File "torch/cuda/__init__.py", line 522, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

ColossalAI version or commit

cb3b2234e1d56ee19aa47f3ace935c09c59efe69 (main)

PyTorch version

2.13.0 (built without CUDA; torch_npu 2.13.0.rc1)

Transformers version

5.17.0

CUDA / NCCL version

N/A - PyTorch is built without CUDA. Ascend equivalents:
  Ascend HDK (driver): 25.2.1, ascendhal 7.35.23
  CANN: 9.1.0 (V100R001C11SPC001B243)
  Collective library: HCCL (not exercised; single process)

GPU model, number of GPUs, number of nodes

8x Ascend 910B2 (64GB) on 1 node, 1 device used.
Host: Kunpeng-920 aarch64, openEuler 22.03 LTS-SP2, Linux 5.10.0, Python 3.12.13.
Container: ascendai/torch-npu:2.13.0rc1-cann9.1.0-910b-openeuler24.03-py3.12

Plugin used

TorchFSDP

Parallel configuration

Single process. No tp / pp / sp / ep, no ZeRO stage.
The failure happens in configure(), before any parallelism is set up.

Output of colossalai check -i

#### Installation Report ####

------------ Environment ------------
Colossal-AI version: 0.5.0
PyTorch version: 2.13.0
System CUDA version: N/A
CUDA version required by PyTorch: N/A

------------ CUDA Extensions AOT Compilation ------------
Found AOT CUDA Extension: ✓
PyTorch version used for AOT compilation: N/A
CUDA version used for AOT compilation: N/A

------------ Compatibility ------------
PyTorch version match: N/A
System and PyTorch CUDA version match: N/A

JazyJiang avatar Oct 26 '26 08:10 JazyJiang

The bug report is precise; adding the ecosystem context: this is the same three-layer device-assumption leak we audited across video-diffusion stacks — (a) import-time default args like device=torch.cuda.current_device(), (b) function-level hardcoded calls like the plugin's, (c) capability/dispatch tables that whitelist device names. TorchFSDPPlugin is layer (b), and routing through colossalai.accelerator like LowLevelZeroPlugin already does is the correct fix; layer (a) is worth a repo-wide grep for the device=torch\.cuda default-argument pattern since those break at import on CPU/MPS/NPU builds before any plugin is even constructed.

One NPU-specific note for whoever tests the fix on 910B: once the device_id issue is resolved and multi-rank FSDP starts initializing, HCCL base-port collisions between concurrent jobs fail silently on the latency axis (collectives succeed, everything just gets ~2x slower) — pin HCCL_EXEC_TIMEOUT/port ranges explicitly in CI so a passing-but-degraded run doesn't get filed as a performance mystery.

Disclosure: this is our own work: https://github.com/maidou75293/ltx-ascend-bench

maidou75293 avatar Nov 04 '26 18:11 maidou75293