Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
name: PR Test

on:
# Do not run CI on push to reduce CI time
# push:
# branches: [main]
# Push to main triggers ONLY the cpu jobs (cheap GitHub-hosted runner) — see
# the per-job `if:` below, which adds `push` only for cpu configs. GPU jobs
# stay PR/label-gated so push events never burn the self-hosted fleet. This
# catches PR-pair regressions where two PRs pass individually but main breaks
# after both land.
push:
branches: [main]
pull_request:
branches: [main]
types: [synchronize, labeled]
Expand Down Expand Up @@ -468,15 +472,17 @@ jobs:
e2e-test-plugin-contracts:
needs: pre-commit

if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'

if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || github.event_name == 'push'



runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
info: [{"num_gpus": 0, "test_file": "test_megatron_argument_validation.py"}, {"num_gpus": 0, "test_file": "plugin_contracts/test_plugin_rollout_contracts.py"}, {"num_gpus": 0, "test_file": "plugin_contracts/test_plugin_runtime_hook_contracts.py"}, {"num_gpus": 0, "test_file": "plugin_contracts/test_plugin_path_loading_contracts.py"}, {"num_gpus": 0, "test_file": "plugin_contracts/test_plugin_generate_contracts.py"}]
info: [{"num_gpus": 0, "test_file": "test_megatron_argument_validation.py"}, {"num_gpus": 0, "test_file": "plugin_contracts/test_plugin_rollout_contracts.py"}, {"num_gpus": 0, "test_file": "plugin_contracts/test_plugin_runtime_hook_contracts.py"}, {"num_gpus": 0, "test_file": "plugin_contracts/test_plugin_path_loading_contracts.py"}, {"num_gpus": 0, "test_file": "plugin_contracts/test_plugin_generate_contracts.py"}, {"num_gpus": 0, "test_file": "test_rm_deepscaler.py"}, {"num_gpus": 0, "test_file": "test_rm_f1.py"}, {"num_gpus": 0, "test_file": "test_rm_gpqa.py"}, {"num_gpus": 0, "test_file": "test_rm_math.py"}, {"num_gpus": 0, "test_file": "test_rm_math_dapo.py"}]
defaults:
run:
working-directory: ${{ github.workspace }}
Expand Down Expand Up @@ -767,4 +773,4 @@ jobs:
else
python tests/ci/gpu_lock_exec.py --count "$NUM_GPUS" -- python "$TEST_PATH" "${TEST_ARGS_ARRAY[@]}"
fi
'
'
19 changes: 16 additions & 3 deletions .github/workflows/pr-test.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
{'test_file': 'plugin_contracts/test_plugin_runtime_hook_contracts.py', 'num_gpus': 0},
{'test_file': 'plugin_contracts/test_plugin_path_loading_contracts.py', 'num_gpus': 0},
{'test_file': 'plugin_contracts/test_plugin_generate_contracts.py', 'num_gpus': 0},
{'test_file': 'test_rm_deepscaler.py', 'num_gpus': 0},
{'test_file': 'test_rm_f1.py', 'num_gpus': 0},
{'test_file': 'test_rm_gpqa.py', 'num_gpus': 0},
{'test_file': 'test_rm_math.py', 'num_gpus': 0},
{'test_file': 'test_rm_math_dapo.py', 'num_gpus': 0},
],
},

Expand All @@ -85,9 +90,13 @@
name: PR Test

on:
# Do not run CI on push to reduce CI time
# push:
# branches: [main]
# Push to main triggers ONLY the cpu jobs (cheap GitHub-hosted runner) — see
# the per-job `if:` below, which adds `push` only for cpu configs. GPU jobs
# stay PR/label-gated so push events never burn the self-hosted fleet. This
# catches PR-pair regressions where two PRs pass individually but main breaks
# after both land.
push:
branches: [main]
pull_request:
branches: [main]
types: [synchronize, labeled]
Expand Down Expand Up @@ -128,7 +137,11 @@ jobs:
<< job_name >>:
needs: pre-commit
<% if config.get('always') %>
<% if config.get('cpu') %>
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || github.event_name == 'push'
<% else %>
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
<% endif %>
<% else %>
if: (github.event_name == 'workflow_dispatch') || (github.event.pull_request && contains(github.event.pull_request.labels.*.name, '<< config.label >>'))
<% endif %>
Expand Down
77 changes: 70 additions & 7 deletions docs/en/advanced/fault-tolerance.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,76 @@
# Fault Tolerance

To ensure long-term, stable RL training, vime enables a certain level of fault tolerance by default. This section introduces the design philosophy behind fault tolerance in vime.
Long-running RL jobs fail in different ways from short supervised runs. Rollout engines can hang, long-tail samples can keep a round open, and serving state must be refreshed after weight updates. vime's fault-tolerance support focuses on making the rollout side observable, restartable, and debuggable without changing the training / rollout / Data Buffer loop.

To enable the fault tolerance function in vime, please set `--use-fault-tolerance`.
Enable fault tolerance with:

## Rollout Fault Tolerance
```bash
--use-fault-tolerance
```

During the rollout process, vime periodically sends heartbeat requests (`/health`) to all vLLM engines. If a heartbeat times out, that vLLM engine will be stopped. After the current rollout round is complete, the engine will be restarted and its parameters will be correctly updated.
## Current Scope

- `--rollout-health-check-first-wait`: Since some large MoE models require compilation on their first run, vime will wait for `rollout_health_check_first_wait` seconds before the first rollout to start sending heartbeats. Defaults to 300s.
- `--rollout-health-check-interval`: The interval between heartbeat checks. Defaults to 10s.
- `--rollout-health-check-timeout`: The timeout limit for a heartbeat request. Defaults to 5s.
vime currently provides rollout-engine fault tolerance:

- health checks for vLLM rollout engines;
- timeout-based rollout engine restart;
- correct parameter update after restart;
- debug rollout dumps for replaying training-side issues without rerunning rollout;
- trace/profiling hooks for inspecting long-tail rollout behavior.

Cluster-level preemption, trainer-rank failure, and full-job resume should still be handled through your cluster scheduler, Ray restart policy, and vime checkpointing. In practice, production jobs combine rollout fault tolerance with frequent checkpoints and debug dumps.

## Rollout Health Checks

During rollout, vime periodically sends heartbeat requests (`/health`) to all vLLM engines. If a heartbeat times out, the unhealthy vLLM engine is stopped. After the current rollout round completes, vime restarts the engine and updates it with the correct parameters before it serves future rollout requests.

The main arguments are:

- `--rollout-health-check-first-wait`: wait before starting heartbeat checks for the first rollout. Large MoE models may compile kernels on first run. Default: `300` seconds.
- `--rollout-health-check-interval`: interval between heartbeat checks. Default: `10` seconds.
- `--rollout-health-check-timeout`: timeout for one heartbeat request. Default: `5` seconds.

Example:

```bash
--use-fault-tolerance \
--rollout-health-check-first-wait 600 \
--rollout-health-check-interval 10 \
--rollout-health-check-timeout 5
```

## Debug and Replay Path

Fault tolerance is more useful when failures are reproducible. vime provides separate rollout-only and train-only debugging paths:

- `--debug-rollout-only`: run rollout and save generated data without training;
- `--save-debug-rollout-data /path/to/rollout_{rollout_id}.pt`: save rollout samples for later inspection or replay;
- `--load-debug-rollout-data /path/to/rollout_{rollout_id}.pt`: replay saved rollout data and skip vLLM initialization;
- `--debug-train-only`: run training-side logic without rollout.

This lets you isolate whether a failure belongs to serving/rollout, data conversion, reward/verifier logic, or Megatron training.

## Recommended Production Pattern

For long-running jobs:

1. Enable `--use-fault-tolerance`.
2. Save checkpoints regularly with `--save-interval`.
3. Save rollout debug dumps for new agentic or verifier-heavy workloads.
4. Use [Trace Viewer](../developer_guide/trace.md) to inspect long-tail samples and reward/model-call spans.
5. Use [Profiling](../developer_guide/profiling.md) to separate rollout bottlenecks from training bottlenecks.
6. Keep vLLM deployment explicit with [vLLM Config](vllm-config.md) for complex multi-model or PD topologies.

## What to Watch

- If startup health checks fail on large MoE models, increase `--rollout-health-check-first-wait`.
- If transient load spikes cause false positives, increase `--rollout-health-check-timeout`.
- If an engine repeatedly restarts after weight sync, inspect the vLLM logs and the latest rollout debug dump.
- If the trainer fails rather than rollout, resume from checkpoint and use debug replay to isolate whether the saved rollout batch is valid.

## Related Docs

- [Debugging](../developer_guide/debug.md)
- [Trace Viewer](../developer_guide/trace.md)
- [Profiling](../developer_guide/profiling.md)
- [CI](../developer_guide/ci.md)
86 changes: 83 additions & 3 deletions docs/en/advanced/pd-disaggregation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,87 @@
# PD Disaggregation

vime supports Prefill and Decode disaggregation (PD Disaggregation).
PD Disaggregation separates Prefill and Decode workers in vLLM rollout. This is especially useful for multi-turn, long-context, and agentic RL workloads where prompt processing and token generation have very different compute and memory profiles.

You can set the number of servers used for Prefill by setting the `--prefill-num-servers` argument.
## When to Use

We recommand using PD Disaggregation for multi-turn/agentic RL training.
Use PD Disaggregation when:

- rollout contexts are long or grow across turns;
- decode dominates rollout time;
- prefix-cache locality matters for multi-turn sessions;
- prefill and decode need different TP, memory, or runtime settings;
- you want an vLLM serving topology that is closer to production serving rather than a single uniform inference group.

For short single-turn tasks, the default regular vLLM engine layout is usually simpler.

## Configuration Paths

vime supports two ways to configure PD.

### Simple Path: `--prefill-num-servers`

For a single actor model with a simple PD layout, set:

```bash
--prefill-num-servers 1
```

This is the lightweight path used by simple scripts. It is convenient when you only need to split prefill/decode without tuning each group separately.

### Advanced Path: `--vllm-config`

For production rollout topologies, use [vLLM Config](vllm-config.md). It lets you configure prefill and decode groups independently, and can also express EPD-style layouts, heterogeneous engine groups, multi-model serving, and per-group vLLM overrides.

Example:

```yaml
vllm:
- name: actor
update_weights: true
server_groups:
- worker_type: prefill
num_gpus: 4
num_gpus_per_engine: 2
overrides:
chunked_prefill_size: 8192
- worker_type: decode
num_gpus: 12
num_gpus_per_engine: 4
overrides:
mem_fraction_static: 0.88
```

Launch with:

```bash
python train.py \
--vllm-config vllm_pd.yaml \
--rollout-num-gpus 16 \
...
```

## Why This Matters for RL

RL rollout is often not a uniform batch of short completions. Agentic and verifier-based workloads commonly have:

- long prompts from tool/environment history;
- multiple turns per sample;
- long-tail decode latency;
- session-local prefix cache opportunities;
- different resource needs for actor, reference, reward, or judge models.

PD lets vime keep the training loop unchanged while using a rollout topology that matches the actual serving workload.

## Operational Notes

- For new complex deployments, prefer `--vllm-config` over `--prefill-num-servers`.
- Use router session affinity for multi-turn agents so turns from the same sample can reuse prefix cache. See [Session-Affinity Routing](vllm-config.md#session-affinity-routing-for-multi-turn-agents).
- Keep `--rollout-num-gpus` equal to the total GPUs described by the vLLM config.
- Do not mix `regular` workers with `prefill`/`decode` workers inside the same model entry.
- Tune prefill and decode TP separately when prompt processing and token generation have different bottlenecks.

## Related Docs

- [vLLM Config](vllm-config.md)
- [Agentic RL Training Roadmap](../get_started/agent.md)
- [Trace Viewer](../developer_guide/trace.md)
45 changes: 45 additions & 0 deletions docs/en/developer_guide/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,48 @@ When running large scale RL, we will occationally meet the IMA in vLLM, there ar
4. Try CUDA Core Dump to find the error kernel

We recommend reading the blog from the vLLM team: [CUDA Core Dump: An Effective Tool to Debug Memory Access Issues and Beyond](https://blog.vllm.ai/2025/08/11/cuda-debugging.html)

## Step-by-Step Debugging with Ray Distributed Debugger

Ray provides a [distributed debugger](https://docs.ray.io/en/latest/ray-observability/ray-distributed-debugger.html) based on debugpy that lets you set breakpoints in the driver process and step through code interactively.

1. Install debugpy:

```bash
pip install debugpy==1.8.0
```

2. Enable `RAY_DEBUG_POSTMORTEM` in your launch script:

```bash
export RAY_DEBUG_POSTMORTEM=1

RUNTIME_ENV_JSON="{
\"env_vars\": {
...
\"RAY_DEBUG_POSTMORTEM\": \"${RAY_DEBUG_POSTMORTEM:-0}\"
}
}"

ray job submit --address="http://127.0.0.1:8265" \
--runtime-env-json="${RUNTIME_ENV_JSON}" \
-- python3 train.py [args...]
```

3. Add `ray.init()` before `breakpoint()` in `train.py`:

```python
if __name__ == "__main__":
ray.init()
breakpoint()
args = parse_args()
train(args)
```

`ray.init()` is required because the distributed debugger depends on `core_worker`, which is only available after Ray initialization. Without it, `breakpoint()` raises `AttributeError: 'Worker' object has no attribute 'core_worker'`.

4. Connect via VS Code:

Install the [Ray Distributed Debugger](https://marketplace.visualstudio.com/items?itemName=ray-project.ray-distributed-debugger) extension in VS Code. Run your launch script to submit the job. Once the job hits `breakpoint()`, open the Ray Dashboard panel in VS Code and click the active breakpoint to attach the debugger. You can then step through code, inspect variables, and set additional breakpoints directly in the editor.

> **Note**: Remove `ray.init()` and `breakpoint()` after debugging. An explicit `ray.init()` without arguments may cause issues in multi-node training where Ray injects specific namespace and runtime environment configurations via `ray job submit`.
9 changes: 5 additions & 4 deletions docs/en/developer_guide/trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ By default it also starts a local static server so you can open the generated HT

## Instrument custom code

For custom rollout or reward code, reuse helpers from `vime.utils.trace_utils`:
For custom rollout or reward code — including custom agent steps, tool calls, sandbox execution, and verifier calls in agentic workflows — reuse helpers from `vime.utils.trace_utils`:

- `trace_span(target, name, attrs=...)`: record a duration span.
- `trace_event(target, name, attrs=...)`: record an instant event.
Expand Down Expand Up @@ -101,13 +101,14 @@ If you need to add attrs after part of the function has executed, use an inner `
- `trace_function(...)` for the outer function-level lifecycle span
- nested `trace_span(...)` for important sub-steps such as generation, RM, filtering, or post-processing

For per-turn attrs around an HTTP call, wrap it in `trace_span` directly:
If you want to record vLLM generation metadata in a consistent way, reuse `build_vllm_meta_trace_attrs`:

```python
from vime.utils.trace_utils import trace_span
from vime.utils.trace_utils import build_vllm_meta_trace_attrs, trace_span

with trace_span(sample, "vllm_generate", attrs={"max_tokens": params["max_new_tokens"]}):
with trace_span(sample, "vllm_generate") as span:
output = await post(url, payload)
span.update(build_vllm_meta_trace_attrs(output))
```

## Tips
Expand Down
20 changes: 18 additions & 2 deletions docs/en/get_started/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ Below is a summary of all available customization interfaces and their purposes.
| [`--custom-megatron-before-log-prob-hook-path`](#17-megatron-hooks) | Custom logic before log probability computation. |
| [`--custom-megatron-before-train-step-hook-path`](#17-megatron-hooks) | Custom logic before each training step. |

## Agentic workflows through customization interfaces

Agentic workflows — multi-turn tool use, sandbox interaction, environment feedback, verifier/test-based rewards — are an important class of data generation workflows. They plug into vime through the existing customization interfaces; vime does not require a separate agent framework.

For most agentic use cases, **start with `--custom-generate-function-path` plus `--custom-rm-path`**, and only override the full rollout function when the default rollout loop is insufficient.

| If you need to … | Use |
| :--- | :--- |
| Run a custom agent loop, tool calls, RAG, sandbox execution, browser/terminal interaction, or multi-turn generation for each sample, while reusing vime's default rollout loop | [`--custom-generate-function-path`](#2-custom-generate-function---custom-generate-function-path) |
| Compute verifier rewards, test-based rewards, environment success checks, rule-based rewards, or call an external reward service | [`--custom-rm-path`](#3-reward-model---custom-rm-path) |
| Replace the entire rollout orchestration (only when per-sample customization is not enough) | [`--rollout-function-path`](#1-rollout-function---rollout-function-path) |
| Control task sampling, buffering, requeueing, or custom prompt/task sources | [`--data-source-path`](#15-data-source---data-source-path) |
| Attach custom loss masks, metadata, or convert agentic outputs into training data | [`--rollout-data-postprocess-path`](#8-rollout-data-postprocess---rollout-data-postprocess-path), [`--custom-convert-samples-to-train-data-path`](#13-samples-to-train-data-conversion---custom-convert-samples-to-train-data-path) |
| Debug long-running custom generation, verifier calls, tool calls, or sandbox steps | trace utilities in [`vime.utils.trace_utils`](../developer_guide/trace.md) |

Native examples of this pattern: [`examples/multi_agent`](../../../examples/multi_agent/README.md) (a `--rollout-function-path`-based multi-agent pattern) and [`examples/fully_async`](../../../examples/fully_async/README.md) (long-tail agentic generation), both keeping vime's default `vllm_rollout` outer loop.

## Detailed Interface Reference

### 1. Rollout Function (`--rollout-function-path`)
Expand Down Expand Up @@ -67,8 +84,6 @@ async def custom_generate(args, sample: Sample, sampling_params: dict) -> Sample
- Adding retrieval-augmented generation (RAG)
- Multi-turn conversation handling

**Example**: See [examples/search-r1/generate_with_search.py](../../../examples/search-r1/generate_with_search.py)

---

### 3. Reward Model (`--custom-rm-path`)
Expand Down Expand Up @@ -295,6 +310,7 @@ dict: {
"rollout_routed_experts": list, # Routed experts (for MoE)
"metadata": list, # Train metadata
"multimodal_train_inputs": list, # Multimodal tensors (for VLM)
"teacher_log_probs": list, # Teacher log probs (for distillation)
}
```

Expand Down
2 changes: 0 additions & 2 deletions docs/en/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ vime is the RL-framework behind GLM-4.7, GLM-4.6 and GLM-4.5. Apart from models
:maxdepth: 1
:caption: Other Usage

_examples_synced/search-r1/README.md
_examples_synced/fully_async/README.md
_examples_synced/retool/README.md
_examples_synced/multi_agent/README.md

.. toctree::
Expand Down
Loading
Loading