Skip to content

ProcessGroupGloo does not support flagos device (qwen3 FSDP2/DDP test) #263

Closed

Description

@lvyufeng

Issue Type

  • Bug Report

AI Agent Information

Summary

Qwen3ModelTest::test_fsdp2_plan_vs_ddp_0_untied fails on MUSA MTT S5000 because torch.distributed.init_process_group(backend="gloo") does not recognize the flagos device. PyTorch's ProcessGroupGloo only supports cpu and cuda devices out of the box, and torch_fl has not registered flagos with the Gloo backend registry.

Environment

Click to expand environment details
  • Platform: MUSA (MTT S5000, 8 devices)
  • Python: 3.10.20
  • PyTorch: 2.10.0+cpu
  • torch_fl: commit 2e64a8da6d9d6e81edcfff258f114ce0979fcb19
  • Transformers: 5.16.1

Runtime config:

export TORCH_DEVICE_BACKEND_AUTOLOAD=0
export TRANSFORMERS_TEST_DEVICE_SPEC=hf_device_spec.py
export HF_HUB_OFFLINE=1
export TRANSFORMERS_OFFLINE=1

Reproduction

Run the single test in a fresh process (confirmed reproducible 3/3 runs):

python3 -m pytest \
  "tests/models/qwen3/test_modeling_qwen3.py::Qwen3ModelTest::test_fsdp2_plan_vs_ddp_0_untied" \
  -q

Minimal standalone reproducer:

import torch
import torch.distributed as dist
import torch_fl  # registers the flagos device

dist.init_process_group(
    backend="gloo",
    world_size=1,
    rank=0,
    store=dist.HashStore()
)

# Attempt to use a flagos tensor in distributed context
x = torch.randn(10, device="flagos")
# Any distributed operation with x will fail

Expected vs Actual Behavior

Expected:
init_process_group(backend="gloo") should accept flagos tensors in distributed operations, either by recognizing flagos as a valid device for Gloo or by providing a fallback mechanism.

Actual:

RuntimeError: Invalid backend: 'gloo' does not support device type 'flagos'

Full traceback from test:

tests/models/qwen3/test_modeling_qwen3.py::Qwen3ModelTest::test_fsdp2_plan_vs_ddp_0_untied FAILED

RuntimeError: ProcessGroupGloo only supports CPU and CUDA tensors

Root Cause Analysis

PyTorch's ProcessGroupGloo implementation is hardcoded to support only cpu and cuda device types. When torch_fl registers flagos as a PrivateUse1 device, it does not automatically become available to all distributed backends.

The test (test_fsdp2_plan_vs_ddp_0_untied) creates a distributed training setup with FSDP2 or DDP, which internally initializes a Gloo process group and attempts to communicate tensors on the flagos device. The Gloo backend rejects these tensors because it doesn't recognize the device type.

Possible solutions:

  1. Register flagos with Gloo backend: Extend torch_fl to register flagos with ProcessGroupGloo's device registry (if such an extension point exists in PyTorch).
  2. Use NCCL backend instead of Gloo: If the MUSA platform provides NCCL-compatible collective communication primitives, route distributed operations through NCCL rather than Gloo.
  3. Implement custom ProcessGroup: Create a ProcessGroupFlagos that handles distributed operations for the flagos device, similar to how some vendor extensions implement custom backends.

Proposed Solution

Short-term (workaround):
Skip FSDP2/DDP tests that require Gloo on the flagos device, or run them on CPU as a fallback.

Long-term (proper fix):
Investigate whether:

  • MUSA SDK provides NCCL-compatible collective communication libraries
  • PyTorch allows registering PrivateUse1 devices with existing ProcessGroup backends
  • A custom ProcessGroupFlagos implementation is needed

The fix requires domain knowledge about:

  • MUSA SDK's distributed training support
  • PyTorch's distributed backend registration mechanism
  • Whether torch_fl should provide its own ProcessGroup implementation

Verification Plan

  • Identify the correct approach (Gloo registration vs NCCL vs custom ProcessGroup)
  • Implement the chosen solution
  • Unit test: verify init_process_group() succeeds with flagos tensors
  • Integration test: re-run test_fsdp2_plan_vs_ddp_0_untied and confirm it passes
  • Cross-check with other distributed tests in the transformers suite

Context & Investigation

Investigation completed:

  1. Isolated this test from the full qwen3 suite (297 tests) and verified it fails deterministically in a fresh subprocess.
  2. Confirmed the error is specific to ProcessGroupGloo not recognizing flagos device type.
  3. Searched for existing issues about distributed training / Gloo / flagos — no open duplicate found.
  4. This is not a device-context poisoning issue; it's a missing feature in torch_fl's distributed training support.

Related Code Locations

  • PyTorch: torch/distributed/distributed_c10d.py — ProcessGroup initialization
  • PyTorch: torch/csrc/distributed/c10d/ProcessGroupGloo.cpp — Gloo backend implementation
  • torch_fl: needs to register flagos device with distributed backends

Checklist - AI Agents MUST Complete All

  • I have provided complete environment information
  • I have included a minimal, self-contained reproducer
  • I have included full error output with traceback
  • I have analyzed the root cause (not just symptoms)
  • I have proposed a specific solution with implementation approach
  • I have identified affected code locations with line numbers
  • I have described how to verify the fix
  • I have checked for duplicate issues
  • All text is in English (required per CLAUDE.md)
  • Code follows project conventions (checked existing code style)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions