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
4 changes: 2 additions & 2 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
strategy:
fail-fast: false
matrix:
info: [{"num_gpus": 8, "test_file": "test_quick_start_glm4_9B.py"}, {"num_gpus": 8, "test_file": "test_qwen3_30B_A3B.py", "use_deepep": "1", "use_fp8_rollout": "1"}, {"enable_eval": "0", "num_gpus": 8, "test_file": "test_qwen3_30B_A3B_r3.py", "use_deepep": "1", "use_fp8_rollout": "1"}, {"enable_eval": "0", "num_gpus": 8, "test_file": "test_qwen3_30B_A3B_r3.py"}, {"num_gpus": 8, "test_file": "test_qwen3_4B_ppo.py"}, {"num_gpus": 8, "test_file": "test_moonlight_16B_A3B.py"}, {"enable_eval": "0", "num_gpus": 8, "test_file": "test_moonlight_16B_A3B_r3.py"}, {"num_gpus": 8, "test_file": "test_mimo_7B_mtp_only_grad.py"}]
info: [{"num_gpus": 8, "test_file": "test_quick_start_glm4_9B.py"}, {"num_gpus": 8, "test_file": "test_qwen3_30B_A3B.py", "use_deepep": "1", "use_fp8_rollout": "1"}, {"enable_eval": "0", "num_gpus": 8, "test_file": "test_qwen3_30B_A3B_r3.py", "use_deepep": "1", "use_fp8_rollout": "1"}, {"enable_eval": "0", "num_gpus": 8, "test_file": "test_qwen3_30B_A3B_r3.py"}, {"num_gpus": 8, "test_file": "test_qwen3_4B_ppo.py"}, {"num_gpus": 8, "test_file": "test_moonlight_16B_A3B.py"}, {"enable_eval": "0", "num_gpus": 8, "test_file": "test_moonlight_16B_A3B_r3.py"}, {"num_gpus": 8, "test_file": "test_mimo_7B_mtp_only_grad.py"}, {"num_gpus": 8, "test_file": "test_qwen2.5_0.5B_debug_rollout_then_train.py"}]
defaults:
run:
working-directory: ${{ github.workspace }}
Expand Down Expand Up @@ -330,7 +330,7 @@ jobs:
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"}, {"num_gpus": 2, "test_file": "test_qwen3_0.6B_fsdp_colocated_2xGPU.py"}, {"num_gpus": 2, "test_file": "test_qwen3_4B_fsdp_true_on_policy.py"}, {"num_gpus": 8, "test_file": "test_qwen3_vl_4B_fsdp.py"}, {"num_gpus": 2, "test_file": "test_qwen3_0.6B_fsdp_distributed.py"}, {"num_gpus": 8, "test_file": "test_quick_start_glm4_9B.py"}, {"num_gpus": 8, "test_file": "test_qwen3_30B_A3B.py"}, {"num_gpus": 8, "test_file": "test_qwen3_4B_ppo.py"}, {"num_gpus": 8, "test_file": "test_moonlight_16B_A3B.py"}, {"num_gpus": 8, "test_file": "test_mimo_7B_mtp_only_grad.py"}, {"num_gpus": 8, "test_file": "test_qwen3_0.6B_parallel_check.py"}, {"num_gpus": 4, "test_file": "test_qwen3_0.6B_megatron_fsdp_align.py"}, {"num_gpus": 8, "test_file": "test_qwen3_4B_ckpt.py"}, {"num_gpus": 8, "test_file": "test_qwen3_4B_ckpt.py --async-save"}, {"num_gpus": 2, "test_file": "test_qwen2.5_0.5B_gsm8k.py"}, {"num_gpus": 2, "test_file": "test_qwen2.5_0.5B_gsm8k_async.py"}]
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"}, {"num_gpus": 2, "test_file": "test_qwen3_0.6B_fsdp_colocated_2xGPU.py"}, {"num_gpus": 2, "test_file": "test_qwen3_4B_fsdp_true_on_policy.py"}, {"num_gpus": 8, "test_file": "test_qwen3_vl_4B_fsdp.py"}, {"num_gpus": 2, "test_file": "test_qwen3_0.6B_fsdp_distributed.py"}, {"num_gpus": 8, "test_file": "test_quick_start_glm4_9B.py"}, {"num_gpus": 8, "test_file": "test_qwen3_30B_A3B.py"}, {"num_gpus": 8, "test_file": "test_qwen3_4B_ppo.py"}, {"num_gpus": 8, "test_file": "test_moonlight_16B_A3B.py"}, {"num_gpus": 8, "test_file": "test_mimo_7B_mtp_only_grad.py"}, {"num_gpus": 8, "test_file": "test_qwen3_0.6B_parallel_check.py"}, {"num_gpus": 4, "test_file": "test_qwen3_0.6B_megatron_fsdp_align.py"}, {"num_gpus": 8, "test_file": "test_qwen3_4B_ckpt.py"}, {"num_gpus": 8, "test_file": "test_qwen3_4B_ckpt.py --async-save"}, {"num_gpus": 2, "test_file": "test_qwen2.5_0.5B_gsm8k.py"}, {"num_gpus": 2, "test_file": "test_qwen2.5_0.5B_gsm8k_async.py"}, {"num_gpus": 8, "test_file": "test_qwen2.5_0.5B_debug_rollout_then_train.py"}]
defaults:
run:
working-directory: ${{ github.workspace }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-test.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
{'test_file': 'test_moonlight_16B_A3B.py', 'num_gpus': 8},
{'test_file': 'test_moonlight_16B_A3B_r3.py', 'num_gpus': 8, 'enable_eval': '0'},
{'test_file': 'test_mimo_7B_mtp_only_grad.py', 'num_gpus': 8},
{'test_file': 'test_qwen2.5_0.5B_debug_rollout_then_train.py', 'num_gpus': 8},
],
},
'e2e-test-precision': {
Expand Down Expand Up @@ -72,6 +73,7 @@
{'test_file': 'test_qwen3_4B_ckpt.py --async-save', 'num_gpus': 8},
{'test_file': 'test_qwen2.5_0.5B_gsm8k.py', 'num_gpus': 2},
{'test_file': 'test_qwen2.5_0.5B_gsm8k_async.py', 'num_gpus': 2},
{'test_file': 'test_qwen2.5_0.5B_debug_rollout_then_train.py', 'num_gpus': 8},
],
},
} %>
Expand Down
4 changes: 2 additions & 2 deletions slime/backends/fsdp_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging

from .actor import FSDPTrainRayActor
from .arguments import load_fsdp_args
from .arguments import fsdp_parse_args

__all__ = ["load_fsdp_args", "FSDPTrainRayActor"]
__all__ = ["fsdp_parse_args", "FSDPTrainRayActor"]

logging.getLogger().setLevel(logging.WARNING)
13 changes: 9 additions & 4 deletions slime/backends/fsdp_utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class FSDPArgs:
config: str | None = None


def parse_fsdp_cli(extra_args_provider=None):
def _parse_fsdp_cli(extra_args_provider=None, ignore_unknown_args=False):
parser = argparse.ArgumentParser("FSDP SFT Training (slime)")
parser.add_argument("--config", type=str, default=None, help="YAML config path")
for f in dataclasses.fields(FSDPArgs):
Expand All @@ -81,16 +81,21 @@ def parse_fsdp_cli(extra_args_provider=None):

if extra_args_provider is not None:
parser = extra_args_provider(parser)
args = parser.parse_args()
if ignore_unknown_args:
args, _ = parser.parse_known_args()
else:
args = parser.parse_args()
return args


def load_fsdp_args(extra_args_provider=None):
args = parse_fsdp_cli(extra_args_provider)
def fsdp_parse_args(extra_args_provider=None, ignore_unknown_args=False):
args = _parse_fsdp_cli(extra_args_provider, ignore_unknown_args=ignore_unknown_args)
if args.config:
with open(args.config) as f:
data = yaml.safe_load(f) or {}
for k, v in data.items():
if not hasattr(args, k):
setattr(args, k, v)
args.rank = 0 # Primary process rank for wandb initialization
args.world_size = args.actor_num_nodes * args.actor_num_gpus_per_node
return args
13 changes: 7 additions & 6 deletions slime/backends/megatron_utils/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def init(

super().init(args, role, with_ref, with_opd_teacher)

if args.debug_rollout_only:
return 0

init(args)

if is_megatron_main_rank():
Expand All @@ -79,9 +82,6 @@ def init(
logger.info(f"Set torch_memory_saver.memory_margin_bytes to {x}")
torch_memory_saver.memory_margin_bytes = x

if self.args.debug_rollout_only:
return 0

if role == "critic":
self.args.load = self.args.critic_load
self.args.save = self.args.critic_save
Expand Down Expand Up @@ -350,14 +350,15 @@ def compute_log_prob(
)

def train(self, rollout_id: int, rollout_data_ref: Box) -> None:
if self.args.debug_rollout_only:
return

if self.args.offload_train:
self.wake_up()

with timer("data_preprocess"):
rollout_data = self._get_rollout_data(rollout_data_ref)
if self.args.debug_rollout_only:
log_rollout_data(rollout_id, self.args, rollout_data)
return
log_rollout_data(rollout_id, self.args, rollout_data)

if self.role == "critic":
return self.train_critic(rollout_id, rollout_data)
Expand Down
76 changes: 73 additions & 3 deletions slime/backends/megatron_utils/arguments.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,66 @@
import logging

from megatron.training.arguments import parse_args, validate_args
from megatron.training.arguments import parse_args as _megatron_parse_args
from megatron.training.arguments import validate_args as _megatron_validate_args
from megatron.training.tokenizer.tokenizer import _vocab_size_with_padding
from transformers import AutoConfig

__all__ = ["validate_args", "parse_args", "set_default_megatron_args"]
__all__ = ["validate_args", "megatron_parse_args", "set_default_megatron_args"]

logger = logging.getLogger(__name__)


def set_default_megatron_args(args):
def validate_args(args):
"""Run megatron's own validate_args plus slime-specific megatron validations."""
_megatron_validate_args(args)

# always use varlen
args.variable_seq_lengths = True
if getattr(args, "moe_token_dispatcher_type", None) == "allgather":
logger.info(
"--moe-token-dispatcher-type allgather does not support variable sequence length, "
"please use alltoall dispatcher instead."
)
args.moe_token_dispatcher_type = "alltoall"

if args.pipeline_model_parallel_size == 1:
assert args.decoder_first_pipeline_num_layers is None and args.decoder_last_pipeline_num_layers is None, (
"decoder_first_pipeline_num_layers and decoder_last_pipeline_num_layers should be None when "
"pipeline_model_parallel_size is 1."
)


def _hf_validate_args(args, hf_config):
def equal(x, y):
return x == y

errors = []

# multimodal models have different config structure
if hasattr(hf_config, "text_config"):
hf_config = hf_config.text_config

for hf_config_name, megatron_config_name, compare_fn in [
("hidden_size", "hidden_size", equal),
("num_attention_heads", "num_attention_heads", equal),
("num_hidden_layers", "num_layers", equal),
("intermediate_size", "ffn_hidden_size", equal),
("tie_word_embeddings", "untie_embeddings_and_output_weights", lambda x, y: not x == y),
("rms_norm_eps", "norm_epsilon", equal),
("rope_theta", "rotary_base", equal),
]:
if hasattr(hf_config, hf_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."
)

if len(errors) > 0:
raise AssertionError("hf_validate_args failed: " + "; ".join(errors))


def _set_default_megatron_args(args):
# always use zero optimizer
args.use_distributed_optimizer = True
# TODO: maybe change this after megatron has good fp8 support
Expand All @@ -31,3 +83,21 @@ def set_default_megatron_args(args):
args.tokenizer_model = args.hf_checkpoint
args.tokenizer_type = "HuggingFaceTokenizer"
return args


# Public alias for external tools (e.g. convert_hf_to_torch_dist.py)
set_default_megatron_args = _set_default_megatron_args


def megatron_parse_args(extra_args_provider, skip_hf_validate=False):
"""Parse megatron args, validate HF config, and set defaults."""
args = _megatron_parse_args(extra_args_provider=extra_args_provider, ignore_unknown_args=True)

if args.hf_checkpoint and not skip_hf_validate:
hf_config = AutoConfig.from_pretrained(args.hf_checkpoint, trust_remote_code=True)
_hf_validate_args(args, hf_config)

args.rank = 0
args.world_size = args.actor_num_nodes * args.actor_num_gpus_per_node
args = _set_default_megatron_args(args)
return args
28 changes: 28 additions & 0 deletions slime/backends/sglang_utils/arguments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import argparse

from sglang.srt.server_args import ServerArgs
from slime.utils.http_utils import _wrap_ipv6

Expand Down Expand Up @@ -138,3 +140,29 @@ def validate_args(args):

if getattr(args, "sglang_router_ip", None):
args.sglang_router_ip = _wrap_ipv6(args.sglang_router_ip)


def sglang_parse_args():
"""
Parse sglang server arguments independently using a separate ArgumentParser.
Uses parse_known_args() to only consume sglang-related arguments from sys.argv,
allowing the remaining arguments to be parsed by megatron/fsdp separately.

Returns:
argparse.Namespace: Parsed sglang arguments (all attributes prefixed with sglang_).
"""
parser = argparse.ArgumentParser(add_help=False)
add_sglang_arguments(parser)

# Compute default sglang_tensor_parallel_size from CLI args
temp_parser = argparse.ArgumentParser(add_help=False)
temp_parser.add_argument("--rollout-num-gpus-per-engine", type=int, default=1)
temp_parser.add_argument("--sglang-pp-size", type=int, default=1)
temp_parser.add_argument("--sglang-pipeline-parallel-size", type=int, default=1)
temp_args, _ = temp_parser.parse_known_args()
pp_size = temp_args.sglang_pp_size if temp_args.sglang_pp_size != 1 else temp_args.sglang_pipeline_parallel_size
sglang_tp_size = temp_args.rollout_num_gpus_per_engine // pp_size
parser.set_defaults(sglang_tensor_parallel_size=sglang_tp_size)

args, _ = parser.parse_known_args()
return args
21 changes: 13 additions & 8 deletions slime/ray/rollout.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ class RolloutManager:
def __init__(self, args, pg):
configure_logger()

self.args = args
self.pg = pg
_start_router(args)
# TODO make args immutable
init_tracking(args, primary=False, router_addr=f"http://{args.sglang_router_ip}:{args.sglang_router_port}")
init_http_client(args)
self.args = args

init_tracking(args, primary=False)

data_source_cls = load_function(self.args.data_source_path)
self.data_source = data_source_cls(args)
Expand All @@ -72,17 +70,19 @@ def __init__(self, args, pg):
if self.args.debug_train_only:
self.all_rollout_engines = []
else:
_start_router(args)
init_http_client(args)
num_gpu_per_engine = min(args.rollout_num_gpus_per_engine, args.num_gpus_per_node)
num_engines = args.rollout_num_gpus // num_gpu_per_engine
self.all_rollout_engines = [None] * num_engines
self.nodes_per_engine = max(1, args.rollout_num_gpus_per_engine // args.num_gpus_per_node)
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:
if not self.args.debug_train_only and 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
Expand Down Expand Up @@ -117,6 +117,8 @@ def dispose(self):
# TODO maybe rename "rollout_engines" and "all_rollout_engines" later
@property
def rollout_engines(self):
if self.args.debug_train_only:
return []
# when doing multi-node serving, we will only send request to node-0 for each engine.
return self.all_rollout_engines[:: self.nodes_per_engine]

Expand All @@ -136,6 +138,9 @@ def generate(self, rollout_id):
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)
if self.args.debug_rollout_only:
# if debug rollout only, we don't convert samples to train data and directly return
return
data = self._convert_samples_to_train_data(data)
return self._split_train_data_by_dp(data, self.train_parallel_config["dp_size"])

Expand Down Expand Up @@ -234,7 +239,7 @@ def _get_rollout_data(self, rollout_id):
while isinstance(data[0], list):
data = list(itertools.chain.from_iterable(data))

if not self.args.disable_rollout_trim_samples:
if not self.args.disable_rollout_trim_samples and not self.args.debug_rollout_only:
global_batch_size = self.args.global_batch_size
if self.args.use_dynamic_global_batch_size:
logger.info(f"Collected {len(data)} samples from rollout to train with dynamic global batch size")
Expand Down
2 changes: 1 addition & 1 deletion slime/ray/train_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ def _get_parallel_config(self):

def set_rollout_manager(self, rollout_manager):
self.rollout_manager = rollout_manager
if self.args.rank == 0:
if not self.args.debug_rollout_only and self.args.rank == 0:
ray.get(self.rollout_manager.set_train_parallel_config.remote(self.train_parallel_config))
Loading
Loading