Skip to content

Update the Sudoku example to start from an SFT model with a progress reward - #8097

Merged
sergiopaniego merged 8 commits into
mainfrom
update-sudoku-example
Nov 5, 2026
Merged

sergiopaniego merged 8 commits into
mainfrom
update-sudoku-example

Conversation

@sergiopaniego

@sergiopaniego sergiopaniego commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Updates the Sudoku example to the pattern of the Wordle one (#7932): it starts from an SFT model (openenv/Qwen3-1.7B-Sudoku-SFT) and trains with two reward terms, 1 for a solved puzzle plus the fraction of empty cells filled.

  • examples/grpo_sudoku/grpo_sudoku.py: rewritten around environment_factory and a place(row, col, number) tool, about 200 lines. sudoku_prompt.txt is gone, since the prompt now fits in the script.
  • examples/grpo_sudoku/grpo_sudoku.ipynb: rebuilt from the Wordle notebook.
  • examples/grpo_sudoku/README.md: the example told as a story, like Rewrite the gpt-oss example: fine-tune on chess puzzles, then back to MXFP4 #8085: what the base model does, the SFT warmup (linking the OpenEnv tutorial for it), GRPO against the environment with the Space setup and the training curve, and the results with the GIF. The grpo_sudoku row in the examples index says the same in one line.
  • docs/source/openenv.md: the rewards tip now says to make sure the games in a group differ, and a new "Long runs against a Space" section covers WebSocket drops in multi-hour runs.

On the same 30 puzzles with 26 empty cells, the SFT model solves 10 and SFT + GRPO (75 steps) solves 22. The full pipeline is in the OpenEnv tutorial: https://huggingface.co/docs/openenv/tutorials/sudoku-grpo


Note

Low Risk
Changes are limited to example scripts, notebooks, and documentation; no TRL trainer or library behavior is modified.

Overview
The grpo_sudoku example is reworked to match the Wordle/OpenEnv pattern: training starts from openenv/Qwen3-1.7B-Sudoku-SFT instead of the base model, with two GRPO rewards (1.0 if solved + fraction of empty cells filled) replacing the previous five shaped reward terms and heavy in-env hint/board parsing.

grpo_sudoku.py and the notebook shrink to a slim SudokuEnv (TextArena via --env-url, reset() reconnects per game for Space WebSocket drops), a short inline prompt, and tuned GRPOConfig (thinking on, 16 generations, long max_completion_length, token_truncate IS). sudoku_prompt.txt is removed.

A new README.md documents baseline → SFT → GRPO results (e.g. 10/30 → 22/30 puzzles at 26 empty cells). example_overview.md and openenv.md are updated with richer Sudoku blurb, reward-group guidance, and a “Long runs against a Space” section.

Reviewed by Cursor Bugbot for commit 9d3809a. Bugbot is set up for automated code reviews on this repo. Configure here.

@bot-ci-comment

bot-ci-comment Bot commented Nov 3, 2026

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@albertvillanova albertvillanova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this reads well and the script stays aligned with the Wordle example. A few nits:

  • docs/source/openenv.md: no OpenEnv release raises SessionLostError yet. It's only on OpenEnv main (openenv/OpenEnv@22ca1ab2), and v0.11.0 still reconnects silently. Could you say "the next OpenEnv release" or "OpenEnv main" instead of "newer clients"?
  • docs/source/openenv.md: the new "Long runs against a Space" section recommends a new client per episode, but grpo_wordle.py doesn't do this, and its run (~2h15) is longer than the ~2h drop interval. Should Wordle get the same reset() change in a follow-up PR?
  • The notebook says a game "reaches about 13k tokens", and the script comment says "games reach 16k tokens". Please use one number.
  • The notebook config has save_total_limit=1 (like the Wordle notebook), but the script doesn't. Intended?
  • README §4: puzzles_c55.json isn't linked, so readers can't find it. Please link it in the OpenEnv repo.
  • Notebook inference uses max_new_tokens=384 with enable_thinking=True (Wordle uses 512). If the thinking is cut off, play_sudoku stops at the first missing tool call. Is 384 enough?

@sergiopaniego

Copy link
Copy Markdown
Member Author

Thanks! All addressed in 7d5a0d1: "the next OpenEnv release" for SessionLostError, 16k tokens in both places, save_total_limit=1 in the script, puzzles_c55.json linked, and 512 new tokens in the notebook. Wordle reset(): agreed, I'll do it in a follow-up PR.

@albertvillanova albertvillanova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, all addressed. I checked the .sync() change: a plain client's close() doesn't stop its background loop thread (one thread leaked per episode with a new client per game), so .sync() is needed here, and in the Wordle follow-up too.

Optional nit: a one-line comment in reset() pointing to https://huggingface.co/docs/trl/openenv#long-runs-against-a-space would explain why the client is replaced each game.

@sergiopaniego
sergiopaniego merged commit 5f31bcf into main Nov 5, 2026
12 checks passed
@sergiopaniego
sergiopaniego deleted the update-sudoku-example branch November 5, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants