Skip to content

Fix math_verify_func for multithreaded environment#3549

Open
SurbhiJainUSC wants to merge 1 commit intomainfrom
math_verify_fix
Open

Fix math_verify_func for multithreaded environment#3549
SurbhiJainUSC wants to merge 1 commit intomainfrom
math_verify_fix

Conversation

@SurbhiJainUSC
Copy link
Copy Markdown
Collaborator

@SurbhiJainUSC SurbhiJainUSC commented Apr 1, 2026

Description

The existing math_verify_func() would fail during training because the underlying Math-Verify 'parse' function uses signal.alarm(), which is incompatible with threaded environments. This results in zero reward score even when the gold and predictions are same.

Error:

Math-Verify 'parse' function doesn't support threaded environment due to usage of signal.alarm() in timeout mechanism. If you need to run in multithreaded environment it's recommended to set the parsing_timeout=None, which will run without timeout (and signal handling). In this case you need to handle the timeouting yourself.

This PR implements a manual math verification function with a timeout (default=5, same as parse() in math_verify), ensuring it can run safely in a multithreaded context.

Tests

python3 -m maxtext.trainers.post_train.rl.train_rl \
model_name=llama3.1-8b-Instruct \
load_parameters_path=$MAXTEXT_CKPT_PATH \
run_name=$RUN_NAME \
base_output_directory=$BASE_OUTPUT_DIRECTORY \
dataset_name=huggingface:nvidia/OpenMathInstruct-2 train_split=train_1M steps=10 \
rollout_tensor_parallelism=1 \
hf_train_files=hf://datasets/nvidia/OpenMathInstruct-2/data/train_1M-*.parquet \
skip_jax_distributed_system=True

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/trainers/post_train/rl/utils_rl.py 65.38% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

1 participant