Skip to content

[rl] Add optional Verifiers rollout integration - #4356

Merged
wwwjn merged 20 commits into
mainfrom
verifiers-dapo-math
Sep 9, 2026
Merged

wwwjn merged 20 commits into
mainfrom
verifiers-dapo-math

Conversation

@wwwjn

@wwwjn wwwjn commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a verifiers example that reuses the DAPO Math dataset and training setup while delegating episode execution and reward calculation to Verifiers.
  • Keep all Verifiers-specific adapters inside the example so other TorchTitan recipes do not import or require verifiers.
  • Use the Verifiers null harness with a local subprocess runtime. No Docker or remote sandbox is required, and no tools are exposed to the model.
  • Leave the original dapo_math implementation unchanged as the native comparison path.

The example can be launched with:

python -m torchtitan.experiments.rl.train \
  --module verifiers \
  --config rl_dapo_qwen3_4b_verifiers_8k

100-step comparison

Both runs loaded Qwen3-4B-Base from the same HF checkpoint on four H100 GPUs and used identical overrides:

  • 100 optimizer steps
  • 2 generator GPUs and a TP=2 trainer
  • 4 prompts per step and 8 samples per prompt (32 training samples per step)
  • maximum completion length 2048 and maximum total length 10240
  • validation disabled
  • zero-standard-deviation reward groups retained
  • checkpoint load-only mode
  • W&B online logging enabled

The table reports the mean across all 100 W&B training steps unless otherwise noted.

Metric Native dapo_math verifiers Verifiers delta
Mean training reward 0.1878 0.1978 +0.0100
Mean truncation rate 7.53% 6.47% -1.06 pp
Mean response length 841.7 tokens 834.2 tokens -0.9%
Mean loss -0.00141 -0.00111 +0.00030
Mean step time 7.118 s 7.101 s -0.2%
Full-step throughput 4464.0 tokens/s 4562.7 tokens/s +2.2%
Forward/backward throughput 8722.0 tokens/s 8473.0 tokens/s -2.9%
Mean decode latency 13445.3 ms 13878.5 ms +3.2%
W&B total runtime 922.5 s 986.6 s +6.9%

The 2 DAPO math run shows similar reward and rollout:
Screenshot 2026-09-01 at 8 59 06 PM

Screenshot 2026-09-01 at 8 56 28 PM

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 27, 2026
@wwwjn
wwwjn requested a review from felipemello1 August 28, 2026 18:20

@dataclass(kw_only=True, slots=True)
class Config(VerifiersRollouter.Config):
train_dataset: VerifiersTaskDataset.Config = field(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dataset is defined through verifiers

@wwwjn
wwwjn force-pushed the verifiers-dapo-math branch from 762930e to 36c417d Compare August 31, 2026 23:51
Comment thread pyproject.toml Outdated
include = ["torchtitan*", "torchtitan_recipes*"]

[tool.setuptools.package-data]
"torchtitan.experiments.rl.examples.verifiers" = ["verifiers_env.toml"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because when release, python packaging includes .py files automatically, but not .toml files. This will not make verifiers a hard dependency

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe i am wrong, but this doesn't smell right. I will take a look at the .toml, but i wonder if theres a more elegant solution. If this is the only way, we should add a comment here on why we need it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toml is consumed by Verifiers. The alternative is to translated into torchtitan VerifiersRollouter.Configs but the Verifiers has so many config fields which I just leave verifiers' config system as is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wwwjn
wwwjn marked this pull request as ready for review September 1, 2026 16:18
@wwwjn
wwwjn requested a review from pzhan9 September 1, 2026 16:18
@felipemello1

felipemello1 commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

not a review, just a general comment: Its unclear to me what the examples/verifiers/... contains. Examples should be something like DAPO_math, search_r1, etc.

But it seems that you also need a components. Is this general for every verifier-based example? If so, maybe lets put it /src?

If this example is about verifiers_dapo_math, lets make it explicit in the folder. Later on we might have verifiers_swebench, for example. Another option could be to have verifiers/dapo_math and verifiers/swe_bench.

Also, it might be worth checking how other libraries integrate with verifiers. Example: https://github.com/thinking-machines-lab/tinker-cookbook/tree/main/tinker_cookbook/recipes/verifiers_rl

@wwwjn

wwwjn commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

not a review, just a general comment: Its unclear to me what the examples/verifiers/... contains. Examples should be something like DAPO_math, search_r1, etc.

But it seems that you also need a components. Is this general for every verifier-based example? If so, maybe lets put it /src?

examples/verifiers/componets is general for every verifier-based example. My original goal is to make this folder a stand-alone example of "titanRL + Verifiers". We only have one Verifiers examples now but I would want this design is easy for user who have their own sandbox account (eg, prime sandbox) to extend this example for agentic training, by reusing everything under examples/verifiers/componets.

If this example is about verifiers_dapo_math, lets make it explicit in the folder. Later on we might have verifiers_swebench, for example. Another option could be to have verifiers/dapo_math and verifiers/swe_bench.

verifiers/swe_bench sounds better. What about examples/verifiers/swe_bench, examples/verifiers/components, like what tinker did -- Put verifiers as a self-contained folder / recipe

Also, it might be worth checking how other libraries integrate with verifiers. Example: https://github.com/thinking-machines-lab/tinker-cookbook/tree/main/tinker_cookbook/recipes/verifiers_rl

In terms of folder organization, we are very similar. In-terms of integration point, I will take more look into details!

@felipemello1 felipemello1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review. I will finish it later.

Comment thread torchtitan/experiments/rl/README.md Outdated
Note: Unified-model performance varies by model, input shape, and parallelism: it can trail native vLLM in inference-only workloads but outperform it end to end in some RL configurations. Batch invariance trades throughput for exact numerics and can be used for debugging or controlled on-policy studies.

[Architecture](#architecture) · [Write an experiment](#write-an-experiment) · [DAPO Math](./examples/dapo_math) · [Observability](#observability) · [Quick Start](#quick-start)
[Architecture](#architecture) · [Write an experiment](#write-an-experiment) · [DAPO Math](./examples/dapo_math) · [Verifiers](./examples/verifiers) · [Observability](#observability) · [Quick Start](#quick-start)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you proposing that we delete dapo_math based on our Rollouter and keep only the verifiers-based one? I am not sure i 100% agree with it. What were your thoughts when you decided that?

@wwwjn wwwjn Sep 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I want to keep both. Verifiers examples is trying to not emphasis on DAPO math , but just as an example for verifiers. The DAPO-math is the official support we have, which is a stand-alone task we used for stress-testing our RL and verifiers-free.

Comment thread torchtitan/experiments/rl/renderer.py Outdated
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(tokenizer_path)
return create_renderer(tokenizer, self.as_renderers_config())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you have to change it? Also, apparently there are some issues renderers. I am working on it, then lets rebase #4365

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, let me rebase later

Comment thread pyproject.toml Outdated
include = ["torchtitan*", "torchtitan_recipes*"]

[tool.setuptools.package-data]
"torchtitan.experiments.rl.examples.verifiers" = ["verifiers_env.toml"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe i am wrong, but this doesn't smell right. I will take a look at the .toml, but i wonder if theres a more elegant solution. If this is the only way, we should add a comment here on why we need it.

Comment thread torchtitan/experiments/__init__.py Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the math-verify is specific to DAPO math. Lets make sure to distinguish it.

Comment on lines +66 to +67
# Unused because this class replaces the base rollout-worker execution path.
worker: RolloutWorker.Config | None = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets make this clearer. Also, i think that in Torchtitan, the standard is to have:

arg1: Blablabla
"""description arg1"""

is this true?

Comment on lines +71 to +75
rubric: Rubric.Config
# Converts sibling rollout rewards into training advantages.
advantage: Configurable.Config = field(
default_factory=AdvantageEstimator.Config
)

@felipemello1 felipemello1 Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would we need it if we are already inheriting it from Rollouter.Config?

Comment on lines +93 to +96
def pop_generation_metadata(self, session_id: str) -> list[GenerationMetadata]:
"""Remove and return generation metadata recorded for one rollout."""
self.turn_counts.pop(session_id, None)
return self.generation_metadata.pop(session_id, [])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it sounds like this should live in trace_to_rollout_turns

os.environ["NO_PROXY"] = no_proxy

with open(config_path, "rb") as file:
data = tomllib.load(file)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re https://github.com/pytorch/torchtitan/pull/4356/changes#r3906031494

I don't think verifiers is consuming toml, it's consuming this dictionary / dataclass.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I checked verifiers they used toml as their config examples, but consumes a dictionary and translate into a config dataclass. I'm originally lean toward toml to let user use the same toml config directly from verifiers.

The alternative is to import Verifiers 's config dataclass, and baked into our components class. This should also be easy to achieved by users if they need to depend on more config dataclass from verifiers. The PR is updated

Comment thread pyproject.toml Outdated
include = ["torchtitan*", "torchtitan_recipes*"]

[tool.setuptools.package-data]
"torchtitan.experiments.rl.examples.verifiers" = ["verifiers_env.toml"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe should be in its own folder

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sg, I'm moving it to examples/verifiers/dapo_math

dataset: Literal["dapo_math", "aime2025"] = "dapo_math"


class VerifiersMathTaskset(vf.Taskset[VerifiersMathTask, VerifiersMathTasksetConfig]):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Becuase Verifiers doesn't have an existing DAPO-math dataset, so this is needed to bridge our dataset to be verifier's taskset. I think this is also useful for other tasks and serves as an example for user who brings their own dataset


"""Register TorchTitan's DAPO-Math and AIME datasets with Verifiers.

Verifiers 0.3.0 does not provide a v1 taskset for these datasets. This module

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the relationship of 0.3.0 vs. v1? Shouldn't we use the latest verifiers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.3.0 is their release number, the latest is 0.3.1 which is just release.

v1 vs v0 is their versioning of the their core source code (like vllm V1 engine), v1 is a rewrite version and v0 is the legacy version

@wwwjn
wwwjn force-pushed the verifiers-dapo-math branch from b315a41 to 07a24ec Compare September 4, 2026 01:33
Comment thread torchtitan/experiments/rl/renderer.py Resolved

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Please address remaining comments, including the ones I left in last round of review, e.g. making naming consistent (like data.py)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't see the size of the img, but please make sure it's not too big e.g. > 1MB

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's ~13kb

@felipemello1 felipemello1 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, thank you so much for this PR! Its not easy to add integrations.

I am leaving a lot of comments, sorry. However, there are very few things i would consider a hard blocker. Please, use your own judgment to prioritize. Feel free to leave TODOs. You don't have to act on every comment.

If i had to summarize: I know TitanRL pretty well, and when reading this integration, i got a bit lost/overwhelmed, because now i need to know: TitanRL + verifiers + verifiers/components + verifiers/dapo_math.

This scares me a bit.

I think that can/should simplify some parts/knobs and make some parts more explicit/obvious. Using the skill I shared to add a few comments in long functions + examples in docstrings can go a long way.

Again: please don't treat every comment as a must-fix

Comment thread torchtitan/experiments/rl/renderer.py Resolved
return RolloutStatus.TRUNCATED_LENGTH

@staticmethod
def trace_to_rollout_turns(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please ask Sol to compare the logged rollout of dapo_math of verifiers vs titanRL, just as a sanity check? i.e. inspect the rollout structure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in terms of statistics:

  • Both 100-step H100 runs completed:
Screenshot 2026-09-09 at 2 20 52 PM

Rollout check:

  • Same top-level and turn schemas.
  • All 402 shared groups had identical prompt_token_ids.
  • All rollouts were single-turn.
  • Completion token/log-prob lengths matched.
  • No rollout errors.
  • Truncation status matched the 2,048-token limit.
  • Verifiers rewards propagated correctly through env_rewards.verifiers_reward.

And I checked some generation examples, both seems coherent and reasonable

@wwwjn
wwwjn force-pushed the verifiers-dapo-math branch from ecc037c to 3407a0c Compare September 9, 2026 06:21
@wwwjn
wwwjn merged commit dd2e469 into main Sep 9, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants