Skip to content

Commit eec8114

Browse files
committed
refactor
1 parent 5e3de12 commit eec8114

21 files changed

Lines changed: 1377 additions & 925 deletions

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
args:
1010
- '-w'
1111
- '--skip="*.txt,pylintrc,.*,src/maxtext/assets/*,src/maxtext/input_pipeline/protos/*"'
12-
- '-L ND,nd,sems,TE,ROUGE,rouge,astroid,ags,dout'
12+
- '-L ND,nd,sems,TE,te,als,ROUGE,rouge,astroid,ags,dout'
1313
- '.'
1414
additional_dependencies:
1515
- tomli
@@ -30,7 +30,7 @@ repos:
3030
args:
3131
- '--disable=R0401,R0917,W0201,W0613'
3232
- "--ignore-patterns='.pytype,.*pyi$'"
33-
- '--ignore-paths=src/maxtext/input_pipeline/protos'
33+
- '--ignore-paths=src/maxtext/input_pipeline/protos|src/maxtext/eval/third_party'
3434

3535
# - repo: https://github.com/google/pytype
3636
# rev: 2024.10.11

src/maxtext/eval/README.md

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,14 @@ official accuracy. The debug report also shows diagnostic accuracy excluding
130130
infrastructure failures; that diagnostic must not be used as the published
131131
benchmark score.
132132

133-
Before a long TPU benchmark, run the one-shot chat-path diagnostic with the
134-
same model/server settings. For an 8-chip v6e GPT-OSS deployment in HF mode:
133+
Before a long TPU benchmark, run the simple-evals unit suite, which checks
134+
Harmony output separation, request-error behavior, concurrency, and result
135+
reporting:
135136

136137
```bash
137-
python -m maxtext.eval.runner.debug_simple_evals \
138-
--model_name gpt-oss-20b \
139-
--hf_path openai/gpt-oss-20b \
140-
--hf_mode \
141-
--base_output_directory /tmp \
142-
--run_name simple_evals_debug \
143-
--max_model_len 32768 \
144-
--tensor_parallel_size 8 \
145-
--debug_max_tokens 1024 \
146-
--reasoning_effort high \
147-
--debug_output /tmp/simple_evals_tpu_debug.json
138+
pytest tests/unit/eval/test_simple_evals_runner.py
148139
```
149140

150-
The script launches the normal in-process server and checks Harmony prompt
151-
rendering, final/reasoning/raw separation, forced analysis-only truncation,
152-
diagnostic opt-in, token accounting, and two-request batch response ordering.
153-
It prints `PASS` and exits zero only when every applicable check succeeds;
154-
otherwise it writes the failure to the JSON report and exits nonzero. When
155-
testing a MaxText checkpoint, pass the same `--checkpoint_path` and
156-
`--model_name` used by the benchmark instead of `--hf_mode`.
157-
158141
## Common Flags
159142

160143
| Flag | Description |

