Skip to content

[rl] refactor alphabet-sort configs into examples/alphabet_sort - #3684

Merged
yichuan-w merged 1 commit into
pytorch:mainfrom
yichuan-w:yichuan/refactor-alphabet-sort
Jun 16, 2026
Merged

yichuan-w merged 1 commit into
pytorch:mainfrom
yichuan-w:yichuan/refactor-alphabet-sort

Conversation

@yichuan-w

Copy link
Copy Markdown
Member

Follow-up to Tianyu's note in #3602 (comment).

config_registry.py had collected all the alphabet-sort smoke/debug configs — the 0.6b/1.7b/14b GRPO recipes, the two batch-invariant variants, and the BatchInvariantFlexConverter they share. That's example-specific code living in what's supposed to be a generic registry. search_r1 already keeps its configs under examples/search_r1/config.py and only re-imports them into config_registry so ConfigManager can find them via --config; this makes alphabet-sort do the same.

What changed:

  • new examples/alphabet_sort/config.py holds the six config functions plus the converter/debug helpers
  • config_registry.py is now just two re-import blocks (alphabet-sort + search_r1)
  • the direct importers (generate.py, test_generator.py, test_bitwise_parity.py) pull the functions from the example module instead of config_registry

--config on the CLI is unchanged: config_registry still re-exports the names, so getattr(config_registry, "rl_grpo_qwen3_0_6b_varlen") keeps working and the integration tests (tests/integration_tests.py) that pass --config strings don't need touching.

Pure move, no behavior change. Confirmed all six configs are still discoverable through config_registry and pre-commit is clean.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 16, 2026
@yichuan-w
yichuan-w marked this pull request as draft June 16, 2026 06:43
@yichuan-w
yichuan-w force-pushed the yichuan/refactor-alphabet-sort branch from 73d7006 to 521f299 Compare June 16, 2026 06:48
@yichuan-w yichuan-w changed the title [rl] refactor alphabet-sort and corresponding CI [rl] move alphabet-sort configs into examples/alphabet_sort Jun 16, 2026
@yichuan-w
yichuan-w force-pushed the yichuan/refactor-alphabet-sort branch from 521f299 to 99e8f4b Compare June 16, 2026 06:50
@yichuan-w
yichuan-w marked this pull request as ready for review June 16, 2026 06:51
@yichuan-w yichuan-w changed the title [rl] move alphabet-sort configs into examples/alphabet_sort [rl] refactor alphabet-sort configs into examples/alphabet_sort Jun 16, 2026
@yichuan-w
yichuan-w requested a review from felipemello1 June 16, 2026 07:53

@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.

looks good, lets just figure out where to put BatchInvariantFlexConverter

_BATCH_INVARIANT_DEBUG = DebugConfig(batch_invariant=True, deterministic=True)


class BatchInvariantFlexConverter(ModelConfigConverter):

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.

shouldnt this be shared by all configs?

from torchtitan.experiments.rl.generator_router import (
GeneratorRouter,
RoundRobinRoutingStrategy,
# Alphabet-sort example configs (the default GRPO smoke/debug recipe).

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.

Suggested change
# Alphabet-sort example configs (the default GRPO smoke/debug recipe).
# Alphabet-sort example configs

# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""Config entry points for the alphabet-sort example (the default GRPO recipe).

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.

Suggested change
"""Config entry points for the alphabet-sort example (the default GRPO recipe).
"""Config entry points for the alphabet-sort example

@yichuan-w
yichuan-w force-pushed the yichuan/refactor-alphabet-sort branch from 99e8f4b to af6da39 Compare June 16, 2026 18:12
@yichuan-w
yichuan-w requested a review from felipemello1 June 16, 2026 18:13

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.

@yichuan-w
yichuan-w force-pushed the yichuan/refactor-alphabet-sort branch from af6da39 to 8273ea8 Compare June 16, 2026 20:04
[
[
"--module rl",
"--module torchtitan.experiments.rl.examples.alphabet_sort",

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.

Thanks, LGTM now. I'll make a PR to improve our life on this later.

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.

actually I saw the CI error.

The plan I had:

  • Modify config/manager.py to search --module alphabet_sort in torchtitan/experiments/rl/examples as well.

Maybe you can do it in this PR if it's blocking. Ping me for another look.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah, lets leave that for next PR and I will fix the CI failure now first

Each example now owns its config_registry.py (matching search_r1), discovered via
--module torchtitan.experiments.rl.examples.<name>. Move the nine alphabet-sort
GRPO configs there and drop the central rl/config_registry.py aggregator;
integration tests, README and generate.py use the full --module path now.

Pull the batch-invariance helpers into rl/batch_invariance.py: the
BatchInvariantFlexConverter (was inline in config_registry) plus
patch_bmm_for_batch_invariance / force_logprobs_fn_for_batch_invariance (were in
actors/generator.py), so any config — not just alphabet-sort — can reuse them.
@yichuan-w
yichuan-w force-pushed the yichuan/refactor-alphabet-sort branch from 8273ea8 to e3d5a49 Compare June 16, 2026 21:04
@yichuan-w
yichuan-w merged commit 439e0ee into pytorch:main Jun 16, 2026
10 of 12 checks passed
yichuan-w added a commit that referenced this pull request Jun 17, 2026
Follow-up to #3684. Now that each RL example owns its `config_registry`
under `rl/examples/<name>`, running one meant typing the full `--module
torchtitan.experiments.rl.examples.alphabet_sort`. This lets
`ConfigManager` resolve the short name like it does for
models/experiments.

What changed:
- `config/manager.py`: when resolving a short `--module` name, also
search `torchtitan.experiments.rl.examples.<name>.config_registry`
(after `torchtitan.models` and `torchtitan.experiments`).
- `experiments/__init__.py`: register `alphabet_sort` and `search_r1` as
supported shorthands.
- Switch the integration tests, READMEs, `train`/example docs and
`loss_compare.py` back to the short names (e.g. `--module
alphabet_sort`).

So `--module alphabet_sort --config rl_grpo_qwen3_0_6b_varlen` now works
like `--module llama3`.

Verified locally:
- `--module llama3 --config llama3_debugmodel` still builds (no
regression).
- `--module alphabet_sort --config rl_grpo_qwen3_0_6b_varlen` and
`--module search_r1 --config rl_grpo_qwen3_1_7b_search_r1` resolve and
build.
- unknown short name still errors, now listing the rl-examples search
path.
- added a CPU unit test for the shorthand registration (full resolution
is exercised by the RL integration tests, which run `--module
alphabet_sort` and pull in vLLM).

cc @tianyu-l — this is the manager.py change you sketched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl ciflow/8gpu 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