Skip to content

GPTOSS openmathinstruct and eval#2990

Merged
cuichenx merged 15 commits into
mainfrom
weijia/gpt_oss_openmatchinstruct2_gsm8k
May 7, 2026
Merged

GPTOSS openmathinstruct and eval#2990
cuichenx merged 15 commits into
mainfrom
weijia/gpt_oss_openmatchinstruct2_gsm8k

Conversation

@weijiac0619

@weijiac0619 weijiac0619 commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

What does this PR do ?

related doc

Changelog

  • Add specific line by line info of high level changes in this PR.

GitHub Actions CI

See the CI sectionin the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

If you haven't finished some of the above items you can still open "Draft" PR.

Additional Information

  • Related to # (issue)

Signed-off-by: weijiac <weijiac@NVIDIA.com>
@copy-pr-bot

copy-pr-bot Bot commented Mar 25, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33 yaoyu-33 changed the title WIP GPTOSS example WIP Mar 30, 2026
Signed-off-by: weijiac <weijiac@NVIDIA.com>
@weijiac0619 weijiac0619 changed the title GPTOSS example WIP GPTOSS openmathinstruct and eval Apr 1, 2026
weijiac0619 and others added 5 commits April 9, 2026 19:56
Signed-off-by: weijiac <weijiac@NVIDIA.com>
Signed-off-by: weijiac <weijiac@NVIDIA.com>
…tchinstruct2_gsm8k

Signed-off-by: weijiac <weijiac@NVIDIA.com>
Signed-off-by: weijiac <weijiac@NVIDIA.com>
Comment thread examples/models/gpt_oss/pack_sft_data.py
Comment thread examples/models/gpt_oss/slurm_sft_analysis_final.sh Outdated
Comment thread examples/models/gpt_oss/slurm_sft_analysis_final.sh Outdated
@weijiac0619 weijiac0619 marked this pull request as ready for review April 25, 2026 00:44
Signed-off-by: weijiac <weijiac@NVIDIA.com>
@cuichenx cuichenx self-requested a review April 25, 2026 00:49
@cuichenx

Copy link
Copy Markdown
Contributor

/claude review

@cuichenx

Copy link
Copy Markdown
Contributor

/ok to test 10d1b91

Comment thread scripts/training/pack_sft_data.py
Comment on lines +60 to +137


def _strip_intermediate_boxed(text: str) -> str:
"""Replace all \\boxed{content} occurrences in text with just content.

Uses brace-depth counting to handle nested braces correctly
(e.g. \\boxed{\\frac{1}{2}} → \\frac{1}{2}).
"""
marker = r"\boxed{"
result = []
i = 0
while i < len(text):
idx = text.find(marker, i)
if idx == -1:
result.append(text[i:])
break
result.append(text[i:idx])
depth = 0
end = -1
for j in range(idx + len(marker) - 1, len(text)):
if text[j] == "{":
depth += 1
elif text[j] == "}":
depth -= 1
if depth == 0:
end = j
break
if end == -1:
# malformed \boxed{, keep as-is
result.append(text[idx:])
break
result.append(text[idx + len(marker) : end])
i = end + 1
return "".join(result)


def process_openmathinstruct2_thinking_packed_example(example: dict, _tokenizer=None) -> dict:
"""Process OpenMathInstruct-2 example into analysis+final channel format.

Puts the CoT reasoning (generated_solution without the trailing \\boxed{N}) into
the 'thinking' field (rendered as <|channel|>analysis by the GPT-OSS chat template)
and the final answer as '#### N' in the 'content' field (rendered as <|channel|>final).

This separates the reasoning chain from the answer delivery, matching the intended
GPT-OSS channel structure for math problem solving.
"""
solution = example["generated_solution"]
expected_answer = str(example["expected_answer"])

# Extract the reasoning prefix: everything before the final \boxed{N}
marker = r"\boxed{"
idx = solution.rfind(marker)
if idx != -1:
depth = 0
end = -1
for i in range(idx + len(marker) - 1, len(solution)):
if solution[i] == "{":
depth += 1
elif solution[i] == "}":
depth -= 1
if depth == 0:
end = i
break
thinking = re.sub(r"\$?\s*$", "", solution[:idx]).rstrip() if end != -1 else solution.rstrip()
else:
thinking = solution.rstrip()

# Strip any intermediate \boxed{} from the reasoning (replace with just content)
thinking = _strip_intermediate_boxed(thinking)

return {
"input": "",
"output": "",
"messages": [
{"role": "user", "content": example["problem"]},
{"role": "assistant", "thinking": thinking, "content": f"#### {expected_answer}"},
],
"original_answers": [expected_answer],

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.

Missing test coverage: _strip_intermediate_boxed and process_openmathinstruct2_thinking_packed_example have non-trivial parsing logic (brace-depth counting, regex stripping, rfind-based extraction) but no tests were added. The existing test file at tests/functional_tests/test_groups/data/hf_processors/test_openmathinstruct2.py only covers process_openmathinstruct2_example.

Worth covering at minimum:

  • Basic case: solution with a single trailing \boxed{N}
  • Nested braces: \boxed{\frac{1}{2}}
  • Multiple \boxed{}: intermediate ones stripped from thinking, last one used for split
  • Malformed input: unclosed \boxed{
  • No \boxed{} at all (fallback path)

Comment thread examples/models/gpt_oss/pack_data_job.sh

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

pls check claude comments, let's add a unit test, otherwise code coverage would fail too. otherwise LGM!

@weijiac0619

Copy link
Copy Markdown
Contributor Author

/ok to test c4dfc76

@cuichenx cuichenx added the ready-to-merge PR is approved, current, and only waiting for CI to pass before merge label May 1, 2026
@cuichenx

cuichenx commented May 1, 2026

Copy link
Copy Markdown
Contributor

/ok to test 2e917a0

@cuichenx cuichenx merged commit 2c1279c into main May 7, 2026
85 of 86 checks passed
@cuichenx cuichenx deleted the weijia/gpt_oss_openmatchinstruct2_gsm8k branch May 7, 2026 19:06
gautham-kollu pushed a commit that referenced this pull request May 12, 2026
Signed-off-by: weijiac <weijiac@NVIDIA.com>
vasunvidia pushed a commit to vasunvidia/Megatron-Bridge that referenced this pull request Jun 10, 2026
Signed-off-by: weijiac <weijiac@NVIDIA.com>
Signed-off-by: Vasudevan Rengasamy <vrengasamy@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge PR is approved, current, and only waiting for CI to pass before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants