Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4c44c7c
add ci for fault tolerance
yitianlian Dec 26, 2025
8dfecf3
change args
yitianlian Dec 26, 2025
92b5e79
fix format error
yitianlian Dec 26, 2025
0a04df8
add short ci
yitianlian Dec 28, 2025
ae9ef43
rm long ci test for fault tolerance
yitianlian Dec 28, 2025
0eecf74
fix
yitianlian Dec 28, 2025
d0d5316
Merge branch 'main' into ci_fault
yitianlian Dec 28, 2025
fe72c7f
fix
yitianlian Dec 28, 2025
d9bd7eb
fix error
yitianlian Dec 28, 2025
d2901af
more gpu debug
yitianlian Dec 29, 2025
2547c23
more gpu debug
yitianlian Dec 29, 2025
9701fb8
Merge branch 'main' into ci_fault
yitianlian Dec 29, 2025
15ec05e
fix linting
yitianlian Dec 29, 2025
bb0a648
fix
yitianlian Dec 29, 2025
a6da749
fix
yitianlian Dec 29, 2025
e92562b
fix
yitianlian Dec 29, 2025
ef03ff4
fix fault tolerance
yitianlian Dec 29, 2025
8752338
fix linting
yitianlian Dec 30, 2025
b7370c3
revert
yitianlian Dec 30, 2025
507b548
better fault tolerance
yitianlian Dec 31, 2025
e668bd2
Merge branch 'main' into ci_fault
yitianlian Dec 31, 2025
f50f1bf
rm
yitianlian Dec 31, 2025
98ac955
Merge branch 'main' into ci_fault
yitianlian Dec 31, 2025
8c2506f
linting
yitianlian Dec 31, 2025
c5a3246
linting
yitianlian Jan 1, 2026
8d220bc
Merge branch 'main' into ci_fault
yitianlian Jan 3, 2026
b4a8856
del first sume
yitianlian Jan 3, 2026
a29cc32
clean code
yitianlian Jan 4, 2026
d9f544d
fix
yitianlian Jan 4, 2026
054a4aa
minor
yitianlian Jan 4, 2026
8fb1a95
clean code
yitianlian Jan 4, 2026
f5dadcd
Merge branch 'main' into ci_fault
yitianlian Jan 4, 2026
cf83c42
clean code
yitianlian Jan 5, 2026
8b17671
reorg
yitianlian Jan 5, 2026
e521ec2
add sync fault tolerance ci
yitianlian Jan 5, 2026
ed42cbc
lint
yitianlian Jan 5, 2026
a79d07c
Merge branch 'main' into ci_fault
yitianlian Jan 5, 2026
9b21a08
Merge branch 'main' into ci_fault
yitianlian Jan 5, 2026
aed04a3
add ci
yitianlian Jan 5, 2026
f65a5d6
add ci
yitianlian Jan 5, 2026
355e5a3
fix ci
yitianlian Jan 6, 2026
a361350
minor fix
yitianlian Jan 6, 2026
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
46 changes: 45 additions & 1 deletion .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,50 @@ jobs:
shell: bash
run: python tests/ci/gpu_lock_exec.py --count ${{ matrix.info.num_gpus }} -- python tests/${{ matrix.info.test_file }}

e2e-test-fault-tolerance:
if: (github.event_name == 'workflow_dispatch') || (github.event.pull_request && contains(github.event.pull_request.labels.*.name, 'run-ci-fault-tolerance'))
runs-on: self-hosted
container:
image: slimerl/slime:latest
options: >
--gpus all
--ipc=host
--shm-size=16g
--ulimit memlock=-1
--ulimit stack=67108864
--memory=0
--memory-swap=0
-e http_proxy=$http_proxy
-e https_proxy=$https_proxy
-e HTTP_PROXY=$HTTP_PROXY
-e HTTPS_PROXY=$HTTPS_PROXY
-v /mnt/nvme0n1/slime_ci:/data/slime_ci
-v /mnt/nvme0n1/slime_ci/models:/root/models
-v /mnt/nvme0n1/slime_ci/datasets:/root/datasets
strategy:
fail-fast: false
matrix:
info: [{"num_gpus": 4, "test_file": "test_qwen2.5_0.5B_gsm8k_async_short.py"}, {"num_gpus": 4, "test_file": "test_qwen2.5_0.5B_gsm8k_short.py"}]
defaults:
run:
working-directory: ${{ github.workspace }}
env:
GITHUB_COMMIT_NAME: ${{ github.sha }}_${{ github.event.pull_request.number || 'non-pr' }}
WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }}
SLIME_TEST_ENABLE_INFINITE_RUN: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.infinite_run) || 'false' }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install
shell: bash
run: cd $GITHUB_WORKSPACE && pip install -e . --no-deps --break-system-packages

