44import subprocess
55import sys
66from pathlib import Path
7+ from types import SimpleNamespace
78
89import pytest
910
@@ -144,6 +145,10 @@ def _compat_script() -> Path:
144145 return ROOT / "Magpie" / "scripts" / "benchmark" / "magpie_bench_remote_compat.sh"
145146
146147
148+ def _humaneval_runner () -> Path :
149+ return ROOT / "Magpie" / "scripts" / "benchmark" / "lm_eval_humaneval_compat.py"
150+
151+
147152def _lm_eval_python_stub (tmp_path : Path , args_file : Path ) -> Path :
148153 stub = tmp_path / "lm_eval_python"
149154 stub .write_text (
@@ -213,7 +218,7 @@ def test_remote_eval_uses_task_compatible_openai_backends():
213218 '${EVAL_CONCURRENT_REQUESTS:-${CONC:-8}}}"'
214219 ) in contents
215220 assert '"local-completions"' in contents
216- assert '"local-chat-completions"' in contents
221+ assert "MAGPIE_EVAL_TOKENIZED_REQUESTS=true" not in contents
217222 assert "unset -f python3" not in contents
218223 assert "Crystal" not in contents
219224
@@ -472,7 +477,9 @@ def test_remote_eval_adds_unsafe_flag_and_code_eval_env_for_humaneval(tmp_path:
472477 assert "HF_ALLOW_CODE_EVAL=1" in args
473478
474479
475- def test_remote_eval_adds_humaneval_sample_logging_and_chat_template (tmp_path : Path ):
480+ def test_remote_eval_adds_humaneval_sample_logging_and_local_chat_template (
481+ tmp_path : Path ,
482+ ):
476483 args_file = tmp_path / "lm_eval.args"
477484 python_stub = _lm_eval_python_stub (tmp_path , args_file )
478485 shell = r'''
@@ -490,8 +497,10 @@ def test_remote_eval_adds_humaneval_sample_logging_and_chat_template(tmp_path: P
490497 "MAGPIE_EVAL_LOG_SAMPLES" : "true" ,
491498 "MAGPIE_EVAL_WRITE_OUT" : "true" ,
492499 "MAGPIE_EVAL_APPLY_CHAT_TEMPLATE" : "true" ,
500+ "MAGPIE_EVAL_TOKENIZER" : "org/prompt-tokenizer" ,
501+ "MAGPIE_EVAL_TOKENIZER_REVISION" : "tokenizer-revision" ,
493502 "LM_EVAL_ARGS_FILE" : str (args_file ),
494- "MODEL" : "test -model" ,
503+ "MODEL" : "served -model-alias " ,
495504 }
496505 env .pop ("HF_ALLOW_CODE_EVAL" , None )
497506 subprocess .run (["bash" , "-c" , shell ], check = True , env = env )
@@ -501,11 +510,15 @@ def test_remote_eval_adds_humaneval_sample_logging_and_chat_template(tmp_path: P
501510 assert "--log_samples" in args
502511 assert "--write_out" in args
503512 assert "--apply_chat_template" in args
504- assert "--model local-chat-completions" in args
505- assert "base_url=http://127.0.0.1:8888/v1/chat/completions" in args
506- assert "tokenized_requests=false" in args
507- assert "tokenizer_backend=none" in args
508- assert "--batch_size 1" in args
513+ assert "--model local-completions" in args
514+ assert "base_url=http://127.0.0.1:8888/v1/completions" in args
515+ assert "tokenized_requests=" not in args
516+ assert "tokenizer_backend=huggingface" in args
517+ assert "model=served-model-alias" in args
518+ assert "tokenizer=org/prompt-tokenizer" in args
519+ assert "revision=tokenizer-revision" in args
520+ assert "--batch_size auto" in args
521+ assert str (_humaneval_runner ()) in args
509522
510523
511524def test_remote_eval_splits_humaneval_flags_from_mixed_tasks (tmp_path : Path ):
@@ -549,12 +562,20 @@ def test_remote_eval_splits_humaneval_flags_from_mixed_tasks(tmp_path: Path):
549562 assert flag in humaneval
550563 assert flag not in plain
551564 assert flag not in stock
565+ assert str (_humaneval_runner ()) in humaneval
566+ assert str (_humaneval_runner ()) not in plain
567+ assert str (_humaneval_runner ()) not in stock
568+ assert "-m lm_eval" in plain
569+ assert "-m lm_eval" in stock
552570 assert "--model local-completions" in plain
553571 assert "--model local-completions" in stock
554- assert "--model local-chat-completions" in humaneval
555- assert "base_url=http://127.0.0.1:8888/v1/chat/completions" in humaneval
572+ assert "--model local-completions" in humaneval
573+ assert "base_url=http://127.0.0.1:8888/v1/completions" in humaneval
574+ assert "tokenized_requests=false" in humaneval
556575 assert "base_url=http://127.0.0.1:8888/v1/completions" in plain
576+ assert "tokenized_requests=false" in plain
557577 assert "base_url=http://127.0.0.1:8888/v1/completions" in stock
578+ assert "tokenized_requests=false" in stock
558579 assert "--include_path" not in plain
559580 assert "--include_path" not in humaneval
560581 assert f"--include_path { include_dir } " in stock
@@ -599,8 +620,52 @@ def test_remote_eval_preserves_stock_include_for_isolated_humaneval(tmp_path: Pa
599620 line for line in args_file .read_text ().splitlines () if "--tasks" in line
600621 )
601622 assert "--tasks humaneval_instruct" in invocation
602- assert "--model local-chat-completions" in invocation
623+ assert "--model local-completions" in invocation
624+ assert "base_url=http://127.0.0.1:8888/v1/completions" in invocation
625+ assert "tokenized_requests=false" in invocation
603626 assert f"--include_path { include_dir } " in invocation
627+ assert str (_humaneval_runner ()) in invocation
628+
629+
630+ def test_staged_humaneval_runner_is_invoked (tmp_path : Path ):
631+ from Magpie .modes .benchmark .benchmarker import BenchmarkMode
632+
633+ inferencex = tmp_path / "InferenceX"
634+ mode = object .__new__ (BenchmarkMode )
635+ mode .config = SimpleNamespace (inferencex_path = str (inferencex ))
636+ mode ._prepare_benchmark_scripts ()
637+
638+ staged_dir = inferencex / "benchmarks"
639+ staged_compat = staged_dir / "magpie_bench_remote_compat.sh"
640+ staged_runner = staged_dir / "lm_eval_humaneval_compat.py"
641+ assert staged_runner .read_bytes () == _humaneval_runner ().read_bytes ()
642+
643+ args_file = tmp_path / "lm_eval.args"
644+ python_stub = _lm_eval_python_stub (tmp_path , args_file )
645+ shell = r'''
646+ source "$MAGPIE_COMPAT"
647+ magpie_write_accuracy_result() { return 0; }
648+ magpie_run_eval_remote_direct
649+ '''
650+ env = {
651+ ** os .environ ,
652+ "MAGPIE_COMPAT" : str (staged_compat ),
653+ "RESULT_DIR" : str (tmp_path / "result" ),
654+ "BENCHMARK_BASE_URL" : "http://127.0.0.1:8888" ,
655+ "MAGPIE_EVAL_PYTHON" : str (python_stub ),
656+ "MAGPIE_EVAL_TASKS" : "humaneval_instruct" ,
657+ "MAGPIE_EVAL_APPLY_CHAT_TEMPLATE" : "true" ,
658+ "MAGPIE_EVAL_TOKENIZED_REQUESTS" : "false" ,
659+ "LM_EVAL_ARGS_FILE" : str (args_file ),
660+ "MODEL" : "test-model" ,
661+ }
662+ subprocess .run (["bash" , "-c" , shell ], check = True , env = env )
663+
664+ invocation = next (
665+ line for line in args_file .read_text ().splitlines () if "--tasks" in line
666+ )
667+ assert str (staged_runner ) in invocation
668+ assert "tokenized_requests=false" in invocation
604669
605670
606671def test_remote_eval_uses_comma_tasks_when_help_shows_single_string_cli (tmp_path : Path ):
0 commit comments