Skip to content

Merge samithuang/slime rebase branch into vime#8

Closed
SamitHuang wants to merge 1 commit into
mainfrom
merge/samithuang-rebase
Closed

Merge samithuang/slime rebase branch into vime#8
SamitHuang wants to merge 1 commit into
mainfrom
merge/samithuang-rebase

Conversation

@SamitHuang

@SamitHuang SamitHuang commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Merges samithuang/slime PR #12 (rebase branch, commit 9146f9f) into vime. Both branches forked from upstream slime 8ef1fb4 and independently added vLLM support; this PR reconciles them so vime retains its vLLM design (kaiyuan) while picking up samithuang's broader infrastructure (Jason & Long): non-colocate Megatron+vLLM weight sync, slime router, Megatron grad-coalesce patch, retool fix, e2e scripts

Per-file precedence

Kept verbatim from vime (kaiyuan vLLM core)

  • slime/backends/vllm_utils/vllm_engine.py (707-line monolithic engine)
  • slime/backends/vllm_utils/__init__.py (empty)
  • slime/rollout/vllm_rollout.py (992-line standalone rollout)
  • slime/backends/sglang_utils/sglang_engine.py
  • slime/rollout/sglang_rollout.py (kept upstream; samithuang's backend-abstraction refactor dropped)

Dropped from samithuang (incompatible with vime's design)

  • slime/backends/vllm_utils/vllm_translation_sidecar.py
  • slime/rollout/backends/{__init__,base_client,sglang_client,vllm_client}.py

Taken from samithuang (Jason & Long infrastructure)

  • slime/backends/megatron_utils/update_weight/update_weight_from_distributed.py (colocate + non-colocate weight sync)
  • slime/backends/megatron_utils/update_weight/update_weight_from_tensor_vllm.py
  • slime/backends/megatron_utils/weight_sync_utils.py
  • slime/backends/megatron_utils/megatron_patch/* (chunked grad coalesce)
  • slime/backends/megatron_utils/{__init__,actor,arguments,sglang}.py, update_weight/common.py
  • slime/ray/actor_group.py, slime/rollout/base_types.py, slime/backends/sglang_utils/arguments.py
  • slime/router/router.py (SlimeRouter, gated by --use-slime-router)
  • e2e scripts: run-qwen2.5-0.5B-vllm.sh, run-qwen2.5-0.5B-reproducibility-noncolocate.sh, convert_qwen2.5_ckpt.sh, setup_for_vllm.md
  • RFC/docs and examples/retool + tests/plugin_contracts updates

Manual splices

  • slime/ray/rollout.py: based on samithuang. Vime's _sanitize_vllm_router_args, _vllm_router_args_from_cli, the model_path kwarg passed to engine actors, and the engine-shutdown loop in RolloutManager.dispose() are preserved. _start_router was rewritten to support three modes: --use-slime-router (SlimeRouter), --rollout-backend vllm (vllm-router via http_utils), and sglang-router fallback. Samithuang's _start_vllm_rollout_servers helper and its early-exit in start_rollout_servers were removed because they target a different VLLMEngine signature; vime's ServerGroup.start_engines already dispatches to VLLMEngine when rollout_backend == "vllm".
  • slime/utils/arguments.py: union of both arg sets with duplicates removed (--rollout-backend, --vllm-gpu-memory-utilization, --vllm-weight-sync-packed). Kept samithuang's --rollout-backend default of sglang for backwards compat and vime's mutually-exclusive --vllm-weight-sync-packed / --no-vllm-weight-sync-packed group. Vime's auto-switch of rollout_function_path to vllm_rollout when --rollout-backend vllm is preserved.
  • slime/utils/http_utils.py: vime's run_router((impl, router_args)) payload contract kept; samithuang's sglang_server_concurrency -> rollout_server_concurrency rename applied.
  • slime/backends/megatron_utils/update_weight/update_weight_from_tensor.py: vime's 3-line addition (import _is_vllm_backend, pass use_vllm=... and packed=False) kept; it correctly wires the existing tensor-update path through samithuang's new vllm-aware signature.

Test plan

  • python -m py_compile over all touched .py files (already green locally).
  • Smoke run of run-qwen2.5-0.5B-vllm.sh (--rollout-backend vllm --use-slime-router, dense Qwen2.5-0.5B on GSM8K).
  • Smoke run of run-qwen2.5-0.5B-reproducibility-noncolocate.sh (non-colocate Megatron+vLLM weight sync).
  • Smoke run of an existing sglang e2e script (e.g. scripts/run-deepseek-r1.sh) to confirm no regression on the default backend.
  • Compare reward curve between sglang and vllm backends on the same config.

Known follow-ups (deferred)

  • docs/en/vllm/ROUTER_DESIGN.md and rfc-rollout-backend-separation-plan.md still mention the dropped vllm_translation_sidecar.py; update once the design has settled.
  • vime's inline vllm-router path and samithuang's standalone slime/router/router.py coexist (selected by --rollout-backend vllm vs --use-slime-router); a future cleanup could unify them.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds vLLM as a rollout backend in Slime, providing backend-agnostic adapters and supporting weight synchronization via CUDA IPC and NCCL. It also introduces a new SlimeRouter and a Megatron patch for chunked gradient coalescing. Review feedback highlights a potential AttributeError in weight updates, a hardcoded override of the rollout offload flag, and the removal of important configuration validation checks. Furthermore, the feedback suggests improving the router's robustness against invalid JSON and division-by-zero errors, and fixing an ineffective variable reassignment in the weight distribution logic.

ray.get(self.rollout_engine_lock.release.remote())
if pbar is not None:
pbar.update(1)
pbar.update(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The explicit check if pbar is not None: was removed in this change. Since pbar defaults to None in the function signature and is not initialized in some calling paths (e.g., the use_vllm_packed branch in update_weights), this will cause an AttributeError when attempting to call .update(1).

Suggested change
pbar.update(1)
if pbar is not None:
pbar.update(1)

Comment thread slime/utils/arguments.py Outdated
args.offload_train = False
if args.offload_rollout is None:
args.offload_rollout = False
args.offload_rollout = False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This hardcoded assignment to False silently overrides the user-provided configuration for --offload-rollout. If the intention was to disable this feature temporarily, it should be handled by setting a default value or providing a warning to the user, rather than a silent override in the validation logic.

Comment on lines +135 to +140
# if hasattr(hf_config, hf_config_name) and hasattr(args, megatron_config_name):
# if not compare_fn(getattr(hf_config, hf_config_name), getattr(args, megatron_config_name)):
# errors.append(
# f"{hf_config_name} in hf config {getattr(hf_config, hf_config_name)} is not equal to "
# f"{megatron_config_name} {getattr(args, megatron_config_name)}, please check the config."
# )

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The validation logic for ensuring consistency between HuggingFace configuration and Megatron arguments has been commented out. This disables important safety checks that prevent model initialization with mismatched parameters (e.g., layer norm epsilon). These checks should be restored or properly integrated with the new vLLM backend logic.

Comment thread slime/router/router.py Outdated
max_connections = getattr(args, "slime_router_max_connections", None)
if max_connections is None:
max_connections = (
args.rollout_server_concurrency * args.rollout_num_gpus // args.rollout_num_gpus_per_engine

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a potential division by zero risk if args.rollout_num_gpus_per_engine is set to 0. While this might be an invalid configuration, adding a guard or a minimum value check during argument validation would improve robustness.

Comment thread slime/router/router.py Outdated
# 2) Fallback to JSON body
if not worker_url:
body = await request.body()
payload = json.loads(body) if body else {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling json.loads(body) without a try-except block will cause the router to crash (returning a 500 error) if the request body is not valid JSON. It is recommended to handle json.JSONDecodeError and return a 400 Bad Request response instead.

if isinstance(model_update_groups, _NcclBridge):
model_update_groups.shutdown()
elif model_update_groups is not None:
model_update_groups = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Reassigning the local variable model_update_groups to None has no effect on the caller's state. If the intention is to clear the reference in the calling object, this must be done explicitly by the caller or by returning None.

@CalvinXKY CalvinXKY self-requested a review May 18, 2026 08:28
@CalvinXKY

Copy link
Copy Markdown
Collaborator

I recommend splitting it and landing Megatron ↔ vLLM weight sync first, then glue/args, then docs/scripts.

Suggested PR split

Priority Scope Rationale
P0 Megatron ↔ vLLM weight sync: update_weight_from_distributed.py (incl. NcclBridge), update_weight_from_tensor_vllm.py, weight_sync_utils.py, update_weight/common.py, tensor wiring, actor.py updater selection, actor_group.py trainer CUDA_VISIBLE_DEVICES Core functionality; highest risk; should be reviewable and testable in isolation
P1 Args + rollout glue without SlimeRouter: arguments.py, rollout.py (vllm-router + sglang fallback only), http_utils.py, base_types.py if needed Depends on P0 but avoids router debate
Defer / discuss slime/router/router.py + --use-slime-router Conflicts with upstream slime direction
Separate megatron_patch/megatron_chunked_grad_coalesce_patch.py Orthogonal to vLLM rollout
Later w/ best practices setup_for_vllm.md, run-qwen2.5-0.5B-*.sh, convert_qwen2.5_ckpt.sh, script concurrency renames Avoid churn while APIs still moving
Cherry-pick retool fix, plugin-contract tests, misc example/doc tweaks Unrelated to vLLM; hard to bisect if bundled

Acceptance for P0: smoke run-qwen2.5-0.5B-reproducibility-noncolocate.sh (non-colocate NCCL) + colocate IPC path.

SlimeRouter — recommend deferring (or dropping from this PR)

Upstream slime has already deprecated --use-slime-router in favor of sgl-router. Maintaining SlimeRouter + vllm-router long-term is costly, especially given upstream’s deprecation.

The weight-sync work (especially non-colocate NcclBridge + colocate IPC) is valuable and should land first in a focused PR. Please defer SlimeRouter, defer docs/scripts until paths stabilize, and keep SGLang changes to the minimal API shim.


# Resolve vLLM base URLs for colocated engines (blocking Ray call)
if dist.get_rank() == 0 and self._colocated_engines:
url_refs = [engine.get_vllm_url.remote() for engine in self._colocated_engines]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VLLMEngine exposes get_url(), not get_vllm_url(). Colocated IPC connect will raise AttributeError. Please use get_url.remote() or add an alias on VLLMEngine.

logger = logging.getLogger(__name__)


class UpdateVLLMWeightFromTensor:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MegatronTrainRayActor.sleep() calls disconnect_rollout_engines() when present. UpdateVLLMWeightFromTensor never implements it, so _NcclBridge / NCCL groups for overflow engines may leak across sleep/wake.

# Bump weight version on sidecar for colocated engines
for engine in self._colocated_engines:
try:
ray.get(engine.set_weight_version.remote(self.weight_version))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VLLMEngine has no set_weight_version (comment still says "sidecar"). This call always fails silently. Implement on VLLMEngine or remove.

@SamitHuang

Copy link
Copy Markdown
Collaborator Author

Will break into smaller PRs starting from #22

@aoshen02 aoshen02 force-pushed the merge/samithuang-rebase branch from a38186e to ebcc57c Compare June 1, 2026 01:36
@knlnguyen1802

Copy link
Copy Markdown
Collaborator

Close this and will continuous update it with main branch

@SamitHuang SamitHuang deleted the merge/samithuang-rebase branch June 9, 2026 07:42
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.

4 participants