- name: Execute
shell: bash
run: python tests/ci/gpu_lock_exec.py --count ${{ matrix.info.num_gpus }} -- python tests/${{ matrix.info.test_file }}

e2e-test-long:
if: (github.event_name == 'workflow_dispatch') || (github.event.pull_request && contains(github.event.pull_request.labels.*.name, 'run-ci-long'))
runs-on: self-hosted
Expand Down Expand Up @@ -243,4 +287,4 @@ jobs:

- name: Execute
shell: bash
run: python tests/ci/gpu_lock_exec.py --count ${{ matrix.info.num_gpus }} -- python tests/${{ matrix.info.test_file }}
run: python tests/ci/gpu_lock_exec.py --count ${{ matrix.info.num_gpus }} -- python tests/${{ matrix.info.test_file }}
7 changes: 7 additions & 0 deletions .github/workflows/pr-test.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
{'test_file': 'test_qwen3_vl_4B_fsdp.py', 'num_gpus': 8},
],
},
'e2e-test-fault-tolerance': {
'label': 'run-ci-fault-tolerance',
'tests': [
{'test_file': 'test_qwen2.5_0.5B_gsm8k_async_short.py', 'num_gpus': 4},
{'test_file': 'test_qwen2.5_0.5B_gsm8k_short.py', 'num_gpus': 4},
],
},
'e2e-test-long': {
'label': 'run-ci-long',
'tests': [
Expand Down
10 changes: 8 additions & 2 deletions slime/backends/megatron_utils/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,18 @@ def update_weights(self) -> None:
if self.args.debug_train_only or self.args.debug_rollout_only:
return

if self.args.offload_train:
reload_process_groups()
if self.args.use_fault_tolerance:
if dist.get_rank() == 0:
ray.get(self.rollout_manager.recover_rollout_engines.remote())
dist.barrier(group=get_gloo_group())

rollout_engines, rollout_engine_lock, num_new_engines = ray.get(
self.rollout_manager.get_rollout_engines_and_lock.remote()
)

if self.args.offload_train:
reload_process_groups()

if num_new_engines > 0:
self.weight_updater.connect_rollout_engines(rollout_engines, rollout_engine_lock)
dist.barrier(group=get_gloo_group())
Expand Down
11 changes: 11 additions & 0 deletions slime/backends/sglang_utils/sglang_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,17 @@ def stop_profile(self):
response.raise_for_status()
return response

def simulate_crash(self):
if self.args.rollout_external or not getattr(self, "process", None):
logger.info(
"simulate_crash called but no local engine process exists (rollout_external=%s); skip kill",
self.args.rollout_external,
)
return

logger.info(f"Simulating crash on engine {self.server_host}:{self.server_port}...")
self.shutdown()


def _compute_server_args(
args,
Expand Down
91 changes: 75 additions & 16 deletions slime/ray/rollout.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ray
import torch
from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy
from sglang.srt.constants import GPU_MEMORY_TYPE_WEIGHTS

from slime.backends.sglang_utils.sglang_engine import SGLangEngine
from slime.rollout.base_types import call_rollout_fn
Expand Down Expand Up @@ -74,14 +75,41 @@ def __init__(self, args, pg):
self.num_new_engines = init_rollout_engines(args, pg, self.all_rollout_engines)
self.nodes_per_engine = max(1, args.rollout_num_gpus_per_engine // args.num_gpus_per_node)
self.rollout_engine_lock = Lock.options(num_cpus=1, num_gpus=0).remote()
self.rollout_id = -1

self._metric_checker = MetricChecker.maybe_create(args)
self._health_monitor = None
if self.args.use_fault_tolerance:
self._health_monitor = RolloutHealthMonitor(self, args)
self._health_monitor.start() # Start the monitor thread (in paused state)
self._ci_fault_injection_pending = self.args.ci_test # Flag for CI fault injection

def _try_ci_fault_injection(self):
"""Try to inject fault during generate (when health monitor is running)."""
if not self._ci_fault_injection_pending:
return

# Only inject fault once
self._ci_fault_injection_pending = False

if self.all_rollout_engines and self.all_rollout_engines[0]:
logger.info("CI Fault Injection: Simulating crash on engine 0 during generate")
try:
# This will cause the ray actor to exit
self.all_rollout_engines[0].simulate_crash.remote()
# Wait for health monitor to detect the crash and mark engine as None
# health_check_interval + health_check_timeout + buffer
wait_time = self.args.rollout_health_check_interval + self.args.rollout_health_check_timeout + 5
logger.info(f"CI Fault Injection: Waiting {wait_time}s for health monitor to detect crash")
time.sleep(wait_time)
except Exception as e:
logger.warning(f"CI Fault Injection failed: {e}")

def dispose(self):
if self._metric_checker is not None:
self._metric_checker.dispose()
if self._health_monitor is not None:
self._health_monitor.stop()

# TODO maybe rename "rollout_engines" and "all_rollout_engines" later
@property
Expand All @@ -97,25 +125,22 @@ def get_num_rollout_per_epoch(self):
return len(self.data_source.dataset) // self.args.rollout_batch_size

def generate(self, rollout_id):
monitor_started = self.args.use_fault_tolerance and self._health_monitor.start()
start_time = time.time()
try:
data, metrics = self._get_rollout_data(rollout_id=rollout_id)
self._save_debug_rollout_data(data, rollout_id=rollout_id, evaluation=False)
_log_rollout_data(rollout_id, self.args, data, metrics, time.time() - start_time)
data = self._convert_samples_to_train_data(data)
return self._split_train_data_by_dp(data, self.train_parallel_config["dp_size"])
finally:
if monitor_started:
self._health_monitor.stop()
self.num_new_engines = init_rollout_engines(self.args, self.pg, self.all_rollout_engines)
else:
self.num_new_engines = 0
self.rollout_id = rollout_id
self.health_monitoring_resume()
if self.args.ci_test and self.args.use_fault_tolerance and rollout_id >= 2:
self._try_ci_fault_injection()
data, metrics = self._get_rollout_data(rollout_id=rollout_id)
self._save_debug_rollout_data(data, rollout_id=rollout_id, evaluation=False)
_log_rollout_data(rollout_id, self.args, data, metrics, time.time() - start_time)
data = self._convert_samples_to_train_data(data)
return self._split_train_data_by_dp(data, self.train_parallel_config["dp_size"])

def eval(self, rollout_id):
if self.args.debug_train_only:
# if debug train only, we don't generate evaluation data
return
self.health_monitoring_resume()

result = call_rollout_fn(self.eval_generate_rollout, self.args, rollout_id, self.data_source, evaluation=True)
data = result.data
Expand All @@ -131,10 +156,44 @@ def load(self, rollout_id=None):
self.data_source.load(rollout_id)

def offload(self):
return ray.get([engine.release_memory_occupation.remote() for engine in self.rollout_engines])
self.health_monitoring_pause()
return ray.get(
[engine.release_memory_occupation.remote() for engine in self.rollout_engines if engine is not None]
)

def onload(self, tags: list[str] | None = None):
return ray.get(
[
engine.resume_memory_occupation.remote(tags=tags)
for engine in self.rollout_engines
if engine is not None
]
)

def recover_rollout_engines(self):
"""Restart any dead rollout engines and update num_new_engines for update_weights detection."""
self.health_monitoring_pause()
if self.rollout_id == -1:
return self.rollout_engines, self.rollout_engine_lock, self.num_new_engines

dead_indices = [i for i, engine in enumerate(self.all_rollout_engines) if engine is None]
self.num_new_engines = init_rollout_engines(self.args, self.pg, self.all_rollout_engines)
logger.info(f"Recovered {self.num_new_engines} dead rollout engines")
assert self.num_new_engines == len(dead_indices), "num_new_engines does not match dead_indices length"
if self.args.offload_rollout and dead_indices:
new_engines = [self.all_rollout_engines[i] for i in dead_indices]
ray.get([engine.release_memory_occupation.remote() for engine in new_engines])
ray.get([engine.resume_memory_occupation.remote(tags=[GPU_MEMORY_TYPE_WEIGHTS]) for engine in new_engines])

return self.rollout_engines, self.rollout_engine_lock, self.num_new_engines

def health_monitoring_pause(self) -> None:
if self._health_monitor is not None:
self._health_monitor.pause()

def onload(self, tags: list[str] = None):
return ray.get([engine.resume_memory_occupation.remote(tags=tags) for engine in self.rollout_engines])
def health_monitoring_resume(self) -> None:
if self._health_monitor is not None:
self._health_monitor.resume()

def check_weights(self, action: str):
return ray.get([engine.check_weights.remote(action=action) for engine in self.rollout_engines])
Expand Down
Loading
Loading