Compare commits

...
Author SHA1 Message Date
d8698f4e53 test(ci): add reverse-text smoke tests for RL OPD + SFT training modes (#2563)
Release / Push CUDA image to Docker (push) Canceled after 0s
* test(ci): add reverse-text smoke tests for RL OPD + SFT training modes

Covers the rl-entrypoint training_mode = "opd" / "sft" paths on the
existing `vm` integration runner. The student inference deployment is
launched by the rl entrypoint; the teacher is started as a dedicated
`uv run inference` process by the test fixture (low gpu_memory_utilization
on GPU 0 so the student still fits), with orchestrator.teacher.client
pointing at it.

Both tests pass locally on 2× Blackwell GPUs in ~1m40s each.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* test(ci): match reverse_text training config + symmetric 0.4 gpu util

Aligns max_steps / seq_len / batch_size / rollouts_per_example / max_completion_tokens
with the existing reverse_text smoke test, and switches the student+teacher
overlap from asymmetric (0.85 + 0.1) to symmetric 0.4 + 0.4 — both fit on one
Blackwell GPU with the small Qwen3-0.6B models. Both tests still pass locally
(~2m10s each).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* test(ci): drop to 5 steps and remove [ckpt] for the OPD/SFT smoke tests

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* test(ci): drop [deployment] and enforce_eager from OPD/SFT configs

Matches the rest of `configs/ci/integration/` — the default
SingleNodeDeploymentConfig (1 train + 1 infer GPU, gpus_per_node=8)
works on the 2-GPU vm runner, and no other CI config sets
enforce_eager. OPD test still passes locally (2m18s).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* test(ci): assert eval reward goes up instead of loss goes down

Loss going down is a weak signal for distillation training modes — both OPD
(KL-style) and SFT (teacher-token CE) loss curves are noisy across the 5
smoke steps. Switch to checking that the per-step eval reward on the same
reverse-text env actually improves end-to-end.

- Add [orchestrator.eval] (interval=1, num_examples=16) to both configs.
- New `check_eval_avg_goes_up` helper greps the orchestrator log for
  "Evaluated <env> ... Avg@K=X.XXXX" and asserts last > first.

Both tests pass locally (OPD 1m52s, SFT 1m42s).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-19 15:30:44 -07:00
6 changed files with 346 additions and 0 deletions
+6
View File
@@ -69,6 +69,12 @@ jobs:
- test: reverse_text
runner: vm
pytest_args: "tests/integration/test_reverse_text.py"
- test: reverse_text_rl_opd
runner: vm
pytest_args: "tests/integration/test_reverse_text_rl_opd.py"
- test: reverse_text_rl_sft
runner: vm
pytest_args: "tests/integration/test_reverse_text_rl_sft.py"
- test: alphabet_sort
runner: vm
pytest_args: "tests/integration/test_alphabet_sort.py"
@@ -0,0 +1,51 @@
# Smoke test for the RL-entrypoint OPD (on-policy distillation) training mode.
# The student inference deployment is launched by the rl entrypoint on GPU 0;
# the teacher inference server is started externally by the test fixture (see
# tests/integration/test_reverse_text_rl_opd.py) on the same GPU. Trainer
# takes GPU 1. Training config mirrors `reverse_text/start.toml`.
max_steps = 5
seq_len = 2048
[model]
name = "PrimeIntellect/Qwen3-0.6B-Reverse-Text-SFT"
[wandb]
project = "reverse-text-ci"
name = "ci-rl-opd"
[orchestrator]
training_mode = "opd"
batch_size = 128
rollouts_per_example = 16
[orchestrator.renderer]
name = "qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
id = "reverse-text"
[orchestrator.eval]
interval = 1
num_examples = 16
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
id = "reverse-text"
[orchestrator.teacher.model]
name = "PrimeIntellect/Qwen3-0.6B-Reverse-Text-RL"
[orchestrator.teacher.client]
base_url = ["http://localhost:8001/v1"]
[trainer.optim]
lr = 3e-6
[inference]
gpu_memory_utilization = 0.4
@@ -0,0 +1,48 @@
# Smoke test for the RL-entrypoint SFT (on-policy hard distillation) training
# mode. The student inference deployment is launched by the rl entrypoint on
# GPU 0; the teacher inference server is started externally by the test
# fixture (see tests/integration/test_reverse_text_rl_sft.py) on the same GPU.
# Trainer takes GPU 1. Training config mirrors `reverse_text/start.toml`.
max_steps = 5
seq_len = 2048
[model]
name = "PrimeIntellect/Qwen3-0.6B-Reverse-Text-SFT"
[wandb]
project = "reverse-text-ci"
name = "ci-rl-sft"
[orchestrator]
training_mode = "sft"
batch_size = 128
rollouts_per_example = 16
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
id = "reverse-text"
[orchestrator.eval]
interval = 1
num_examples = 16
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
id = "reverse-text"
[orchestrator.teacher.model]
name = "PrimeIntellect/Qwen3-0.6B-Reverse-Text-RL"
[orchestrator.teacher.client]
base_url = ["http://localhost:8001/v1"]
[trainer.optim]
lr = 3e-6
[inference]
gpu_memory_utilization = 0.4
@@ -0,0 +1,113 @@
import os
import signal
import subprocess
import time
from pathlib import Path
from typing import Callable, Generator
import httpx
import pytest
from prime_rl.utils.process import cleanup_process
from tests.conftest import ProcessResult
from tests.utils import check_eval_avg_goes_up, check_no_error, strip_escape_codes
pytestmark = [pytest.mark.gpu, pytest.mark.slow]
TIMEOUT = 600 # 10 minutes
TEACHER_PORT = 8001
TEACHER_READY_TIMEOUT_S = 300
def _wait_for_teacher(port: int, timeout_s: int) -> None:
"""Block until the teacher inference server's /v1/models endpoint is reachable."""
url = f"http://localhost:{port}/v1/models"
deadline = time.time() + timeout_s
while time.time() < deadline:
try:
r = httpx.get(url, timeout=2.0)
if r.status_code == 200:
return
except (httpx.ConnectError, httpx.ReadTimeout):
pass
time.sleep(1.0)
raise TimeoutError(f"Teacher inference server at {url} did not become ready within {timeout_s}s")
@pytest.fixture(scope="module")
def teacher_inference(output_dir: Path) -> Generator[subprocess.Popen, None, None]:
"""Spawn a `uv run inference` teacher on GPU 0 (shared with the rl-launched
student) at 40% gpu_memory_utilization. Tears down at module scope.
"""
# The rl entrypoint's --clean-output-dir wipes the rl output_dir on start,
# so park the teacher log next to it instead of inside it.
teacher_log_dir = output_dir.parent / f"{output_dir.name}_teacher"
teacher_log_dir.mkdir(parents=True, exist_ok=True)
log_path = teacher_log_dir / "teacher_inference.log"
cmd = [
"uv",
"run",
"inference",
"--model.name",
"PrimeIntellect/Qwen3-0.6B-Reverse-Text-RL",
"--server.port",
str(TEACHER_PORT),
"--gpu-memory-utilization",
"0.4",
]
env = {**os.environ, "CUDA_VISIBLE_DEVICES": "0"}
with open(log_path, "w") as log_file:
proc = subprocess.Popen(cmd, env=env, stdout=log_file, stderr=log_file)
try:
_wait_for_teacher(TEACHER_PORT, TEACHER_READY_TIMEOUT_S)
yield proc
finally:
cleanup_process(proc.pid, signal.SIGTERM)
try:
proc.wait(timeout=30)
except subprocess.TimeoutExpired:
cleanup_process(proc.pid, signal.SIGKILL)
proc.wait()
@pytest.fixture(scope="module")
def wandb_name(branch_name: str) -> str:
return f"test-reverse-text-rl-opd:{branch_name}"
@pytest.fixture(scope="module")
def rl_opd_process(
teacher_inference,
run_process: Callable[..., ProcessResult],
output_dir: Path,
wandb_project: str,
wandb_name: str,
) -> ProcessResult:
"""Run the RL entrypoint with training_mode = "opd"; teacher_inference is
a fixture-managed external vLLM at http://localhost:8001/v1."""
cmd = [
"uv",
"run",
"rl",
"@",
"configs/ci/integration/reverse_text_rl_opd/start.toml",
"--clean-output-dir",
"--wandb.project",
wandb_project,
"--wandb.name",
wandb_name,
"--output-dir",
output_dir.as_posix(),
]
return run_process(cmd, timeout=TIMEOUT)
@pytest.fixture(scope="module")
def test_no_error(rl_opd_process: ProcessResult, output_dir: Path):
check_no_error(rl_opd_process, output_dir)
def test_eval_avg_goes_up(rl_opd_process: ProcessResult, test_no_error, output_dir: Path):
with open(output_dir / "logs" / "orchestrator.log", "r") as f:
orchestrator_stdout = strip_escape_codes(f.read()).splitlines()
check_eval_avg_goes_up(orchestrator_stdout, env_name="reverse-text")
@@ -0,0 +1,113 @@
import os
import signal
import subprocess
import time
from pathlib import Path
from typing import Callable, Generator
import httpx
import pytest
from prime_rl.utils.process import cleanup_process
from tests.conftest import ProcessResult
from tests.utils import check_eval_avg_goes_up, check_no_error, strip_escape_codes
pytestmark = [pytest.mark.gpu, pytest.mark.slow]
TIMEOUT = 600 # 10 minutes
TEACHER_PORT = 8001
TEACHER_READY_TIMEOUT_S = 300
def _wait_for_teacher(port: int, timeout_s: int) -> None:
"""Block until the teacher inference server's /v1/models endpoint is reachable."""
url = f"http://localhost:{port}/v1/models"
deadline = time.time() + timeout_s
while time.time() < deadline:
try:
r = httpx.get(url, timeout=2.0)
if r.status_code == 200:
return
except (httpx.ConnectError, httpx.ReadTimeout):
pass
time.sleep(1.0)
raise TimeoutError(f"Teacher inference server at {url} did not become ready within {timeout_s}s")
@pytest.fixture(scope="module")
def teacher_inference(output_dir: Path) -> Generator[subprocess.Popen, None, None]:
"""Spawn a `uv run inference` teacher on GPU 0 (shared with the rl-launched
student) at 40% gpu_memory_utilization. Tears down at module scope.
"""
# The rl entrypoint's --clean-output-dir wipes the rl output_dir on start,
# so park the teacher log next to it instead of inside it.
teacher_log_dir = output_dir.parent / f"{output_dir.name}_teacher"
teacher_log_dir.mkdir(parents=True, exist_ok=True)
log_path = teacher_log_dir / "teacher_inference.log"
cmd = [
"uv",
"run",
"inference",
"--model.name",
"PrimeIntellect/Qwen3-0.6B-Reverse-Text-RL",
"--server.port",
str(TEACHER_PORT),
"--gpu-memory-utilization",
"0.4",
]
env = {**os.environ, "CUDA_VISIBLE_DEVICES": "0"}
with open(log_path, "w") as log_file:
proc = subprocess.Popen(cmd, env=env, stdout=log_file, stderr=log_file)
try:
_wait_for_teacher(TEACHER_PORT, TEACHER_READY_TIMEOUT_S)
yield proc
finally:
cleanup_process(proc.pid, signal.SIGTERM)
try:
proc.wait(timeout=30)
except subprocess.TimeoutExpired:
cleanup_process(proc.pid, signal.SIGKILL)
proc.wait()
@pytest.fixture(scope="module")
def wandb_name(branch_name: str) -> str:
return f"test-reverse-text-rl-sft:{branch_name}"
@pytest.fixture(scope="module")
def rl_sft_process(
teacher_inference,
run_process: Callable[..., ProcessResult],
output_dir: Path,
wandb_project: str,
wandb_name: str,
) -> ProcessResult:
"""Run the RL entrypoint with training_mode = "sft"; teacher_inference is
a fixture-managed external vLLM at http://localhost:8001/v1."""
cmd = [
"uv",
"run",
"rl",
"@",
"configs/ci/integration/reverse_text_rl_sft/start.toml",
"--clean-output-dir",
"--wandb.project",
wandb_project,
"--wandb.name",
wandb_name,
"--output-dir",
output_dir.as_posix(),
]
return run_process(cmd, timeout=TIMEOUT)
@pytest.fixture(scope="module")
def test_no_error(rl_sft_process: ProcessResult, output_dir: Path):
check_no_error(rl_sft_process, output_dir)
def test_eval_avg_goes_up(rl_sft_process: ProcessResult, test_no_error, output_dir: Path):
with open(output_dir / "logs" / "orchestrator.log", "r") as f:
orchestrator_stdout = strip_escape_codes(f.read()).splitlines()
check_eval_avg_goes_up(orchestrator_stdout, env_name="reverse-text")
+15
View File
@@ -107,6 +107,21 @@ def check_loss_goes_down(lines: list[str]):
return check_number_goes_up_or_down(lines, go_up=False, pattern=r"Loss:\s*(\d+\.\d{4})")
def check_eval_avg_goes_up(lines: list[str], env_name: str):
"""Assert that the last `Evaluated {env_name} ... Avg@K=X.XXXX` line reports a
higher score than the first one. Use for smoke tests with `interval = 1`
evals."""
pattern = rf"Evaluated {re.escape(env_name)} .*Avg@\d+=(\d+\.\d{{4}})"
eval_lines = [line for line in lines if "SUCCESS" in line and re.search(pattern, line)]
assert len(eval_lines) >= 2, f"Need at least 2 eval lines for {env_name!r}, found {len(eval_lines)}"
start = float(re.search(pattern, eval_lines[0]).group(1))
end = float(re.search(pattern, eval_lines[-1]).group(1))
assert end > start, (
f"Eval avg for {env_name!r} did not go up: first={start} last={end}\n"
f"first line: {eval_lines[0]}\nlast line: {eval_lines[-1]}"
)
def check_reward_in_range(
lines: list[str],
step: int = -1,