Compare commits

...
Author SHA1 Message Date
a166a8b8df fix(orchestrator): trim glibc heap after each step to prevent RSS growth (#2527)
Release / Push CUDA image to Docker (push) Canceled after 0s
numpy/pandas allocate array data via malloc() (outside Python's allocator),
so gc.collect() alone doesn't reclaim RSS after per-step DataFrames are freed.
glibc retains freed pages in its internal pool, causing ~+6 MB/step monotonic
RssAnon growth on the orchestrator process.

malloc_trim(0) forces glibc to return freed heap pages to the OS, producing
a stable sawtooth pattern (peak during rollout generation, drops after trim)
with no upward trend.

Verified on alphabet-sort (512 rollouts/step, 20 steps, no wandb):
- Without fix: 941 MB → 973 MB by step 3 (+6 MB/step, unbounded)
- With fix:    941 MB → 942 MB by step 5 (flat, sawtooth only)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 15:57:34 -07:00
samsjaandGitHub 66ff00d117 make renderers default for rollouts (#2521)
Release / Push CUDA image to Docker (push) Canceled after 0s
2026-05-17 12:58:38 +02:00
ae610d9dd8 feat(renderer): expose preserve_*_thinking flags in RendererConfig (#2436)
Release / Push CUDA image to Docker (push) Canceled after 0s
* feat(renderer): expose preserve_*_thinking flags in RendererConfig

Adds two new fields to RendererConfig:
  - preserve_all_thinking
  - preserve_thinking_between_tool_calls

The orchestrator forwards them in two places so train and infer stay
consistent:

  1. create_renderer() — bound at construction on the training-side
     renderer used by build_trajectory_step / render_ids.
  2. setup_inference_pool() → setup_clients() → vf.ClientConfig — the
     verifiers RendererClient picks them up and forwards to its
     create_renderer_pool, so every inference render carries the same
     thinking-preservation behaviour.

Both flags are off by default → zero behaviour change for existing
configs. Setting either without orchestrator.use_renderer=True is
rejected by validate_renderer_args, matching the existing renderer
knobs.

Bumps source pins:
  - verifiers 3b77145 → a7516a1 (PR #1298: ClientConfig propagation)
  - renderers (now a separate repo): pinned to fe67f9f (PR #4:
    construction-time preserve flags)

Re-applies #2433, which was merged into feat/unify-inference-generate
by mistake.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(sft): forward preserve_*_thinking flags through SFT renderer path

The flags were added to the shared RendererConfig but only wired up
in the orchestrator. SFT also constructs a renderer via create_renderer
for training-side tokenization, so it must forward both flags or
silently ignore them.

Also tighten validate_renderer_args to reject either flag when
use_renderer=False, matching the orchestrator validator.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 17:38:53 -07:00
15 changed files with 160 additions and 21 deletions
@@ -16,6 +16,8 @@ language_model_attr = "model.language_model"
[orchestrator]
batch_size = 256
rollouts_per_example = 16
use_token_client = false
use_renderer = false
[orchestrator.train.sampling]
max_completion_tokens = 64
@@ -11,6 +11,8 @@ language_model_attr = "model.language_model"
[orchestrator]
batch_size = 256
rollouts_per_example = 16
use_token_client = false
use_renderer = false
[orchestrator.train.sampling]
@@ -12,6 +12,8 @@ language_model_attr = "model.language_model"
[orchestrator]
batch_size = 16
rollouts_per_example = 2
use_token_client = false
use_renderer = false
[orchestrator.train.sampling]
max_completion_tokens = 32
+2
View File
@@ -72,6 +72,8 @@ type = "sft"
[orchestrator]
use_token_client = false
use_renderer = false
use_sft_loss = true
[orchestrator.teacher_rollout_model.client]
base_url = ["https://your-openai-compatible-endpoint/v1"]
@@ -30,6 +30,7 @@ save_adapter_separately = true
batch_size = 256
rollouts_per_example = 4
use_token_client = false
use_renderer = false
use_sft_loss = true
[orchestrator.train.sampling]
@@ -1121,23 +1121,23 @@ class OrchestratorConfig(BaseConfig):
use_token_client: Annotated[
bool,
Field(
description="Whether to use the token-in-token-out (TITO) client for training across all environments. "
description="Whether to use the server-tokenized token-in-token-out (TITO) client for training across all environments. "
"WARNING: Only use this if your environment has a linear history and the chat template has the extension "
"property (i.e. no tokens are ever removed or inserted by the chat template). Mutually exclusive with "
"``use_renderer``."
),
] = True
] = False
use_renderer: Annotated[
bool,
Field(
description="Whether to use the renderer client (client-side tokenization via the ``renderers`` package, "
description="Whether to use the renderer-backed TITO client (client-side tokenization via the ``renderers`` package, "
"served by ``/v1/generate``). Mutually exclusive with ``use_token_client``. When True, the "
"``[orchestrator.renderer]`` block (name / tool_parser / reasoning_parser / pool_size) "
"applies; when False those fields must be left at their defaults. Not supported for VLMs — "
"VLMs must use the token client (TITO) so image preprocessing and chat templating stay server-side."
"``[orchestrator.renderer]`` block (name / tool_parser / reasoning_parser / pool_size) applies. "
"This is the default for text-only rollouts. Not supported for VLMs — VLMs must use MITO so "
"image preprocessing and chat templating stay server-side."
),
] = False
] = True
env_install_prerelease: Annotated[
bool,
@@ -1223,18 +1223,18 @@ class OrchestratorConfig(BaseConfig):
def validate_client_mode(self):
"""The two client toggles select among three exclusive modes:
- ``use_token_client=True`` + ``use_renderer=False`` → TITO (default)
- ``use_token_client=False`` + ``use_renderer=True`` → renderer
- ``use_token_client=False`` + ``use_renderer=True`` → renderer-backed TITO (default)
- ``use_token_client=True`` + ``use_renderer=False`` → server-tokenized TITO
- ``use_token_client=False`` + ``use_renderer=False`` → MITO
Both True is invalid: TITO and renderer are different wire protocols
(server-side templating vs client-side tokenization).
Both True is invalid: renderer-backed TITO and server-tokenized TITO are
different wire protocols (client-side vs server-side tokenization).
"""
if self.use_token_client and self.use_renderer:
raise ValueError(
"orchestrator.use_token_client and orchestrator.use_renderer are mutually exclusive. "
"Pick one: token client (TITO, server-side templating) or renderer client (client-side "
"tokenization)."
"Pick one TITO path: renderer client (client-side tokenization) or token client "
"(server-side tokenization)."
)
return self
@@ -1242,12 +1242,12 @@ class OrchestratorConfig(BaseConfig):
def validate_renderer_vs_vlm(self):
"""The renderer client takes plain message dicts and tokenizes
them client-side. VLMs need server-side image preprocessing and
chat templating, so they must use the token client (TITO) — fail
chat templating, so they must use MITO — fail
loudly when both are set."""
if self.use_renderer and self.model.vlm is not None:
raise ValueError(
"orchestrator.use_renderer is not supported for VLMs. Use the token client "
"(``use_token_client=true``, the default) so image preprocessing and chat "
"orchestrator.use_renderer is not supported for VLMs. Use MITO "
"(``use_token_client=false`` and ``use_renderer=false``) so image preprocessing and chat "
"templating stay on the inference server."
)
return self
@@ -1269,6 +1269,12 @@ class OrchestratorConfig(BaseConfig):
renderer_args_set.append(f"renderer.reasoning_parser={self.renderer.reasoning_parser!r}")
if self.renderer.pool_size is not None:
renderer_args_set.append(f"renderer.pool_size={self.renderer.pool_size!r}")
if self.renderer.preserve_all_thinking:
renderer_args_set.append(f"renderer.preserve_all_thinking={self.renderer.preserve_all_thinking!r}")
if self.renderer.preserve_thinking_between_tool_calls:
renderer_args_set.append(
f"renderer.preserve_thinking_between_tool_calls={self.renderer.preserve_thinking_between_tool_calls!r}"
)
if renderer_args_set:
raise ValueError(
@@ -414,6 +414,12 @@ class SFTConfig(BaseConfig):
renderer_args_set.append(f"renderer.tool_parser={self.renderer.tool_parser!r}")
if self.renderer.reasoning_parser is not None:
renderer_args_set.append(f"renderer.reasoning_parser={self.renderer.reasoning_parser!r}")
if self.renderer.preserve_all_thinking:
renderer_args_set.append(f"renderer.preserve_all_thinking={self.renderer.preserve_all_thinking!r}")
if self.renderer.preserve_thinking_between_tool_calls:
renderer_args_set.append(
f"renderer.preserve_thinking_between_tool_calls={self.renderer.preserve_thinking_between_tool_calls!r}"
)
if renderer_args_set:
raise ValueError(
@@ -135,7 +135,7 @@ class BaseModelConfig(BaseConfig):
class RendererConfig(BaseConfig):
"""Configures the client-side renderer (chat-template + response parsing).
Only consumed when ``orchestrator.use_renderer = true``. The renderer
Consumed when ``use_renderer = true``. The renderer
owns both directions: render messages → token ids on the client, and
parse model output tokens → structured ``content`` / ``reasoning_content``
/ ``tool_calls``.
@@ -186,6 +186,37 @@ class RendererConfig(BaseConfig):
),
] = None
preserve_all_thinking: Annotated[
bool,
Field(
description=(
"Override flag forwarded to the renderer at construction. When "
"True, every past-assistant turn's ``reasoning_content`` is "
"re-emitted between ``<think>``/``</think>`` (or the model's "
"equivalent), even if the underlying chat template would drop "
"it. Off by default — preserves byte-identical output to the "
"stock template. Strict superset of "
"``preserve_thinking_between_tool_calls``."
),
),
] = False
preserve_thinking_between_tool_calls: Annotated[
bool,
Field(
description=(
"Override flag forwarded to the renderer at construction. When "
"True, preserves past-assistant ``reasoning_content`` only "
"inside the *current* tool cycle — the contiguous "
"assistant→tool→…→assistant block after the most recent user "
"message, when that block contains at least one tool response. "
"A new user turn closes the block; older blocks fall back to "
"the template default (typically dropped). Use "
"``preserve_all_thinking`` to keep older blocks too."
),
),
] = False
class ElasticConfig(BaseConfig):
"""Configures elastic inference pool with DNS-based service discovery.
+4
View File
@@ -157,6 +157,10 @@ If you wish to configure values of the default variant, you don't need to set th
For hosted multi-tenant runs where the trainer image's `trainer.loss.type` is fixed, the orchestrator exposes a per-run override that forces SFT loss on every micro-batch without rebuilding the trainer. Set `orchestrator.use_sft_loss = true` alongside `orchestrator.teacher_rollout_model`; both must be configured together (the orchestrator validator enforces this). The orchestrator stamps each `TrainingSample.sft_loss = True`, which the trainer's `compute_loss` honors by dispatching to `sft_loss_fn` per batch — independent of the trainer's configured default loss.
### RL rollout client defaults
For text-only RL rollouts, the orchestrator defaults to renderer-backed TITO (`use_renderer = true`, `use_token_client = false`). VLM configs must explicitly use MITO (`use_token_client = false`, `use_renderer = false`) so image preprocessing and chat templating stay server-side. External teacher rollouts must also set `use_renderer = false`.
### Model fields
For `BaseModel | None` fields (like `[ckpt]`, `[wandb]`, `[compile]`), a bare flag enables them with defaults:
+17 -4
View File
@@ -1,4 +1,5 @@
import asyncio
import ctypes
import gc
import os
import time
@@ -797,6 +798,13 @@ async def orchestrate(config: OrchestratorConfig):
del train_rollouts, train_examples, training_batch, vlm_cache
del results_df, metrics_df
gc.collect()
# Return free glibc heap pages to the OS. numpy/pandas allocate array data
# via malloc (outside Python's allocator), so gc.collect() alone doesn't
# reclaim the RSS. malloc_trim(0) forces glibc to return freed pages.
try:
ctypes.CDLL("libc.so.6").malloc_trim(0)
except Exception as e:
logger.warning(f"malloc_trim(0) failed - RSS may grow unboundedly: {e}")
event_loop_lag_monitor.reset()
@@ -903,12 +911,13 @@ async def setup_rollout_inference_pool(
- external teacher rollout → MITO (``openai_chat_completions``),
forced regardless of the toggles (config-level validator
rejects ``use_token_client`` / ``use_renderer`` in that case)
- ``use_renderer=True`` → renderer client (``/v1/generate``).
- ``use_renderer=True`` → renderer-backed TITO client (``/v1/generate``).
Default for text-only rollouts.
Not allowed for VLMs (validated at config time).
- ``use_token_client=True`` → TITO
- ``use_token_client=True`` → server-tokenized TITO
(``openai_chat_completions_token``, ``/v1/chat/completions/tokens``).
Default. VLMs land here too.
- both False → MITO (``openai_chat_completions``).
VLMs land here too.
"""
if config.teacher_rollout_model is not None:
logger.info("Using external rollout model (MITO) without renderer client")
@@ -926,6 +935,8 @@ async def setup_rollout_inference_pool(
renderer=config.renderer.name,
tool_parser=config.renderer.tool_parser,
reasoning_parser=config.renderer.reasoning_parser,
preserve_all_thinking=config.renderer.preserve_all_thinking,
preserve_thinking_between_tool_calls=config.renderer.preserve_thinking_between_tool_calls,
)
logger.info(f"Initialized {type(renderer).__name__} for {config.model.name}")
inference_pool = await setup_inference_pool(
@@ -937,13 +948,15 @@ async def setup_rollout_inference_pool(
tool_parser=config.renderer.tool_parser,
reasoning_parser=config.renderer.reasoning_parser,
renderer_pool_size=config.renderer.pool_size,
preserve_all_thinking=config.renderer.preserve_all_thinking,
preserve_thinking_between_tool_calls=config.renderer.preserve_thinking_between_tool_calls,
)
logger.info("Using direct renderer rollout client")
return renderer, inference_pool
train_client_type = "openai_chat_completions_token" if config.use_token_client else "openai_chat_completions"
if config.use_token_client:
logger.info("Using token client (TITO) for rollouts — server-side templating, /v1/chat/completions/tokens")
logger.info("Using server-tokenized TITO for rollouts — /v1/chat/completions/tokens")
else:
logger.info("Using MITO (openai_chat_completions) for rollouts")
inference_pool = await setup_inference_pool(
+2
View File
@@ -166,6 +166,8 @@ def train(config: SFTConfig):
renderer=config.renderer.name,
tool_parser=config.renderer.tool_parser,
reasoning_parser=config.renderer.reasoning_parser,
preserve_all_thinking=config.renderer.preserve_all_thinking,
preserve_thinking_between_tool_calls=config.renderer.preserve_thinking_between_tool_calls,
)
if isinstance(renderer, DefaultRenderer):
raise ValueError(
+22
View File
@@ -68,6 +68,8 @@ class StaticInferencePool:
tool_parser: str | None = None,
reasoning_parser: str | None = None,
renderer_pool_size: int | None = None,
preserve_all_thinking: bool = False,
preserve_thinking_between_tool_calls: bool = False,
):
renderer_model_name = model_name if train_client_type == "renderer" else None
self._train_clients = setup_clients(
@@ -78,6 +80,8 @@ class StaticInferencePool:
tool_parser=tool_parser,
reasoning_parser=reasoning_parser,
renderer_pool_size=renderer_pool_size,
preserve_all_thinking=preserve_all_thinking,
preserve_thinking_between_tool_calls=preserve_thinking_between_tool_calls,
)
self._eval_clients = setup_clients(client_config, client_type=eval_client_type)
self._admin_clients = setup_admin_clients(client_config)
@@ -129,6 +133,8 @@ async def setup_inference_pool(
tool_parser: str | None = None,
reasoning_parser: str | None = None,
renderer_pool_size: int | None = None,
preserve_all_thinking: bool = False,
preserve_thinking_between_tool_calls: bool = False,
) -> InferencePool:
"""Create an inference pool from config (static or elastic)."""
logger = get_logger()
@@ -152,6 +158,8 @@ async def setup_inference_pool(
tool_parser=tool_parser,
reasoning_parser=reasoning_parser,
renderer_pool_size=renderer_pool_size,
preserve_all_thinking=preserve_all_thinking,
preserve_thinking_between_tool_calls=preserve_thinking_between_tool_calls,
)
logger.info(
@@ -168,6 +176,8 @@ async def setup_inference_pool(
tool_parser=tool_parser,
reasoning_parser=reasoning_parser,
renderer_pool_size=renderer_pool_size,
preserve_all_thinking=preserve_all_thinking,
preserve_thinking_between_tool_calls=preserve_thinking_between_tool_calls,
)
@@ -179,9 +189,20 @@ def setup_clients(
tool_parser: str | None = None,
reasoning_parser: str | None = None,
renderer_pool_size: int | None = None,
preserve_all_thinking: bool = False,
preserve_thinking_between_tool_calls: bool = False,
) -> list[vf.ClientConfig]:
clients = []
client_idx = 0
# Only forward preserve flags when the client actually uses a renderer —
# MITO/TITO clients ignore them and the verifiers ClientConfig may reject
# unknown extras on older versions.
renderer_extra: dict = {}
if client_type == "renderer":
renderer_extra = {
"preserve_all_thinking": preserve_all_thinking,
"preserve_thinking_between_tool_calls": preserve_thinking_between_tool_calls,
}
for base_url in client_config.base_url:
for dp_rank in range(client_config.dp_rank_count):
headers = client_config.headers.copy()
@@ -205,6 +226,7 @@ def setup_clients(
max_retries=10,
extra_headers=headers,
extra_headers_from_state=client_config.extra_headers_from_state,
**renderer_extra,
)
)
client_idx += 1
+10
View File
@@ -110,6 +110,8 @@ class ElasticInferencePool:
tool_parser: str | None = None,
reasoning_parser: str | None = None,
renderer_pool_size: int | None = None,
preserve_all_thinking: bool = False,
preserve_thinking_between_tool_calls: bool = False,
):
self.logger = get_logger()
self.client_config = client_config
@@ -125,6 +127,8 @@ class ElasticInferencePool:
self.tool_parser = tool_parser
self.reasoning_parser = reasoning_parser
self.renderer_pool_size = renderer_pool_size
self.preserve_all_thinking = preserve_all_thinking
self.preserve_thinking_between_tool_calls = preserve_thinking_between_tool_calls
self.router_url = client_config.router_url
self._servers: dict[str, ServerState] = {}
@@ -152,6 +156,8 @@ class ElasticInferencePool:
tool_parser: str | None = None,
reasoning_parser: str | None = None,
renderer_pool_size: int | None = None,
preserve_all_thinking: bool = False,
preserve_thinking_between_tool_calls: bool = False,
) -> ElasticInferencePool:
if client_config.elastic is None:
raise ValueError("Elastic inference pool requires elastic config")
@@ -164,6 +170,8 @@ class ElasticInferencePool:
tool_parser=tool_parser,
reasoning_parser=reasoning_parser,
renderer_pool_size=renderer_pool_size,
preserve_all_thinking=preserve_all_thinking,
preserve_thinking_between_tool_calls=preserve_thinking_between_tool_calls,
)
await pool.start()
return pool
@@ -214,6 +222,8 @@ class ElasticInferencePool:
tool_parser=self.tool_parser,
reasoning_parser=self.reasoning_parser,
renderer_pool_size=self.renderer_pool_size,
preserve_all_thinking=self.preserve_all_thinking,
preserve_thinking_between_tool_calls=self.preserve_thinking_between_tool_calls,
)
if urls
else []
@@ -50,6 +50,8 @@ def test_setup_rollout_inference_pool_uses_direct_renderer_client_for_local_vllm
tool_parser=None,
reasoning_parser=None,
pool_size=None,
preserve_all_thinking=False,
preserve_thinking_between_tool_calls=False,
),
)
rollout_client_config = SimpleNamespace(base_url=["http://localhost:8000/v1"])
@@ -79,6 +81,8 @@ def test_setup_rollout_inference_pool_uses_direct_renderer_client_for_local_vllm
renderer="qwen3_vl",
tool_parser=None,
reasoning_parser=None,
preserve_all_thinking=False,
preserve_thinking_between_tool_calls=False,
)
setup_pool_mock.assert_awaited_once_with(
rollout_client_config,
@@ -89,6 +93,8 @@ def test_setup_rollout_inference_pool_uses_direct_renderer_client_for_local_vllm
tool_parser=None,
reasoning_parser=None,
renderer_pool_size=None,
preserve_all_thinking=False,
preserve_thinking_between_tool_calls=False,
)
asyncio.run(run())
+30
View File
@@ -157,6 +157,36 @@ def test_removed_fused_lm_head_chunk_size_field_is_rejected():
TrainerModelConfig.model_validate({"fused_lm_head_chunk_size": "auto"})
def test_orchestrator_vlm_configs_must_disable_renderer():
with pytest.raises(ValidationError, match="orchestrator.use_renderer is not supported for VLMs"):
OrchestratorConfig.model_validate(
{
"model": {
"vlm": {
"vision_encoder_attr": "model.visual",
"language_model_attr": "model.language_model",
}
}
}
)
config = OrchestratorConfig.model_validate(
{
"model": {
"vlm": {
"vision_encoder_attr": "model.visual",
"language_model_attr": "model.language_model",
}
},
"use_token_client": False,
"use_renderer": False,
}
)
assert config.use_token_client is False
assert config.use_renderer is False
def test_selective_activation_checkpointing_requires_custom_impl():
with pytest.raises(ValidationError, match="Selective activation checkpointing requires model.impl='custom'"):
TrainerModelConfig.model_validate({"impl": "hf", "ac": {"mode": "selective"}})