Upload hf_test_runner.py with huggingface_hub
Browse files- hf_test_runner.py +3 -30
hf_test_runner.py
CHANGED
|
@@ -51,7 +51,7 @@ except ImportError:
|
|
| 51 |
|
| 52 |
# Constants
|
| 53 |
PREEXEC_ERROR_EXIT_CODE = 2
|
| 54 |
-
HF_DATASET_ID = "samahadhoud/idea-first-code-later-cp"
|
| 55 |
|
| 56 |
|
| 57 |
@dataclass
|
|
@@ -211,19 +211,13 @@ def _preexec_setrlimit_bytes(bytes_limit):
|
|
| 211 |
Note:
|
| 212 |
If this function fails, it writes the traceback to stderr and
|
| 213 |
exits with PREEXEC_ERROR_EXIT_CODE (2) to signal the error.
|
| 214 |
-
On macOS, RLIMIT_AS may not be supported, so failures are silently ignored.
|
| 215 |
"""
|
| 216 |
try:
|
| 217 |
if bytes_limit is None:
|
| 218 |
return
|
| 219 |
if not isinstance(bytes_limit, int) or bytes_limit < 0:
|
| 220 |
raise ValueError("bytes_limit must be non-negative int")
|
| 221 |
-
|
| 222 |
-
try:
|
| 223 |
-
resource.setrlimit(resource.RLIMIT_AS, (bytes_limit, bytes_limit))
|
| 224 |
-
except (ValueError, OSError):
|
| 225 |
-
# RLIMIT_AS not supported on macOS, silently ignore
|
| 226 |
-
pass
|
| 227 |
except Exception:
|
| 228 |
try:
|
| 229 |
tb = traceback.format_exc()
|
|
@@ -523,35 +517,14 @@ class TestRunner:
|
|
| 523 |
Note:
|
| 524 |
The scorer is compiled with g++ -std=c++17. The executable is stored
|
| 525 |
in a temporary directory that persists for the duration of testing.
|
| 526 |
-
On macOS, bits/stdc++.h is replaced with standard includes.
|
| 527 |
"""
|
| 528 |
# Create persistent temp directory for scorer (not auto-deleted)
|
| 529 |
tmp_dir = tempfile.mkdtemp(prefix="scorer_")
|
| 530 |
scorer_src = os.path.join(tmp_dir, "scorer.cpp")
|
| 531 |
scorer_exe = os.path.join(tmp_dir, "scorer")
|
| 532 |
|
| 533 |
-
scorer_code = problem.special_judge_code
|
| 534 |
-
|
| 535 |
-
# Handle bits/stdc++.h which doesn't exist on macOS
|
| 536 |
-
if "#include <bits/stdc++.h>" in scorer_code or '#include "bits/stdc++.h"' in scorer_code:
|
| 537 |
-
# Replace with common standard includes
|
| 538 |
-
replacement = """#include <iostream>
|
| 539 |
-
#include <vector>
|
| 540 |
-
#include <string>
|
| 541 |
-
#include <algorithm>
|
| 542 |
-
#include <cmath>
|
| 543 |
-
#include <set>
|
| 544 |
-
#include <map>
|
| 545 |
-
#include <cstdio>
|
| 546 |
-
#include <cstdlib>
|
| 547 |
-
#include <cstring>
|
| 548 |
-
#include <sstream>
|
| 549 |
-
#include <fstream>"""
|
| 550 |
-
scorer_code = scorer_code.replace('#include <bits/stdc++.h>', replacement)
|
| 551 |
-
scorer_code = scorer_code.replace('#include "bits/stdc++.h"', replacement)
|
| 552 |
-
|
| 553 |
with open(scorer_src, "w") as f:
|
| 554 |
-
f.write(
|
| 555 |
|
| 556 |
result = subprocess.run(
|
| 557 |
["g++", "-o", scorer_exe, scorer_src, "-std=c++17"],
|
|
|
|
| 51 |
|
| 52 |
# Constants
|
| 53 |
PREEXEC_ERROR_EXIT_CODE = 2
|
| 54 |
+
HF_DATASET_ID = "samahadhoud/idea-first-code-later-cp-benchmark"
|
| 55 |
|
| 56 |
|
| 57 |
@dataclass
|
|
|
|
| 211 |
Note:
|
| 212 |
If this function fails, it writes the traceback to stderr and
|
| 213 |
exits with PREEXEC_ERROR_EXIT_CODE (2) to signal the error.
|
|
|
|
| 214 |
"""
|
| 215 |
try:
|
| 216 |
if bytes_limit is None:
|
| 217 |
return
|
| 218 |
if not isinstance(bytes_limit, int) or bytes_limit < 0:
|
| 219 |
raise ValueError("bytes_limit must be non-negative int")
|
| 220 |
+
resource.setrlimit(resource.RLIMIT_AS, (bytes_limit, bytes_limit))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
except Exception:
|
| 222 |
try:
|
| 223 |
tb = traceback.format_exc()
|
|
|
|
| 517 |
Note:
|
| 518 |
The scorer is compiled with g++ -std=c++17. The executable is stored
|
| 519 |
in a temporary directory that persists for the duration of testing.
|
|
|
|
| 520 |
"""
|
| 521 |
# Create persistent temp directory for scorer (not auto-deleted)
|
| 522 |
tmp_dir = tempfile.mkdtemp(prefix="scorer_")
|
| 523 |
scorer_src = os.path.join(tmp_dir, "scorer.cpp")
|
| 524 |
scorer_exe = os.path.join(tmp_dir, "scorer")
|
| 525 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
with open(scorer_src, "w") as f:
|
| 527 |
+
f.write(problem.special_judge_code)
|
| 528 |
|
| 529 |
result = subprocess.run(
|
| 530 |
["g++", "-o", scorer_exe, scorer_src, "-std=c++17"],
|