Skip to content

Conversation

@mianmianboom
Copy link

What does this PR do?

This PR adds support for selecting between Ray and openYuanrong (ray_adapter) as the distributed backend via the DISTRIBUTED_BACKEND environment variable.

Checklist Before Starting

  • Search for similar PRs. Query: distributed backend selection ray adapter
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

Test commands:

# Test with default Ray backend
pytest tests/single_controller/test_ray_utils_on_cpu.py -v

# Test with openYuanrong backend
DISTRIBUTED_BACKEND=yr pytest tests/single_controller/test_ray_utils_on_cpu.py -v

API and Usage Example

Set the DISTRIBUTED_BACKEND environment variable to choose the backend:

  • DISTRIBUTED_BACKEND=ray or unset: Use default Ray backend (default)
  • DISTRIBUTED_BACKEND=yr or DISTRIBUTED_BACKEND=yuanrong: Use openYuanrong backend
# Use default Ray backend
bash examples/grpo_trainer/run_qwen2_5_7b_grpo_npu.sh

# Use openYuanrong backend (both 'yr' and 'yuanrong' are supported)
DISTRIBUTED_BACKEND=yr bash examples/grpo_trainer/run_qwen2_5_7b_grpo_npu.sh
# or
DISTRIBUTED_BACKEND=yuanrong bash examples/grpo_trainer/run_qwen2_5_7b_grpo_npu.sh

Design & Code Changes

Design Overview: To support the YuanRong distributed computing platform alongside Ray, we implemented a non-intrusive backend injection mechanism. By utilizing Python's sys.modules interception, we can dynamically redirect import ray to the YuanRong adapter ( ray_adapter ) at runtime based on an environment variable. This approach allows the existing codebase to remain largely unchanged, as it continues to import and use the ray namespace, while the underlying implementation is transparently switched to YuanRong when configured.

Specific Changes:

  1. New file : verl/utils/distributed_backend.py - Core backend selection module. It checks the DISTRIBUTED_BACKEND environment variable and injects either ray_adapter or the standard ray module into sys.modules['ray'] .
  2. Modified files :
    • verl/init.py : Added import verl.utils.distributed_backend to ensure the backend injection logic is executed immediately upon package initialization.
    • Test files : Updated import order in 17 test files to ensure import ray occurs after verl imports. This guarantees that the injection logic in verl/init.py runs before ray is loaded.

Checklist Before Submitting

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Test User seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants