Skip to content

feat(xpu): enable Ulysses context parallel on XPU - #530

Open
Madhustat wants to merge 2 commits into
alibaba:mainfrom
Madhustat:xpu/pr2-ulysses-context-parallel
Open

Madhustat wants to merge 2 commits into
alibaba:mainfrom
Madhustat:xpu/pr2-ulysses-context-parallel

Conversation

@Madhustat

Copy link
Copy Markdown

Relates to #525

Depends on #526 (feat(xpu): add Intel XPU platform support). This PR is stacked on #526; until #526 is merged, the GitHub diff also includes its base platform commit, and the context-parallel change is the final commit in this PR.

Summary

Enable ROLL's existing Ulysses context parallel on XPU:

  • Apply the shared Ulysses attention patch in the XPU platform, as the CUDA and ROCm platforms do
  • Make the standalone flash_attn imports optional for the Transformers-based Ulysses path

When flash_attn is installed, the existing flash_attn functions remain in use. When it is not installed, the module still imports, and only the code path that needs flash_attn raises a clear ImportError.

Motivation

XpuPlatform.apply_ulysses_patch() currently returns without applying the Ulysses patch, so ROLL falls back to context parallel size 1 even when the configuration sets ulysses_size: 2, and logs: ulysses_size in config (2) is not equal to cp_size (1), using cp_size instead

Applying the patch alone is not sufficient because ulysses_attention.py imports the standalone flash_attn package at module load time, while that package is not installed in the validated XPU environment.

Changes

  • roll/platforms/xpu.py (added by feat(xpu): add Intel XPU platform support #526): apply_ulysses_patch() calls the shared roll.utils.context_parallel.apply_ulysses_patch(), as cuda.py and rocm.py do.
  • roll/utils/context_parallel/ulysses_attention.py:
    • Wrap the flash_attn imports in try / except ImportError.
    • _flash_attention_forward, used only by the Transformers < 4.53 patch path, raises an ImportError at entry if
      flash_attn is not installed.

Validation

XPU: 2 × Intel Arc Pro B70, PyTorch 2.14.0+xpu, vLLM 0.31.0+xpu, Transformers 5.17.0, oneCCL 2022.0.0. With
attn_implementation: fa2, Transformers resolves to the XPU build of kernels-community/flash-attn2. XPU workflow runs also included #527 and #524; this change does not depend on either.

Configurations derived from ROLL examples, reduced to two XPUs and small models, each with a context parallel 1 control:

Workflow / test Model Result
GRPO, colocated Qwen2.5-0.5B Pass
GRPO, colocated Qwen3-0.6B Pass
DPO, FSDP2 reference Qwen2.5-0.5B Pass
SFT Qwen2.5-0.5B Pass
FSDP2 log-probability test, cp_rmpad (tests/distributed/strategy/log_probs/) Qwen3-0.6B Pass

In every context parallel 2 run, the Ulysses patch was applied and no not equal to cp_size warning was logged. A two-rank check confirmed that each rank processes half of the sequence and that the all-to-all runs in every attention layer; context parallel 1 and 2 log-probabilities and gradients are equally close to an fp32 reference.

NVIDIA: main and e9f3618f give matching results on the context-parallel unit tests, cp_rmpad, one context-parallel workflow, and one workflow without context parallel, with the installed flash_attn functions in use.

Scope

  • Single node, attn_implementation: fa2, Transformers >= 4.53.0 on XPU; lower versions need the standalone
    flash_attn package.
  • The Transformers FlashAttention-2 kernel backend must be available in the environment.
  • Multi-node context parallel is tracked separately.

Register Intel XPU in ROLL's platform abstraction: device detection,
the XCCL communication backend, XPU device visibility for Ray workers,
and the XPU vLLM worker.

Add a supports_tensor_ipc platform flag (default True) so colocated
weight updates use the existing broadcast path when tensor IPC is
unavailable, and call the CUDA allocator and host-cache APIs only when
the PyTorch build provides them.

Document the supports_tensor_ipc flag and the Ray visible-device fallback
with one-line comments.
Apply the shared Ulysses attention patch in XpuPlatform.apply_ulysses_patch, as the CUDA and ROCm platforms do.
Make the flash_attn import in ulysses_attention.py optional: the transformers>=4.53 patch path only needs expandKV
from this module, and XPU has no flash_attn package. The transformers<4.53 path raises a clear ImportError when
flash_attn is missing.
@Madhustat
Madhustat force-pushed the xpu/pr2-ulysses-context-parallel branch from e9f3618 to f912d52 Compare November 27, 2026 06:03

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant