fix(cookbooks): normalize LaTeX and markdown formatting in Fireworks … - #659
Open
shobhitagnihotri69 wants to merge 1 commit into
Open
shobhitagnihotri69 wants to merge 1 commit into
shobhitagnihotri69 wants to merge 1 commit into
Conversation
…arithmetic grader
LLMs frequently format final integer answers with LaTeX boxing (\boxed{...}, $\boxed{...}$) or markdown bold/code tags on the final line.
Previously, re.fullmatch rejected this formatting, causing correct model rollouts to receive reward 0.0 and corrupting RL training signals.
This unwraps \boxed{...} and strips markdown/LaTeX delimiters from the final answer line, updates the test expectations, adds tests for formatted answers, and syncs the cookbook documentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The arithmetic task in
cookbooks/fireworks-rl-trainingchecks the final integer on the last non-empty line. However, reasoning models (such as Qwen 2.5 and DeepSeek-R1) standardly format their final answers wrapped in LaTeX boxing (\boxed{...},$\boxed{...}$), markdown bold (**...**), or inline code tags.Previously,
re.fullmatch(r"[+-]?(?:\d+|\d{1,3}(?:,\d{3})+)", final)on the final line rejected these common wrappers, assigningreward = 0.0to mathematically correct rollouts and corrupting the RL training reward signal.Changes
\boxed{...}and strips enclosing markdown/LaTeX delimiters ($,*,`,.) from the final answer line prior to integer matching.1.0for\boxed{...}and adds test coverage for$\boxed{...}$,**...**, and`...`intest_train.py.docs/v6/cookbooks/fireworks-rl-training.mdx.Verification
uv run pytest test_train.py -k test_grades_integer_on_last_nonempty_line(22 passed, 100%).ruff checkandruff format.Note
Low Risk
Cookbook-only grader and test/doc updates; no auth, infra, or broader SDK behavior changes.
Overview
The Fireworks RL cookbook’s
grade_final_integergrader now normalizes common answer wrappers on the last line before parsing the integer, so correct math isn’t scored as wrong when models use typical reasoning-model formatting.After taking the last non-empty line, it unwraps
\boxed{...}and strips enclosing$,*, backticks, whitespace, and trailing periods, then applies the existing comma-aware integer regex. Tests now expect full reward for\boxed{...},$\boxed{...}$,**...**, and`...`answers. The v6 cookbook doc snippet matchesenv.py.Reviewed by Cursor Bugbot for commit 3bce83c. Bugbot is set up for automated code reviews on this repo. Configure here.