Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ SGLANG_ARGS=(
--rollout-num-gpus-per-engine ${ROLLOUT_NUM_GPUS_PER_ENGINE:-4}
--sglang-mem-fraction-static ${STUDENT_MEM_FRACTION:-0.7}
--sglang-load-format dummy
--sglang-enable-weights-cpu-backup
--sglang-max-running-requests 64
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ SGLANG_ARGS=(
--rollout-num-gpus-per-engine ${ROLLOUT_NUM_GPUS_PER_ENGINE:-4}
--sglang-mem-fraction-static ${STUDENT_MEM_FRACTION:-0.7}
--sglang-load-format dummy
--sglang-enable-weights-cpu-backup
--sglang-max-running-requests 64
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ SGLANG_ARGS=(
--rollout-num-gpus-per-engine 4
--sglang-mem-fraction-static 0.6
--sglang-load-format dummy
--sglang-enable-weights-cpu-backup
--sglang-max-running-requests 64
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ SGLANG_ARGS=(
--rollout-num-gpus-per-engine 1
--sglang-mem-fraction-static 0.8
--sglang-load-format dummy
--sglang-enable-weights-cpu-backup
)

RESOURCE_JSON="{\"actor\": [1, ${ACTOR_GPUS}], \"rollout\": [1, ${ROLLOUT_GPUS}], \"teacher\": [1, ${TEACHER_GPUS}]}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ SGLANG_ARGS=(
--sglang-mem-fraction-static 0.6
--sglang-max-running-requests 128
--sglang-load-format dummy
--sglang-enable-weights-cpu-backup
)

PARTIAL_ROLLOUT_ARGS=(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ SGLANG_ARGS=(
--rollout-num-gpus-per-engine 2
--sglang-mem-fraction-static 0.7
--sglang-load-format dummy
--sglang-enable-weights-cpu-backup
)

RESOURCE_JSON="{\"actor\": [1, ${ACTOR_GPUS}], \"rollout\": [1, ${ROLLOUT_GPUS}], \"teacher\": [1, ${TEACHER_GPUS}]}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ SGLANG_ARGS=(
--sglang-mem-fraction-static ${STUDENT_MEM_FRACTION:-0.7}
--sglang-load-format dummy
--sglang-cuda-graph-bs 1 2 4 8 $(seq 16 8 256)
--sglang-enable-weights-cpu-backup
)

WANDB_ARGS=(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ SGLANG_ARGS=(
--rollout-num-gpus-per-engine "${ROLLOUT_NUM_GPUS_PER_ENGINE:-2}"
--sglang-mem-fraction-static "${STUDENT_MEM_FRACTION:-0.8}"
--sglang-load-format dummy
--sglang-enable-weights-cpu-backup
--sglang-cuda-graph-bs 1 2 4 8 $(seq 16 8 256)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ SGLANG_ARGS=(
--rollout-num-gpus-per-engine "${ROLLOUT_NUM_GPUS_PER_ENGINE:-2}"
--sglang-mem-fraction-static "${STUDENT_MEM_FRACTION:-0.8}"
--sglang-load-format dummy
--sglang-enable-weights-cpu-backup
--sglang-cuda-graph-bs 1 2 4 8 $(seq 16 8 256)
)

Expand Down
2 changes: 2 additions & 0 deletions relax/utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from relax.utils.opd.opd_utils import (
add_opd_arguments,
is_managed_opd_teacher_enabled,
maybe_enable_sglang_weights_cpu_backup,
teacher_sglang_parse_args,
validate_managed_opd_teacher_colocate_args,
validate_opd_args,
Expand Down Expand Up @@ -3455,6 +3456,7 @@ def slime_validate_args(args):
args.offload_train = False
if args.offload_rollout is None:
args.offload_rollout = False
maybe_enable_sglang_weights_cpu_backup(args)

if args.use_critic:
args.offload_train = True
Expand Down
15 changes: 15 additions & 0 deletions relax/utils/opd/opd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ def build_teacher_overrides(args: Any, colocate_sync: bool = False) -> dict[str,
overrides["model_path"] = args.teacher_hf_checkpoint
overrides.setdefault("load_format", "auto")
overrides.setdefault("enable_memory_saver", colocate_sync)
if overrides.get("enable_memory_saver"):
# Release/resume without a CPU backup leaves weight pages uninitialized (uniform output).
overrides.setdefault("enable_weights_cpu_backup", True)
return overrides


Expand Down Expand Up @@ -460,6 +463,18 @@ def validate_managed_opd_teacher_colocate_args(args: Any) -> None:
)


def maybe_enable_sglang_weights_cpu_backup(args: Any) -> None:
# Rollout sleep/wake without a CPU backup leaves weight pages uninitialized.
if not getattr(args, "use_opd", False):
return
if not getattr(args, "offload_rollout", False):
return
if getattr(args, "sglang_enable_weights_cpu_backup", False):
return
logger.info("OPD with offloaded rollout: auto-enabling --sglang-enable-weights-cpu-backup.")
args.sglang_enable_weights_cpu_backup = True


def add_opd_arguments(parser: Any) -> Any:
parser.add_argument(
"--use-opd",
Expand Down
33 changes: 33 additions & 0 deletions tests/distributed/ray/test_teacher_sglang_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from relax.utils.opd.opd_utils import (
build_teacher_engine_args,
build_teacher_overrides,
maybe_enable_sglang_weights_cpu_backup,
teacher_sglang_parse_args,
)

Expand Down Expand Up @@ -52,3 +53,35 @@ def add_cli_args(parser):

assert args.teacher_sglang_mem_fraction_static == 0.73
assert not hasattr(args, "teacher_sglang_model_path")


def test_opd_with_offloaded_rollout_enables_weights_cpu_backup():
args = SimpleNamespace(use_opd=True, offload_rollout=True)

maybe_enable_sglang_weights_cpu_backup(args)

assert args.sglang_enable_weights_cpu_backup is True


def test_opd_without_offload_keeps_weights_cpu_backup_untouched():
args = SimpleNamespace(use_opd=True, offload_rollout=False)

maybe_enable_sglang_weights_cpu_backup(args)

assert not hasattr(args, "sglang_enable_weights_cpu_backup")


def test_non_opd_keeps_weights_cpu_backup_untouched():
args = SimpleNamespace(offload_rollout=True)

maybe_enable_sglang_weights_cpu_backup(args)

assert not hasattr(args, "sglang_enable_weights_cpu_backup")


def test_explicit_weights_cpu_backup_is_preserved():
args = SimpleNamespace(use_opd=True, offload_rollout=True, sglang_enable_weights_cpu_backup=True)

maybe_enable_sglang_weights_cpu_backup(args)

assert args.sglang_enable_weights_cpu_backup is True
Loading