src/maxtext/eval/native_evals/aime_eval.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""AIME 2024 and 2025 simple-evals tasks."""
16+
1517
from __future__ import annotations
1618

1719
import random
@@ -23,6 +25,9 @@
2325
from maxtext.eval.third_party.simple_evals.common import HTML_JINJA
2426
from maxtext.eval.third_party.simple_evals.types import Eval, EvalResult, SamplerBase, SingleEvalResult
2527

28+
# SamplerBase intentionally preserves the vendored simple-evals API.
29+
# pylint: disable=protected-access
30+
2631
_AIME_2024_URL = (
2732
"https://huggingface.co/datasets/Maxwell-Jia/AIME_2024/resolve/refs%2Fconvert%2Fparquet/default/train/0000.parquet"
2833
)
@@ -37,7 +42,7 @@
3742

3843
QUERY_TEMPLATE = (
3944
"Solve this competition math problem. The final answer is always an integer between 0 and 999. "
40-
'Think step by step, then write the final answer by itself on the last line in the format '
45+
"Think step by step, then write the final answer by itself on the last line in the format "
4146
'"Answer: $N" (without quotes), where $N is the integer answer.\n\n{problem}'
4247
)
4348

@@ -71,22 +76,20 @@ def __init__(self, year: int, num_examples: int | None = None, n_repeats: int =
7176

7277
def __call__(self, sampler: SamplerBase) -> EvalResult:
7378
def fn(row: dict):
74-
prompt_messages = [
75-
sampler._pack_message(content=QUERY_TEMPLATE.format(problem=row["problem"]), role="user")
76-
]
79+
prompt_messages = [sampler._pack_message(content=QUERY_TEMPLATE.format(problem=row["problem"]), role="user")]
7780
sampler_response = sampler(prompt_messages)
7881
response_text = sampler_response.response_text
7982
actual_queried_prompt_messages = sampler_response.actual_queried_message_list
80-
extracted_answer = extract_answer(response_text)
83+
extracted_answer = extract_answer(response_text) if common.request_succeeded(sampler_response) else None
8184
score = 1.0 if extracted_answer is not None and int(extracted_answer) == int(row["answer"]) else 0.0
8285
html = common.jinja_env.from_string(HTML_JINJA).render(
8386
prompt_messages=actual_queried_prompt_messages,
84-
next_message=dict(content=response_text, role="assistant"),
87+
next_message={"content": response_text, "role": "assistant"},
8588
score=score,
8689
correct_answer=row["answer"],
8790
extracted_answer=extracted_answer,
8891
)
89-
convo = actual_queried_prompt_messages + [dict(content=response_text, role="assistant")]
92+
convo = actual_queried_prompt_messages + [{"content": response_text, "role": "assistant"}]
9093
return SingleEvalResult(
9194
html=html,
9295
score=score,

src/maxtext/eval/native_evals/gsm8k_eval.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""GSM8K simple-evals task."""
16+
1517
from __future__ import annotations
1618

1719
import random
@@ -24,6 +26,9 @@
2426
from maxtext.eval.third_party.simple_evals.mgsm_eval import score_mgsm
2527
from maxtext.eval.third_party.simple_evals.types import Eval, EvalResult, SamplerBase, SingleEvalResult
2628

29+
# SamplerBase intentionally preserves the vendored simple-evals API.
30+
# pylint: disable=protected-access
31+
2732
_DATASET_REPO_ID = "openai/gsm8k"
2833
_TEST_PARQUET_FILENAME = "main/test-00000-of-00001.parquet"
2934

@@ -83,22 +88,20 @@ def __init__(self, num_examples: int | None = None):
8388

8489
def __call__(self, sampler: SamplerBase) -> EvalResult:
8590
def fn(row: dict):
86-
prompt_messages = [
87-
sampler._pack_message(content=QUERY_TEMPLATE.format(question=row["question"]), role="user")
88-
]
91+
prompt_messages = [sampler._pack_message(content=QUERY_TEMPLATE.format(question=row["question"]), role="user")]
8992
sampler_response = sampler(prompt_messages)
9093
response_text = sampler_response.response_text
9194
actual_queried_prompt_messages = sampler_response.actual_queried_message_list
92-
extracted_answer = extract_answer(response_text)
95+
extracted_answer = extract_answer(response_text) if common.request_succeeded(sampler_response) else None
9396
score = score_mgsm(row["target"], extracted_answer or "")
9497
html = common.jinja_env.from_string(HTML_JINJA).render(
9598
prompt_messages=actual_queried_prompt_messages,
96-
next_message=dict(content=response_text, role="assistant"),
99+
next_message={"content": response_text, "role": "assistant"},
97100
score=score,
98101
correct_answer=row["target"],
99102
extracted_answer=extracted_answer or None,
100103
)
101-
convo = actual_queried_prompt_messages + [dict(content=response_text, role="assistant")]
104+
convo = actual_queried_prompt_messages + [{"content": response_text, "role": "assistant"}]
102105
return SingleEvalResult(
103106
html=html,
104107
score=score,

0 commit comments

Comments
 (0)