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
39 changes: 39 additions & 0 deletions tests/dist_rl/launch/common/resolve_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,45 @@ def test_rollout_cache_params_follow_config(self):
resolve_config.rollout_cache_params(hp).enable_prefix_caching
)

def test_rollout_seed_defaults_to_42_and_validates_type(self):
default_hp = resolve_config.initialize(["agentic_grpo_config.beta=0.0"])
self.assertEqual(default_hp.config["rollout_config"]["seed"], 42)

null_hp = resolve_config.initialize(
["agentic_grpo_config.beta=0.0", "rollout_config.seed=null"]
)
self.assertIsNone(null_hp.config["rollout_config"]["seed"])

zero_hp = resolve_config.initialize(
["agentic_grpo_config.beta=0.0", "rollout_config.seed=0"]
)
self.assertEqual(zero_hp.config["rollout_config"]["seed"], 0)
# Changing the rollout seed does not split the JAX compilation cache key.
self.assertEqual(
resolve_config.rollout_cache_params(default_hp),
resolve_config.rollout_cache_params(zero_hp),
)

for bad_seed in ("true", "false", "1.5", "'abc'"):
with self.subTest(bad_seed=bad_seed):
with self.assertRaisesRegex(
TypeError, r"rollout_config\.seed must be an int or null"
):
resolve_config.initialize([
"agentic_grpo_config.beta=0.0",
f"rollout_config.seed={bad_seed}",
])

for neg_seed in ("-1", "-42"):
with self.subTest(neg_seed=neg_seed):
with self.assertRaisesRegex(
ValueError, r"rollout_config\.seed must be non-negative"
):
resolve_config.initialize([
"agentic_grpo_config.beta=0.0",
f"rollout_config.seed={neg_seed}",
])

def test_rollout_cache_settings_fail_loud(self):
# `k8s.sh` and the URI derivation must read `disable` the same way.
with self.assertRaisesRegex(TypeError, "jax_cache.disable must be a bool"):
Expand Down
18 changes: 18 additions & 0 deletions tests/dist_rl/launch/nodes/node_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,24 @@ def test_external_rollout_replica_takes_index_from_env(self):
with self.assertRaisesRegex(ValueError, f"{replica_env} must be set"):
node_utils.worker_id(hp, "rollout", "rollout-0")

def test_rollout_replica_index_reads_and_validates_env(self):
single_hp = resolve_config.initialize([
"cluster_config.target=k8s",
"cluster_config.k8s.rollout_id=exp-v2-9",
"agentic_grpo_config.beta=0.0",
])
replica_env = node_utils.ROLLOUT_REPLICA_ENV
env = {k: v for k, v in os.environ.items() if k != replica_env}
with mock.patch.dict(os.environ, env, clear=True):
# Numeric suffix in a single-replica k8s rollout_id does not shift index.
self.assertEqual(node_utils.rollout_replica_index(single_hp), 0)

multi_hp = resolve_config.initialize(
[*_EXTERNAL, "cluster_config.rollout_replicas=4"]
)
with mock.patch.dict(os.environ, {replica_env: "3"}):
self.assertEqual(node_utils.rollout_replica_index(multi_hp), 3)

def test_service_port_reads_role_port(self):
port_env = node_utils.WORKER_PORT_ENV
env = {k: v for k, v in os.environ.items() if k != port_env}
Expand Down
35 changes: 35 additions & 0 deletions tests/dist_rl/launch/nodes/rollout_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,41 @@ def test_defaults_disable_top_k(self):
self.assertEqual(config.top_k, -1)
self.assertTrue(config.return_logprobs)

def test_per_replica_seed_derives_32bit_seed_and_reaches_all_samplers(self):
replica_env = node_utils.ROLLOUT_REPLICA_ENV
env_without_replica = {
k: v for k, v in os.environ.items() if k != replica_env
}
with mock.patch.dict(os.environ, env_without_replica, clear=True):
self.assertEqual(_rollout_config().seed, 42)
self.assertEqual(_vllm_engine_kwargs()["seed"], 42)
self.assertIsNone(_rollout_config("rollout_config.seed=null").seed)
self.assertNotIn(
"seed", _vllm_engine_kwargs("rollout_config.seed=null")
)

multi_argv = (
"cluster_config.target=k8s",
"cluster_config.rollout_replicas=8",
"agentic_grpo_config.beta=0.0",
)
with mock.patch.dict(os.environ, {replica_env: "5"}):
self.assertEqual(_rollout_config(*multi_argv).seed, 47)
self.assertEqual(_vllm_engine_kwargs(*multi_argv)["seed"], 47)
self.assertEqual(
rollout._rollout_config(
_hp(*multi_argv), mock.Mock(), sampler_type="vanilla"
).seed,
47,
)
# Modulo 2**32 keeps the seed within numpy's valid 32-bit range.
self.assertEqual(
_vllm_engine_kwargs(
*multi_argv, f"rollout_config.seed={2**32 - 2}"
)["seed"],
3,
)

def test_vllm_model_version_only_for_vllm_samplers(self):
hp = _hp()
self.assertEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"return_routed_experts": false,
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": 42,
"temperature": 1.0,
"top_k": -1,
"top_p": 1.0,
Expand Down Expand Up @@ -134,7 +135,7 @@
"rollout_vllm_tpu_backend_type": "jax",
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": null,
"seed": 42,
"staging_max_bytes": null,
"store_routed_experts": false,
"temperature": 1.0,
Expand Down Expand Up @@ -266,6 +267,7 @@
"max_num_batched_tokens": null,
"max_num_seqs": null,
"model": "Qwen/Qwen3-1.7B",
"seed": 42,
"tokenizer": "/models/tokenizer",
"trust_remote_code": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"return_routed_experts": false,
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": 42,
"temperature": 1.0,
"top_k": -1,
"top_p": 1.0,
Expand Down Expand Up @@ -150,7 +151,7 @@
"rollout_vllm_tpu_backend_type": "jax",
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": null,
"seed": 42,
"staging_max_bytes": null,
"store_routed_experts": false,
"temperature": 1.0,
Expand Down Expand Up @@ -296,6 +297,7 @@
"max_num_batched_tokens": 2048,
"max_num_seqs": 32,
"model": "google/gemma-4-E2B-it",
"seed": 42,
"tokenizer": "/models/tokenizer",
"trust_remote_code": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"return_routed_experts": false,
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": 43,
"temperature": 1.0,
"top_k": -1,
"top_p": 1.0,
Expand Down Expand Up @@ -136,7 +137,7 @@
"rollout_vllm_tpu_backend_type": "jax",
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": null,
"seed": 43,
"staging_max_bytes": null,
"store_routed_experts": false,
"temperature": 1.0,
Expand Down Expand Up @@ -279,6 +280,7 @@
"max_num_batched_tokens": null,
"max_num_seqs": null,
"model": "Qwen/Qwen3-1.7B",
"seed": 43,
"tokenizer": "/models/tokenizer",
"trust_remote_code": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"return_routed_experts": false,
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": 43,
"temperature": 1.0,
"top_k": -1,
"top_p": 1.0,
Expand Down Expand Up @@ -136,7 +137,7 @@
"rollout_vllm_tpu_backend_type": "jax",
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": null,
"seed": 43,
"staging_max_bytes": null,
"store_routed_experts": false,
"temperature": 1.0,
Expand Down Expand Up @@ -250,6 +251,7 @@
"max_num_batched_tokens": null,
"max_num_seqs": null,
"model": "Qwen/Qwen3-1.7B",
"seed": 43,
"tokenizer": "/models/tokenizer",
"trust_remote_code": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"return_routed_experts": false,
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": 42,
"temperature": 1.0,
"top_k": -1,
"top_p": 1.0,
Expand Down Expand Up @@ -137,7 +138,7 @@
"rollout_vllm_tpu_backend_type": "jax",
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": null,
"seed": 42,
"staging_max_bytes": null,
"store_routed_experts": false,
"temperature": 1.0,
Expand Down Expand Up @@ -225,6 +226,7 @@
"max_num_batched_tokens": null,
"max_num_seqs": null,
"model": "Qwen/Qwen3-1.7B",
"seed": 42,
"tensor_parallel_size": 4,
"tokenizer": "/models/tokenizer",
"trust_remote_code": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"return_routed_experts": false,
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": 42,
"temperature": 1.0,
"top_k": -1,
"top_p": 1.0,
Expand Down Expand Up @@ -150,7 +151,7 @@
"rollout_vllm_tpu_backend_type": "jax",
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": null,
"seed": 42,
"staging_max_bytes": null,
"store_routed_experts": false,
"temperature": 1.0,
Expand Down Expand Up @@ -305,6 +306,7 @@
"max_num_batched_tokens": null,
"max_num_seqs": null,
"model": "Qwen/Qwen3-1.7B",
"seed": 42,
"tokenizer": "/models/tokenizer",
"trust_remote_code": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"return_routed_experts": false,
"routed_experts_encode_mode": "auto",
"routed_experts_num_experts": null,
"seed": 42,
"temperature": 1.0,
"top_k": -1,
"top_p": 1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"return_routed_experts": true,
"routed_experts_encode_mode": "uint10",
"routed_experts_num_experts": 128,
"seed": 42,
"temperature": 1.0,
"top_k": -1,
"top_p": 1.0,
Expand Down Expand Up @@ -169,7 +170,7 @@
"rollout_vllm_tpu_backend_type": "jax",
"routed_experts_encode_mode": "uint10",
"routed_experts_num_experts": 128,
"seed": null,
"seed": 42,
"staging_max_bytes": null,
"store_routed_experts": false,
"temperature": 1.0,
Expand Down Expand Up @@ -286,6 +287,7 @@
"max_num_batched_tokens": null,
"max_num_seqs": null,
"model": "Qwen/Qwen3-1.7B",
"seed": 42,
"tensor_parallel_size": 2,
"tokenizer": "/models/tokenizer",
"trust_remote_code": true
Expand Down
5 changes: 4 additions & 1 deletion tunix/dist_rl/launch/common/base_dist_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ model_config: &base_model_config
# Not supported yet: the resolver rejects any value but null. LoRA always
# initializes with seed 0.
# TODO(noghabi): Seed the LoRA init (and the model init, once the trainer
# loads through `tunix.cli`'s `create_model`) and rollout sampling from it.
# loads through `tunix.cli`'s `create_model`) from it.
rng_seed: null
dtype: "float32"
load_dtype: "float32"
Expand Down Expand Up @@ -163,6 +163,9 @@ rollout_config:
temperature: 1.0
top_p: 1.0
top_k: -1
# Base random seed for the rollout sampler; offset by each rollout replica's
# index modulo 2**32. Null leaves the sampler seed unset.
seed: 42
# Comma-separated token ids or token strings that end a generation, e.g.
# "151645,151643" for Qwen3. When empty, generation stops on the tokenizer's
# EOS token only, and the rollout cannot tell a finished response from a
Expand Down
21 changes: 19 additions & 2 deletions tunix/dist_rl/launch/common/resolve_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@
f"{section}.rng_seed": (
None,
(
"LoRA always initializes with seed 0, and rollout sampling"
" is not seeded"
"LoRA always initializes with seed 0; use"
" rollout_config.seed for rollout sampling"
),
)
for section in _MODEL_SECTIONS
Expand Down Expand Up @@ -1475,6 +1475,7 @@ def _validate_dist_invariants(hp: cli_config.HyperParameters) -> None:
f" ({actor_axes['fsdp']}) when model_source='maxtext'."
)

_validate_rollout_seed(hp)
_validate_typed_vllm_settings(hp)

for role_key in (
Expand Down Expand Up @@ -1681,6 +1682,22 @@ def _validate_rollout_weights(hp: cli_config.HyperParameters) -> None:
)


def _validate_rollout_seed(hp: cli_config.HyperParameters) -> None:
"""Validates `rollout_config.seed` (non-negative `int` or `null`)."""
seed = hp.config_mapping("rollout_config")["seed"]
if seed is None:
return
if isinstance(seed, bool) or not isinstance(seed, int):
raise TypeError(
f"rollout_config.seed must be an int or null, got {seed!r}."
)
if seed < 0:
raise ValueError(
"rollout_config.seed must be non-negative (or null to leave unset),"
f" got {seed}."
)


def _validate_typed_vllm_settings(hp: cli_config.HyperParameters) -> None:
"""Validates the typed `vllm_config` rollout settings."""
vllm = hp.config_mapping("vllm_config")
Expand Down
Loading
Loading