Use base-model code completion for SmolScript 0.4.0
Browse filesTask comments and fixed headers/scaffolds; deterministic prefix assembly and first-function scope extraction without semantic repair. Same 350 tasks/tests and 96–256 token budgets. All 350 reference bodies pass static roundtrip checks. Full runtime validation and model score improvements remain unverified.
- README.md +24 -4
- SHA256SUMS +11 -8
- completion.py +160 -0
- evaluate.py +7 -13
- examples/base-prompts.json +65 -0
- examples/local-test-report.json +9 -3
- generation_settings.py +1 -1
- generators/build.py +2 -1
- manifest.json +1 -0
- pyproject.toml +1 -1
- tests/test_completion.py +63 -0
- validators/dataset.py +2 -0
README.md
CHANGED
|
@@ -25,7 +25,7 @@ configs:
|
|
| 25 |
---
|
| 26 |
# SmolScript
|
| 27 |
|
| 28 |
-
An original execution-based benchmark of basic programming for 25M–350M parameter language models.
|
| 29 |
|
| 30 |
**Release status: execution-unverified candidate.** All 350 default records have been generated and statically validated. No complete reference execution run or model baseline is claimed. The authoring environment has no Docker/Podman daemon; all 350 default reference solutions and their negative controls still require execution in the supplied sandbox image. See `validation_report.json` for the machine-readable audit. Do not treat this candidate as a validated leaderboard release until `python validate.py` succeeds.
|
| 31 |
|
|
@@ -85,7 +85,7 @@ python evaluate.py --model HuggingFaceTB/SmolLM2-135M --output results.json --re
|
|
| 85 |
python evaluate.py --model HuggingFaceTB/SmolLM2-135M --language python rust --difficulty easy --output subset.json
|
| 86 |
```
|
| 87 |
|
| 88 |
-
One fixed completion prompt (`smolscript-completion-
|
| 89 |
|
| 90 |
Existing files require `--resume`. Settings, dataset/runner hashes, image ID and selected IDs must match. Completed task results are checkpointed atomically; a generated response is saved before execution, so an execution interruption can reuse it. Partial runs never receive a full score. Use one process per output path (a file lock enforces this). Context overflow is an explicit failure; input prompts are never silently truncated.
|
| 91 |
|
|
@@ -95,7 +95,7 @@ For externally generated code, create JSONL records `{"id":"...","code":"..."}`
|
|
| 95 |
python evaluate.py --predictions predictions.jsonl --output results.json
|
| 96 |
```
|
| 97 |
|
| 98 |
-
|
| 99 |
|
| 100 |
## Metrics
|
| 101 |
|
|
@@ -125,7 +125,7 @@ The default split and both local/Modal evaluators now use the same fixed 350 IDs
|
|
| 125 |
|
| 126 |
The language budgets (before a 32-token moderate-task allowance, capped at 256) are Python 128, JavaScript 192, HTML 160, CSS 96, C++ 224, C 256, Lua 160, C# 256, Rust 256. They depend only on language/difficulty, never reference solutions. `--max-new-tokens N` overrides these budgets for a separately recorded experiment; `--batch-size N` overrides the default 64. A response that hits its cap is scored as generated; incorrect or incomplete code still fails the normal execution tests. Generation statistics include token-limit completions, OOM retries, final batch size, elapsed generation time and measured token throughput.
|
| 127 |
|
| 128 |
-
Example: `python evaluate.py --model HuggingFaceTB/SmolLM2-135M --batch-size 64 --output results-v030.json`. Generated batches are checkpointed before execution, and resume skips their inference. Numerical batching differences can change greedy outputs for near-tied logits. This release reduces the task count from 1,000 to 350 and retains the fast decoding budgets introduced in 0.2.0. Its scores must not be merged with earlier editions. Template IDs are `smolscript-0.
|
| 129 |
|
| 130 |
|
| 131 |
## Browser timeout handling
|
|
@@ -142,3 +142,23 @@ Rebuild the Docker image after updating these files. The Modal launcher automati
|
|
| 142 |
CSS styles are inserted synchronously with a DOM style element; the evaluator does not use Playwright 1.56 `add_style_tag`, whose inline-style path waits for a `load` callback. This avoids waiting for that callback on the HTML/CSS pages with scripting disabled. Trusted fixture and baseline errors remain infrastructure failures, separate from candidate execution. Timeout diagnostics now name the precise phase, operation, scenario and language and include bounded worker stderr.
|
| 143 |
|
| 144 |
The Modal path first checks runtime availability and a trusted CSS computed-style/distractor probe, before model generation. Worker processes use explicit subprocess UID/GID settings and private writable HOME/XDG/TMP directories; no Python pre-exec callback is used in the threaded launcher. These changes preserve the fixed 350-example dataset and scoring definition. End-to-end Modal browser verification is still required; local tests cover the injection protocol, diagnostic fields, preflight failure and watchdog behavior.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
---
|
| 26 |
# SmolScript
|
| 27 |
|
| 28 |
+
An original execution-based benchmark of basic programming for 25M–350M parameter language models. Evaluator **0.4.0**, **350 default examples** (fixed dataset edition 0.3.0), nine languages, MIT license.
|
| 29 |
|
| 30 |
**Release status: execution-unverified candidate.** All 350 default records have been generated and statically validated. No complete reference execution run or model baseline is claimed. The authoring environment has no Docker/Podman daemon; all 350 default reference solutions and their negative controls still require execution in the supplied sandbox image. See `validation_report.json` for the machine-readable audit. Do not treat this candidate as a validated leaderboard release until `python validate.py` succeeds.
|
| 31 |
|
|
|
|
| 85 |
python evaluate.py --model HuggingFaceTB/SmolLM2-135M --language python rust --difficulty easy --output subset.json
|
| 86 |
```
|
| 87 |
|
| 88 |
+
One fixed completion prompt (`smolscript-base-completion-v2`), one generation, seed 0, greedy decoding, no beam search, and versioned task budgets from 96 to 256 tokens. Starting batch size is 64, with automatic CUDA OOM backoff. Prompts are grouped by token budget and length; KV caching and supported last-token logits optimizations are enabled. Progress is reported between batches, avoiding per-token GPU-to-CPU synchronization. The same completion template is used for base and instruction models; no model-specific chat template is applied. The model revision resolves to an immutable commit and is retained on resume. Use `--revision SHA` for an explicit pin. Prompts contain task comments, the input domain, supplied standard-library imports, web fixtures/base styles where needed, and a function/markup prefix. Models continue the supplied source directly. References, public examples, hidden tests, and expected answers are never sent to the model.
|
| 89 |
|
| 90 |
Existing files require `--resume`. Settings, dataset/runner hashes, image ID and selected IDs must match. Completed task results are checkpointed atomically; a generated response is saved before execution, so an execution interruption can reuse it. Partial runs never receive a full score. Use one process per output path (a file lock enforces this). Context overflow is an explicit failure; input prompts are never silently truncated.
|
| 91 |
|
|
|
|
| 95 |
python evaluate.py --predictions predictions.jsonl --output results.json
|
| 96 |
```
|
| 97 |
|
| 98 |
+
Externally supplied predictions use complete source code (raw code or a single fenced code block). Model inference stores raw continuations and deterministically assembles the supplied prefix before scoring. Multiple or unfinished fences are rejected. Function tasks receive fixed stdin/stdout wrappers. Compiled languages compile once per task, then run a fresh process per test. HTML is parsed with html5lib and checked in Chromium with document scripts disabled. CSS is parsed with tinycss2 and tested against a fixed fixture at the specified widths. Browser tests assert DOM/computed styles and geometry, without image similarity.
|
| 99 |
|
| 100 |
## Metrics
|
| 101 |
|
|
|
|
| 125 |
|
| 126 |
The language budgets (before a 32-token moderate-task allowance, capped at 256) are Python 128, JavaScript 192, HTML 160, CSS 96, C++ 224, C 256, Lua 160, C# 256, Rust 256. They depend only on language/difficulty, never reference solutions. `--max-new-tokens N` overrides these budgets for a separately recorded experiment; `--batch-size N` overrides the default 64. A response that hits its cap is scored as generated; incorrect or incomplete code still fails the normal execution tests. Generation statistics include token-limit completions, OOM retries, final batch size, elapsed generation time and measured token throughput.
|
| 127 |
|
| 128 |
+
Example: `python evaluate.py --model HuggingFaceTB/SmolLM2-135M --batch-size 64 --output results-v030.json`. Generated batches are checkpointed before execution, and resume skips their inference. Numerical batching differences can change greedy outputs for near-tied logits. This release reduces the task count from 1,000 to 350 and retains the fast decoding budgets introduced in 0.2.0. Its scores must not be merged with earlier editions. Template IDs are `smolscript-0.4.0` and `cognirank2-v4`; use a new output path. No GPU throughput speedup is claimed without a measured run.
|
| 129 |
|
| 130 |
|
| 131 |
## Browser timeout handling
|
|
|
|
| 142 |
CSS styles are inserted synchronously with a DOM style element; the evaluator does not use Playwright 1.56 `add_style_tag`, whose inline-style path waits for a `load` callback. This avoids waiting for that callback on the HTML/CSS pages with scripting disabled. Trusted fixture and baseline errors remain infrastructure failures, separate from candidate execution. Timeout diagnostics now name the precise phase, operation, scenario and language and include bounded worker stderr.
|
| 143 |
|
| 144 |
The Modal path first checks runtime availability and a trusted CSS computed-style/distractor probe, before model generation. Worker processes use explicit subprocess UID/GID settings and private writable HOME/XDG/TMP directories; no Python pre-exec callback is used in the threaded launcher. These changes preserve the fixed 350-example dataset and scoring definition. End-to-end Modal browser verification is still required; local tests cover the injection protocol, diagnostic fields, preflight failure and watchdog behavior.
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
## Base-model completion protocol (0.4.0)
|
| 148 |
+
|
| 149 |
+
The same completion template is used for every model, including instruction models. There is no chat wrapper, conversational instruction block, worked solution, reference implementation, test input, expected answer, or answer-dependent repair. Example prompt ending:
|
| 150 |
+
|
| 151 |
+
```python
|
| 152 |
+
# Starting with n, double it, then take the last decimal digit of its absolute value. Return the result.
|
| 153 |
+
# Integer n from -120 to 120.
|
| 154 |
+
def solve(n):
|
| 155 |
+
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
The model continues at the indented body. Python headers omit type annotations. JavaScript, C, C++, C#, Rust and Lua receive their function/method openings (including the C# class), and applicable supplied imports. HTML receives a task comment followed by `<`; CSS receives its fixture/context and task as a CSS comment. `examples/base-prompts.json` contains an example for each language. `completion.py` is the authoritative prompt and assembly implementation.
|
| 159 |
+
|
| 160 |
+
The supplied prefix is attached to the generated continuation. Answer-independent lexical scope extraction keeps the first completed function/class body and discards trailing prose. Python uses indentation tokens; braced languages count delimiters while ignoring ordinary strings/comments (and supported regex/raw/verbatim strings); Lua counts block keywords. These are constrained completion delimiters, not general language parsers. Syntax and behavior are still checked inside the sandbox. Missing delimiters, malformed indentation, expressions, and return values are never repaired, and no closing suffix is invented. Complete entry-point definitions emitted from scratch, including a single fenced code block, are accepted as deterministic formatting alternatives.
|
| 161 |
+
|
| 162 |
+
Raw continuations and assembled `evaluated_code` are saved separately. The standalone `--predictions` path continues to accept complete code and bypasses the completion prefix. All 350 supplied reference bodies roundtrip through assembly (Python body AST equality, other languages source equality); this is a static assembly check, not complete runtime validation. Full isolated reference execution and a new KLM benchmark run remain outstanding.
|
| 163 |
+
|
| 164 |
+
Use a **new output path** for `smolscript-0.4.0` / `cognirank2-v4`. Dataset edition/selection 0.3.0 remains fixed; only the evaluation prompt/assembly protocol changes. Old scores are not comparable and must be rerun for leaderboard comparisons. Token budgets, deterministic greedy decoding, batch size 64, eight isolated Modal scoring workers, tests and weights remain the same.
|
SHA256SUMS
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
ff73ee904edc9381bd1ea24847e41c6176aec22ba4b63321e8354562f24ba5ce .gitignore
|
| 2 |
8719af4397a8387b8f04140613943545f8ecd90f06529dcab9e68a94927d13fe LICENSE
|
| 3 |
-
|
| 4 |
2447d09ae445094c1ae59df644b46e3ca2f4cc64de630966b94bd5db8b8bf0ac archive/v0.1.0/hidden.jsonl
|
| 5 |
1926bca1b0c6b2244554577135a9c3c305b18fd834c654803b4e8480fff0d3d9 archive/v0.1.0/smolscript.jsonl
|
| 6 |
7bf25948750648aa036bdf277cfd7c38597c98aa06131e805628b9055a7938d9 archive/v0.1.0/smolscript.parquet
|
|
@@ -9,22 +9,24 @@ f1025bcd6a338e93766ddeacb39f2aaf9edb743b9f418968f46bcd13aa14b862 README.md
|
|
| 9 |
1c17c3515e86e2c4bc25c84b45b9f086c87efd98e1d75a7f4b42772b9d88176e archive/v0.2.0/smolscript.jsonl
|
| 10 |
358eae399dac7564ea5fb8753734f189aea3932994a22779d543bdcce847e050 archive/v0.2.0/smolscript.parquet
|
| 11 |
34c7244ea9160ba090e7c3bc1802ca68cc882f8ee9c29736ea8529d499977677 archive/v0.2.0/solutions.jsonl
|
|
|
|
| 12 |
9f9798909d3ab3631a457de1bc7e573c546ed3f3b0f78e6bcb82780e280b37b3 data/smolscript.jsonl
|
| 13 |
ad56c7186df28d84a23912a7fa2ec28b6762240a33b7b2a49412ce5b47319862 data/smolscript.parquet
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
713855348ffc53f49b03a0df47b67294fe2d3593054636eec12b9f184fb3534e examples/result-format.json
|
| 17 |
-
|
| 18 |
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 generators/__init__.py
|
| 19 |
-
|
| 20 |
e1cf493b995f15470c56c097b73e7403ae06f74f5d12cbb3a43ce522514d8577 generators/code.py
|
| 21 |
60be0a7ac6fcd3dfd8b663fc19af189aba3acfdd923219dc6cc1972033380240 generators/specs.py
|
| 22 |
c800d0237c7f4342fb636b6e54f15616a9547406f165e7ad7f96965cd6b9a4d1 generators/subset.py
|
| 23 |
ae6a8d5109035027b71df7eb7297e7c0b811a4a98c649e1729a3fe2a2c09c5bf generators/web.py
|
| 24 |
-
|
| 25 |
6bac32e6045f1788e8b68e96ff6ee41f1b2152cca1b17de24be405025f294930 metrics.py
|
| 26 |
e00a185b961e80e1e1e86e6ddf97ec470d10e1c7b2bed44eb221af42a0eb6972 private_tests/hidden.jsonl
|
| 27 |
-
|
| 28 |
d736311f2645f4bdc7bac3316d858788118af4d551290d3924299f96935bd886 references/solutions.jsonl
|
| 29 |
5a3cb2a82cf3784c41fc9f9046fe6806d5bbe7ce8ae415a9ed1c373abcfe7826 runners/__init__.py
|
| 30 |
965bc9e3dabfc3fba4b745994b43118c456be477edcc34a3ba929ebf39e19ce9 runners/c_runner.py
|
|
@@ -44,9 +46,10 @@ d9ebf5141e3c1928879865050bf3ad7773613084fe62a0ff7eac8d1ea69f8cc4 runners/sandbo
|
|
| 44 |
53098a63b7d2053a4d8494c340e63d924646255c297d31e78c0025ef552c6cd6 sandbox/Dockerfile
|
| 45 |
013cc442aa61d4b85f1986b111ea9adea5f9749bf0cef5176faa67963c900e7c sandbox/supervisor.py
|
| 46 |
538b3c7176b678e6a2b2a55a52aaa2e4a03accc20b2d7d850ee67695f5ecdc9f sandbox/worker.py
|
|
|
|
| 47 |
c155b14ce8fa94dd4a179c22e6ab13accadffcf3571f384d27985ba916cbf864 tests/test_core.py
|
| 48 |
14f40a4b954c81dcf6cb8a2bdf361023e8cea36b54b31e40657f92f39433c124 tests/test_watchdog.py
|
| 49 |
ffba2ed9eabec6186a7568ff0535c9733841b661f7c1e420770dbeb47d87dbae validate.py
|
| 50 |
845d1ef1d45133e04908e1ff187281b9af9f4e48c2bec1994f91b1b191d5d563 validation_report.json
|
| 51 |
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 validators/__init__.py
|
| 52 |
-
|
|
|
|
| 1 |
ff73ee904edc9381bd1ea24847e41c6176aec22ba4b63321e8354562f24ba5ce .gitignore
|
| 2 |
8719af4397a8387b8f04140613943545f8ecd90f06529dcab9e68a94927d13fe LICENSE
|
| 3 |
+
ed646bff1e37aaa95e039cabd8a3d58ed18485179de096e37f5ddf7a7223966e README.md
|
| 4 |
2447d09ae445094c1ae59df644b46e3ca2f4cc64de630966b94bd5db8b8bf0ac archive/v0.1.0/hidden.jsonl
|
| 5 |
1926bca1b0c6b2244554577135a9c3c305b18fd834c654803b4e8480fff0d3d9 archive/v0.1.0/smolscript.jsonl
|
| 6 |
7bf25948750648aa036bdf277cfd7c38597c98aa06131e805628b9055a7938d9 archive/v0.1.0/smolscript.parquet
|
|
|
|
| 9 |
1c17c3515e86e2c4bc25c84b45b9f086c87efd98e1d75a7f4b42772b9d88176e archive/v0.2.0/smolscript.jsonl
|
| 10 |
358eae399dac7564ea5fb8753734f189aea3932994a22779d543bdcce847e050 archive/v0.2.0/smolscript.parquet
|
| 11 |
34c7244ea9160ba090e7c3bc1802ca68cc882f8ee9c29736ea8529d499977677 archive/v0.2.0/solutions.jsonl
|
| 12 |
+
7a057672dbe866e2b8dca92c8fc2a8baf35547831666d41309f20cc09c96344e completion.py
|
| 13 |
9f9798909d3ab3631a457de1bc7e573c546ed3f3b0f78e6bcb82780e280b37b3 data/smolscript.jsonl
|
| 14 |
ad56c7186df28d84a23912a7fa2ec28b6762240a33b7b2a49412ce5b47319862 data/smolscript.parquet
|
| 15 |
+
0eaebae91f30afdebb84183619620f3eb73257ba3ab7c09572f0a982c5c99cd6 evaluate.py
|
| 16 |
+
9ee4551be1a573d2bb94f41935f94028ab538d3b6e4ba957d6bf9a9076fefd67 examples/base-prompts.json
|
| 17 |
+
3c1e0c66200ec31a08d316a012ac30456c06c90521360db8a150a3a56357e255 examples/local-test-report.json
|
| 18 |
713855348ffc53f49b03a0df47b67294fe2d3593054636eec12b9f184fb3534e examples/result-format.json
|
| 19 |
+
af0da7e2ef72cb6ac992aac4a83ddfe200e2512b5e26209882b403cb2b48ea4a generation_settings.py
|
| 20 |
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 generators/__init__.py
|
| 21 |
+
8f14ca3a1a122d0d4ab34420e0c5493299166554aa296ec503af3e53e1847485 generators/build.py
|
| 22 |
e1cf493b995f15470c56c097b73e7403ae06f74f5d12cbb3a43ce522514d8577 generators/code.py
|
| 23 |
60be0a7ac6fcd3dfd8b663fc19af189aba3acfdd923219dc6cc1972033380240 generators/specs.py
|
| 24 |
c800d0237c7f4342fb636b6e54f15616a9547406f165e7ad7f96965cd6b9a4d1 generators/subset.py
|
| 25 |
ae6a8d5109035027b71df7eb7297e7c0b811a4a98c649e1729a3fe2a2c09c5bf generators/web.py
|
| 26 |
+
8a834a5d375b4fa14d9b1416d47056e0533c8338401aff505e98767349e38673 manifest.json
|
| 27 |
6bac32e6045f1788e8b68e96ff6ee41f1b2152cca1b17de24be405025f294930 metrics.py
|
| 28 |
e00a185b961e80e1e1e86e6ddf97ec470d10e1c7b2bed44eb221af42a0eb6972 private_tests/hidden.jsonl
|
| 29 |
+
8e37b2b9360b8283ef7f99a5702b5575d66c34e88e9d59c0f9631437fd30aa61 pyproject.toml
|
| 30 |
d736311f2645f4bdc7bac3316d858788118af4d551290d3924299f96935bd886 references/solutions.jsonl
|
| 31 |
5a3cb2a82cf3784c41fc9f9046fe6806d5bbe7ce8ae415a9ed1c373abcfe7826 runners/__init__.py
|
| 32 |
965bc9e3dabfc3fba4b745994b43118c456be477edcc34a3ba929ebf39e19ce9 runners/c_runner.py
|
|
|
|
| 46 |
53098a63b7d2053a4d8494c340e63d924646255c297d31e78c0025ef552c6cd6 sandbox/Dockerfile
|
| 47 |
013cc442aa61d4b85f1986b111ea9adea5f9749bf0cef5176faa67963c900e7c sandbox/supervisor.py
|
| 48 |
538b3c7176b678e6a2b2a55a52aaa2e4a03accc20b2d7d850ee67695f5ecdc9f sandbox/worker.py
|
| 49 |
+
f58268efbe40e27869f903e8b482b28e1e55213705be8c72e2fb6f5b0b95336c tests/test_completion.py
|
| 50 |
c155b14ce8fa94dd4a179c22e6ab13accadffcf3571f384d27985ba916cbf864 tests/test_core.py
|
| 51 |
14f40a4b954c81dcf6cb8a2bdf361023e8cea36b54b31e40657f92f39433c124 tests/test_watchdog.py
|
| 52 |
ffba2ed9eabec6186a7568ff0535c9733841b661f7c1e420770dbeb47d87dbae validate.py
|
| 53 |
845d1ef1d45133e04908e1ff187281b9af9f4e48c2bec1994f91b1b191d5d563 validation_report.json
|
| 54 |
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 validators/__init__.py
|
| 55 |
+
8bf1f3115935b74be29476ebe5f6965e45f92e12e76679c343b17f6d2215b6a4 validators/dataset.py
|
completion.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fixed base-model code completion. No reference/test fields are read."""
|
| 2 |
+
import io
|
| 3 |
+
import re
|
| 4 |
+
import tokenize
|
| 5 |
+
PROMPT_VERSION='smolscript-base-completion-v2'
|
| 6 |
+
SIGNATURES={
|
| 7 |
+
'python':{'scalar':'def solve(n):','string':'def solve(s):','array':'def solve(values):'},
|
| 8 |
+
'javascript':{'scalar':'function solve(n)','string':'function solve(s)','array':'function solve(values)','dom':'function setup()'},
|
| 9 |
+
'cpp':{'scalar':'long long solve(long long n)','string':'std::string solve(std::string s)','array':'long long solve(const std::vector<long long>& values)'},
|
| 10 |
+
'c':{'scalar':'long long solve(long long n)','string':'const char *solve(const char *input)','array':'long long solve(const long long *values, int length)'},
|
| 11 |
+
'lua':{'scalar':'function solve(n)','string':'function solve(s)','array':'function solve(values)'},
|
| 12 |
+
'csharp':{'scalar':'public static long Solve(long n)','string':'public static string Solve(string s)','array':'public static long Solve(long[] values)'},
|
| 13 |
+
'rust':{'scalar':'fn solve(mut n: i64) -> i64','string':'fn solve(mut s: String) -> String','array':'fn solve(values: Vec<i64>) -> i64'},
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
def prefix(row):
|
| 17 |
+
lang=row['language'];kind=row['metadata']['family']
|
| 18 |
+
if lang=='html':return '<'
|
| 19 |
+
if lang=='css':return ''
|
| 20 |
+
header=SIGNATURES[lang][kind]
|
| 21 |
+
if lang=='python':return header+'\n '
|
| 22 |
+
if lang=='lua':return header+'\n '
|
| 23 |
+
if kind=='dom':return header+' {\n '
|
| 24 |
+
if lang=='csharp':return 'public class Solution {\n'+header+' {\n '
|
| 25 |
+
return header+' {\n '
|
| 26 |
+
|
| 27 |
+
def prompt(row):
|
| 28 |
+
from runners.protocol import HEADERS
|
| 29 |
+
lang=row['language'];meta=row['metadata']
|
| 30 |
+
task=re.sub(r'^In [^,]+,\s*','',row['prompt'])
|
| 31 |
+
task=task.replace(' Return CSS only.','').replace(' Return an HTML fragment.','')
|
| 32 |
+
task=task.removeprefix('Implement setup(). ')
|
| 33 |
+
details=[task]
|
| 34 |
+
if meta.get('input_domain'):details.append(meta['input_domain'])
|
| 35 |
+
context=[]
|
| 36 |
+
if meta.get('fixture'):context.append('HTML fixture: '+meta['fixture'])
|
| 37 |
+
if meta.get('base_css'):context.append('Existing CSS: '+meta['base_css'])
|
| 38 |
+
details=context+details
|
| 39 |
+
if lang=='html':comment='<!-- '+ ' '.join(details).replace('-->','-- >')+' -->\n'
|
| 40 |
+
elif lang=='css':comment='/* '+ ' '.join(details).replace('*/','* /')+' */\n'
|
| 41 |
+
else:
|
| 42 |
+
marker='#' if lang=='python' else '--' if lang=='lua' else '//'
|
| 43 |
+
comment='\n'.join(marker+' '+line for line in details)+'\n'
|
| 44 |
+
return comment+HEADERS.get(lang,'')+prefix(row)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def _brace_end(source):
|
| 48 |
+
"""First complete braced function/class, ignoring quoted strings/comments.
|
| 49 |
+
|
| 50 |
+
Lexer-only delimiting: never evaluate, fix or choose code by test success.
|
| 51 |
+
"""
|
| 52 |
+
depth=0;opened=False;i=0;previous=''
|
| 53 |
+
while i<len(source):
|
| 54 |
+
if source.startswith('//',i):
|
| 55 |
+
end=source.find('\n',i);i=len(source) if end<0 else end+1;continue
|
| 56 |
+
if source.startswith('/*',i):
|
| 57 |
+
end=source.find('*/',i+2)
|
| 58 |
+
if end<0:return len(source)
|
| 59 |
+
i=end+2;continue
|
| 60 |
+
# C/C++/C#/JS/Rust strings and character literals; Rust lifetimes are
|
| 61 |
+
# identifiers, not single-quoted characters.
|
| 62 |
+
ch=source[i]
|
| 63 |
+
raw=re.match(r'(?:u8|u|U|L)?R"([^\s()\\]{0,16})\(',source[i:])
|
| 64 |
+
if raw:
|
| 65 |
+
end=source.find(')'+raw.group(1)+'"',i+raw.end())
|
| 66 |
+
if end<0:return len(source)
|
| 67 |
+
i=end+len(raw.group(1))+2;previous='v';continue
|
| 68 |
+
word=re.match(r'[A-Za-z_$][\w$]*',source[i:])
|
| 69 |
+
if word:
|
| 70 |
+
previous=word.group();i+=len(previous);continue
|
| 71 |
+
if ch in ('"','`') or (ch=="'" and re.match(r"'(?:\\.|[^'\\\n])'",source[i:])):
|
| 72 |
+
quote=ch;verbatim=quote=='"' and i>0 and source[i-1]=='@';i+=1
|
| 73 |
+
while i<len(source):
|
| 74 |
+
if source[i]=='\\' and not verbatim:i+=2;continue
|
| 75 |
+
if source[i]==quote:
|
| 76 |
+
if quote=='"' and i+1<len(source) and source[i+1]=='"' and verbatim:
|
| 77 |
+
i+=2;continue
|
| 78 |
+
i+=1;break
|
| 79 |
+
i+=1
|
| 80 |
+
previous='v';continue
|
| 81 |
+
# JS regular-expression literals occurring where an expression begins.
|
| 82 |
+
if ch=='/' and previous in ('=', '(', ',', ':', '[', '!', '?', 'return', 'throw', 'case', '=>'):
|
| 83 |
+
j=i+1;inside=False
|
| 84 |
+
while j<len(source) and source[j]!='\n':
|
| 85 |
+
if source[j]=='\\':j+=2;continue
|
| 86 |
+
if source[j]=='[':inside=True
|
| 87 |
+
if source[j]==']':inside=False
|
| 88 |
+
if source[j]=='/' and not inside:i=j+1;break
|
| 89 |
+
j+=1
|
| 90 |
+
else:i+=1
|
| 91 |
+
previous='v';continue
|
| 92 |
+
if ch=='{':depth+=1;opened=True
|
| 93 |
+
elif ch=='}':
|
| 94 |
+
depth-=1
|
| 95 |
+
if opened and depth==0:return i+1
|
| 96 |
+
if not ch.isspace():previous='=>' if ch=='>' and previous=='=' else ch
|
| 97 |
+
i+=1
|
| 98 |
+
return len(source)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def _python_end(source):
|
| 102 |
+
depth=0;body=False
|
| 103 |
+
try:
|
| 104 |
+
for token in tokenize.generate_tokens(io.StringIO(source).readline):
|
| 105 |
+
if token.type==tokenize.INDENT:depth+=1;body=True
|
| 106 |
+
elif token.type==tokenize.DEDENT:
|
| 107 |
+
depth-=1
|
| 108 |
+
if body and depth==0:return sum(len(x) for x in source.splitlines(keepends=True)[:token.start[0]-1])
|
| 109 |
+
except (tokenize.TokenError,IndentationError):pass
|
| 110 |
+
return len(source)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def _lua_end(source):
|
| 114 |
+
# Tokenize strings/comments first, then count Lua's block delimiters.
|
| 115 |
+
pattern=r'--\[\[.*?\]\]|--[^\n]*|\[(=*)\[.*?\]\1\]|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|\b(?:function|if|for|while|do|repeat|end|until)\b'
|
| 116 |
+
depth=0;loops=0
|
| 117 |
+
for match in re.finditer(pattern,source,re.S):
|
| 118 |
+
word=match.group()
|
| 119 |
+
if word in ('function','if','repeat'):depth+=1
|
| 120 |
+
elif word in ('for','while'):depth+=1;loops+=1
|
| 121 |
+
elif word=='do':
|
| 122 |
+
if loops:loops-=1
|
| 123 |
+
else:depth+=1
|
| 124 |
+
elif word in ('end','until'):
|
| 125 |
+
depth-=1
|
| 126 |
+
if depth==0:return match.end()
|
| 127 |
+
return len(source)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def assemble(row,continuation):
|
| 131 |
+
"""Attach the supplied header; keep the first completed entry-point scope.
|
| 132 |
+
|
| 133 |
+
No indentation, expressions, missing delimiters or return values are repaired.
|
| 134 |
+
A complete function emitted from scratch is accepted as a format alternative.
|
| 135 |
+
"""
|
| 136 |
+
lang=row['language']
|
| 137 |
+
text=continuation
|
| 138 |
+
if text.lstrip().startswith('```'):
|
| 139 |
+
from runners.common import extract_code
|
| 140 |
+
text=extract_code(text)
|
| 141 |
+
expected=prefix(row)
|
| 142 |
+
starts={
|
| 143 |
+
'python':r'^def\s+solve\s*\(', 'javascript':r'^(?:async\s+)?function\s+(?:solve|setup)\s*\(',
|
| 144 |
+
'lua':r'^function\s+solve\s*\(', 'csharp':r'^public\s+class\s+Solution\b',
|
| 145 |
+
'rust':r'^fn\s+solve\s*\(', 'cpp':r'^(?:long\s+long|std::string)\s+solve\s*\(',
|
| 146 |
+
'c':r'^(?:long\s+long|const\s+char\s*\*)\s*solve\s*\(',
|
| 147 |
+
}
|
| 148 |
+
complete_python=False
|
| 149 |
+
if lang=='python':
|
| 150 |
+
import ast
|
| 151 |
+
try:complete_python=any(isinstance(n,ast.FunctionDef) and n.name=='solve' for n in ast.parse(text).body)
|
| 152 |
+
except SyntaxError:pass
|
| 153 |
+
if complete_python:code=text.lstrip()
|
| 154 |
+
elif lang in starts and re.match(starts[lang],text.lstrip()):code=text.lstrip()
|
| 155 |
+
elif lang=='html' and text.lstrip().startswith('<'):code=text.lstrip()
|
| 156 |
+
else:code=expected+text
|
| 157 |
+
if lang=='python' and not complete_python:code=code[:_python_end(code)]
|
| 158 |
+
elif lang=='lua':code=code[:_lua_end(code)]
|
| 159 |
+
elif lang not in ('html','css','python'):code=code[:_brace_end(code)]
|
| 160 |
+
return code.rstrip()+'\n'
|
evaluate.py
CHANGED
|
@@ -10,16 +10,9 @@ from runners.common import extract_code
|
|
| 10 |
from runners.sandbox import Sandbox
|
| 11 |
from metrics import aggregate
|
| 12 |
ROOT=Path(__file__).resolve().parent
|
| 13 |
-
|
| 14 |
from generation_settings import PROTOCOL,DEFAULT_BATCH_SIZE,token_budget
|
| 15 |
|
| 16 |
-
def prompt(row):
|
| 17 |
-
# Only these public fields reach the model. No tests, answers or references.
|
| 18 |
-
fixture=row['metadata'].get('fixture','');base=row['metadata'].get('base_css','')
|
| 19 |
-
return ('Write code for the following task. Use the standard library only. Return code only.\n'
|
| 20 |
-
+row['prompt']+'\n'+row['output_format']+'\n'+(row['metadata'].get('input_domain') or '')
|
| 21 |
-
+('\nHTML fixture:\n'+fixture if fixture else '')+('\nExisting CSS:\n'+base if base else '')+'\nCode:\n')
|
| 22 |
-
|
| 23 |
def save(path,value):
|
| 24 |
path.parent.mkdir(parents=True,exist_ok=True);temp=path.with_suffix('.tmp');temp.write_text(json.dumps(value,indent=2,allow_nan=False)+'\n');temp.replace(path)
|
| 25 |
|
|
@@ -34,7 +27,7 @@ def main():
|
|
| 34 |
sandbox=Sandbox(a.image,a.engine)
|
| 35 |
rows=[r for r in load(ROOT/'data/smolscript.jsonl') if (not a.language or r['language'] in a.language) and (not a.difficulty or r['difficulty'] in a.difficulty)]
|
| 36 |
hidden={r['id']:r for r in load(ROOT/'private_tests/hidden.jsonl')}
|
| 37 |
-
files=['data/smolscript.jsonl','private_tests/hidden.jsonl','evaluate.py','metrics.py','generation_settings.py']+[str(p.relative_to(ROOT)) for p in sorted((ROOT/'runners').glob('*.py'))]+['sandbox/worker.py','sandbox/supervisor.py']
|
| 38 |
fingerprint={f:hashlib.sha256((ROOT/f).read_bytes()).hexdigest() for f in files}
|
| 39 |
settings={'model':a.model,'requested_revision':a.revision,'language':a.language,'difficulty':a.difficulty,
|
| 40 |
'max_new_tokens':a.max_new_tokens,'batch_size':a.batch_size,'decode_protocol':PROTOCOL,'prompt_version':PROMPT_VERSION,'dataset':fingerprint,'sandbox':sandbox.identity,
|
|
@@ -57,8 +50,8 @@ def main():
|
|
| 57 |
snapshot=snapshot_download(a.model,revision=state.get('resolved_revision') or a.revision)
|
| 58 |
revision=Path(snapshot).name
|
| 59 |
state['resolved_revision']=revision
|
| 60 |
-
tokenizer=AutoTokenizer.from_pretrained(snapshot)
|
| 61 |
-
model=AutoModelForCausalLM.from_pretrained(snapshot,torch_dtype='auto',device_map=a.device)
|
| 62 |
model.eval();torch.manual_seed(0)
|
| 63 |
import importlib.metadata
|
| 64 |
state['environment']={'python':sys.version,'packages':{n:importlib.metadata.version(n) for n in ('torch','transformers','huggingface-hub')},'device':str(model.device)}
|
|
@@ -91,10 +84,11 @@ def main():
|
|
| 91 |
text=codes[row['id']]
|
| 92 |
else:text=state['generations'][row['id']]
|
| 93 |
state['pending']={'id':row['id'],'generation':text};save(a.output,state)
|
| 94 |
-
|
|
|
|
| 95 |
except ValueError as e:result={'passed':False,'syntax_success':False,'tests':[],'error':str(e)}
|
| 96 |
else:result=get_runner(row['language']).evaluate(row,code,hidden[row['id']],sandbox)
|
| 97 |
-
state['results'].append({'id':row['id'],'language':row['language'],'difficulty':row['difficulty'],'generation':text,**result})
|
| 98 |
state.pop('pending',None)
|
| 99 |
save(a.output,state);print(f"{len(state['results'])}/{len(rows)} {row['id']} {'PASS' if result['passed'] else 'FAIL'}",flush=True)
|
| 100 |
state['metrics']=aggregate(state['results'],[r['id'] for r in rows],full_run=not(a.language or a.difficulty));state['complete']=True;save(a.output,state)
|
|
|
|
| 10 |
from runners.sandbox import Sandbox
|
| 11 |
from metrics import aggregate
|
| 12 |
ROOT=Path(__file__).resolve().parent
|
| 13 |
+
from completion import prompt,assemble,PROMPT_VERSION
|
| 14 |
from generation_settings import PROTOCOL,DEFAULT_BATCH_SIZE,token_budget
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def save(path,value):
|
| 17 |
path.parent.mkdir(parents=True,exist_ok=True);temp=path.with_suffix('.tmp');temp.write_text(json.dumps(value,indent=2,allow_nan=False)+'\n');temp.replace(path)
|
| 18 |
|
|
|
|
| 27 |
sandbox=Sandbox(a.image,a.engine)
|
| 28 |
rows=[r for r in load(ROOT/'data/smolscript.jsonl') if (not a.language or r['language'] in a.language) and (not a.difficulty or r['difficulty'] in a.difficulty)]
|
| 29 |
hidden={r['id']:r for r in load(ROOT/'private_tests/hidden.jsonl')}
|
| 30 |
+
files=['data/smolscript.jsonl','private_tests/hidden.jsonl','evaluate.py','metrics.py','generation_settings.py','completion.py']+[str(p.relative_to(ROOT)) for p in sorted((ROOT/'runners').glob('*.py'))]+['sandbox/worker.py','sandbox/supervisor.py']
|
| 31 |
fingerprint={f:hashlib.sha256((ROOT/f).read_bytes()).hexdigest() for f in files}
|
| 32 |
settings={'model':a.model,'requested_revision':a.revision,'language':a.language,'difficulty':a.difficulty,
|
| 33 |
'max_new_tokens':a.max_new_tokens,'batch_size':a.batch_size,'decode_protocol':PROTOCOL,'prompt_version':PROMPT_VERSION,'dataset':fingerprint,'sandbox':sandbox.identity,
|
|
|
|
| 50 |
snapshot=snapshot_download(a.model,revision=state.get('resolved_revision') or a.revision)
|
| 51 |
revision=Path(snapshot).name
|
| 52 |
state['resolved_revision']=revision
|
| 53 |
+
tokenizer=AutoTokenizer.from_pretrained(snapshot,trust_remote_code=True)
|
| 54 |
+
model=AutoModelForCausalLM.from_pretrained(snapshot,trust_remote_code=True,torch_dtype='auto',device_map=a.device)
|
| 55 |
model.eval();torch.manual_seed(0)
|
| 56 |
import importlib.metadata
|
| 57 |
state['environment']={'python':sys.version,'packages':{n:importlib.metadata.version(n) for n in ('torch','transformers','huggingface-hub')},'device':str(model.device)}
|
|
|
|
| 84 |
text=codes[row['id']]
|
| 85 |
else:text=state['generations'][row['id']]
|
| 86 |
state['pending']={'id':row['id'],'generation':text};save(a.output,state)
|
| 87 |
+
code=None
|
| 88 |
+
try:code=extract_code(text) if a.predictions else assemble(row,text)
|
| 89 |
except ValueError as e:result={'passed':False,'syntax_success':False,'tests':[],'error':str(e)}
|
| 90 |
else:result=get_runner(row['language']).evaluate(row,code,hidden[row['id']],sandbox)
|
| 91 |
+
state['results'].append({'id':row['id'],'language':row['language'],'difficulty':row['difficulty'],'generation':text,'evaluated_code':code,**result})
|
| 92 |
state.pop('pending',None)
|
| 93 |
save(a.output,state);print(f"{len(state['results'])}/{len(rows)} {row['id']} {'PASS' if result['passed'] else 'FAIL'}",flush=True)
|
| 94 |
state['metrics']=aggregate(state['results'],[r['id'] for r in rows],full_run=not(a.language or a.difficulty));state['complete']=True;save(a.output,state)
|
examples/base-prompts.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"id": "smolscript-python-0015",
|
| 4 |
+
"language": "python",
|
| 5 |
+
"prompt_version": "smolscript-base-completion-v2",
|
| 6 |
+
"completion_prompt": "# Starting with n, double it, then take the last decimal digit of its absolute value. Return the result.\n# Integer n from -120 to 120.\ndef solve(n):\n ",
|
| 7 |
+
"supplied_prefix": "def solve(n):\n "
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"id": "smolscript-javascript-0010",
|
| 11 |
+
"language": "javascript",
|
| 12 |
+
"prompt_version": "smolscript-base-completion-v2",
|
| 13 |
+
"completion_prompt": "// Starting with ASCII string s, replace each run of spaces with one space, then keep the first floor(length/2) characters. Return the result.\n// ASCII s of at most 80 characters, without newlines.\nfunction solve(s) {\n ",
|
| 14 |
+
"supplied_prefix": "function solve(s) {\n "
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"id": "smolscript-html-0003",
|
| 18 |
+
"language": "html",
|
| 19 |
+
"prompt_version": "smolscript-base-completion-v2",
|
| 20 |
+
"completion_prompt": "<!-- Create an h1 heading reading Welcome. On its outer element, set right-to-left direction via dir. -->\n<",
|
| 21 |
+
"supplied_prefix": "<"
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"id": "smolscript-css-0010",
|
| 25 |
+
"language": "css",
|
| 26 |
+
"prompt_version": "smolscript-base-completion-v2",
|
| 27 |
+
"completion_prompt": "/* HTML fixture: <div id=\"scope\"><div id=\"target\" class=\"target\" data-kind=\"card\">Alpha<span>One</span><span>Two</span></div><div class=\"other\">Beta</div></div><div class=\"target\" id=\"outside\">Outside</div> Existing CSS: * { box-sizing: content-box; } .target,.other { border: 1px solid black; width:200px; height:80px; min-width:0; max-width:none; margin:0; padding:0; display:block; position:static; } Style every element with class target: set font-weight to 700. Leave other elements unchanged. */\n",
|
| 28 |
+
"supplied_prefix": ""
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"id": "smolscript-cpp-0003",
|
| 32 |
+
"language": "cpp",
|
| 33 |
+
"prompt_version": "smolscript-base-completion-v2",
|
| 34 |
+
"completion_prompt": "// Starting with n, clamp it to the inclusive range -5 to 5, then subtract it from ten. Return the result.\n// Integer n from -120 to 120.\n#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\n#include <cstdlib>\nlong long solve(long long n) {\n ",
|
| 35 |
+
"supplied_prefix": "long long solve(long long n) {\n "
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"id": "smolscript-c-0001",
|
| 39 |
+
"language": "c",
|
| 40 |
+
"prompt_version": "smolscript-base-completion-v2",
|
| 41 |
+
"completion_prompt": "// Starting with n, replace it with 1 if negative, otherwise 0, then add one. Return the result.\n// Integer n from -120 to 120.\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\nlong long solve(long long n) {\n ",
|
| 42 |
+
"supplied_prefix": "long long solve(long long n) {\n "
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"id": "smolscript-lua-0001",
|
| 46 |
+
"language": "lua",
|
| 47 |
+
"prompt_version": "smolscript-base-completion-v2",
|
| 48 |
+
"completion_prompt": "-- Starting with n, replace it with 1 if negative, otherwise 0, then add one. Return the result.\n-- Integer n from -120 to 120.\nfunction solve(n)\n ",
|
| 49 |
+
"supplied_prefix": "function solve(n)\n "
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"id": "smolscript-csharp-0003",
|
| 53 |
+
"language": "csharp",
|
| 54 |
+
"prompt_version": "smolscript-base-completion-v2",
|
| 55 |
+
"completion_prompt": "// Starting with n, clamp it to the inclusive range -5 to 5, then subtract it from ten. Return the result.\n// Integer n from -120 to 120.\nusing System;\nusing System.Linq;\nusing System.Collections.Generic;\npublic class Solution {\npublic static long Solve(long n) {\n ",
|
| 56 |
+
"supplied_prefix": "public class Solution {\npublic static long Solve(long n) {\n "
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"id": "smolscript-rust-0002",
|
| 60 |
+
"language": "rust",
|
| 61 |
+
"prompt_version": "smolscript-base-completion-v2",
|
| 62 |
+
"completion_prompt": "// Starting with ASCII string s, convert lowercase ASCII letters to uppercase, then convert uppercase ASCII letters to lowercase. Return the result.\n// ASCII s of at most 80 characters, without newlines.\nuse std::io::{self, Read};\nfn solve(mut s: String) -> String {\n ",
|
| 63 |
+
"supplied_prefix": "fn solve(mut s: String) -> String {\n "
|
| 64 |
+
}
|
| 65 |
+
]
|
examples/local-test-report.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"unit_tests": {
|
| 3 |
-
"passed":
|
| 4 |
"command": "python -m unittest discover -s tests -q"
|
| 5 |
},
|
| 6 |
"python_reference_ast_parse": 44,
|
|
@@ -21,9 +21,15 @@
|
|
| 21 |
"rust": 39
|
| 22 |
},
|
| 23 |
"blocked_reason": "Docker/Podman unavailable; full isolated reference and negative-control execution remains unverified.",
|
| 24 |
-
"model_baselines": "
|
| 25 |
"gpu_throughput_benchmark": "not run",
|
| 26 |
"watchdog_policy": "phase-watchdog-v1",
|
| 27 |
"watchdog_test_execution": "trusted synthetic workers; candidate generations not executed on host",
|
| 28 |
-
"browser_setup_patch": "synchronous-css-private-home-v1"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"unit_tests": {
|
| 3 |
+
"passed": 28,
|
| 4 |
"command": "python -m unittest discover -s tests -q"
|
| 5 |
},
|
| 6 |
"python_reference_ast_parse": 44,
|
|
|
|
| 21 |
"rust": 39
|
| 22 |
},
|
| 23 |
"blocked_reason": "Docker/Podman unavailable; full isolated reference and negative-control execution remains unverified.",
|
| 24 |
+
"model_baselines": "No 0.4.0 model baseline run",
|
| 25 |
"gpu_throughput_benchmark": "not run",
|
| 26 |
"watchdog_policy": "phase-watchdog-v1",
|
| 27 |
"watchdog_test_execution": "trusted synthetic workers; candidate generations not executed on host",
|
| 28 |
+
"browser_setup_patch": "synchronous-css-private-home-v1",
|
| 29 |
+
"reference_body_assembly": {
|
| 30 |
+
"checked": 350,
|
| 31 |
+
"method": "Python body AST equality; other languages source equality",
|
| 32 |
+
"execution": false
|
| 33 |
+
},
|
| 34 |
+
"prompt_version": "smolscript-base-completion-v2"
|
| 35 |
}
|
generation_settings.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""Versioned decoding policy; never reads references or hidden answers."""
|
| 2 |
-
PROTOCOL='smolscript-0.
|
| 3 |
DEFAULT_BATCH_SIZE=64
|
| 4 |
MAX_NEW_TOKENS=256
|
| 5 |
|
|
|
|
| 1 |
"""Versioned decoding policy; never reads references or hidden answers."""
|
| 2 |
+
PROTOCOL='smolscript-0.4.0'
|
| 3 |
DEFAULT_BATCH_SIZE=64
|
| 4 |
MAX_NEW_TOKENS=256
|
| 5 |
|
generators/build.py
CHANGED
|
@@ -125,7 +125,8 @@ def build():
|
|
| 125 |
# HF-compatible nested metadata; JSON strings give consistent test schemas across modalities.
|
| 126 |
parquet_rows=[{**r,'tests':stable(r['tests']),'metadata':stable(r['metadata'])} for r in public]
|
| 127 |
pq.write_table(pa.Table.from_pylist(parquet_rows),ROOT/'data/smolscript.parquet',compression='zstd')
|
| 128 |
-
|
|
|
|
| 129 |
'difficulty':{'easy':210,'medium':105,'moderate':35},'generator_seed':7301,
|
| 130 |
'validation_status':'execution_unverified','selection_protocol':DEFAULT_VERSION,
|
| 131 |
'selected_ids':[r['id'] for r in public],
|
|
|
|
| 125 |
# HF-compatible nested metadata; JSON strings give consistent test schemas across modalities.
|
| 126 |
parquet_rows=[{**r,'tests':stable(r['tests']),'metadata':stable(r['metadata'])} for r in public]
|
| 127 |
pq.write_table(pa.Table.from_pylist(parquet_rows),ROOT/'data/smolscript.parquet',compression='zstd')
|
| 128 |
+
from generation_settings import PROTOCOL
|
| 129 |
+
manifest={'evaluation_protocol':PROTOCOL,'version':DEFAULT_VERSION,'examples':350,'languages':{k:sum(v) for k,v in ALLOCATION.items()},
|
| 130 |
'difficulty':{'easy':210,'medium':105,'moderate':35},'generator_seed':7301,
|
| 131 |
'validation_status':'execution_unverified','selection_protocol':DEFAULT_VERSION,
|
| 132 |
'selected_ids':[r['id'] for r in public],
|
manifest.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
{
|
|
|
|
| 2 |
"version": "smolscript-0.3.0",
|
| 3 |
"examples": 350,
|
| 4 |
"languages": {
|
|
|
|
| 1 |
{
|
| 2 |
+
"evaluation_protocol": "smolscript-0.4.0",
|
| 3 |
"version": "smolscript-0.3.0",
|
| 4 |
"examples": 350,
|
| 5 |
"languages": {
|
pyproject.toml
CHANGED
|
@@ -3,7 +3,7 @@ requires = ["setuptools>=68"]
|
|
| 3 |
build-backend = "setuptools.build_meta"
|
| 4 |
[project]
|
| 5 |
name = "smolscript"
|
| 6 |
-
version = "0.
|
| 7 |
description = "A small-model multilingual execution benchmark"
|
| 8 |
requires-python = ">=3.11"
|
| 9 |
license = {text = "MIT"}
|
|
|
|
| 3 |
build-backend = "setuptools.build_meta"
|
| 4 |
[project]
|
| 5 |
name = "smolscript"
|
| 6 |
+
version = "0.4.0"
|
| 7 |
description = "A small-model multilingual execution benchmark"
|
| 8 |
requires-python = ">=3.11"
|
| 9 |
license = {text = "MIT"}
|
tests/test_completion.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ast
|
| 2 |
+
import json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
import sys
|
| 5 |
+
import unittest
|
| 6 |
+
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT))
|
| 7 |
+
from completion import prompt,prefix,assemble,PROMPT_VERSION
|
| 8 |
+
from validators.dataset import load
|
| 9 |
+
|
| 10 |
+
class CompletionTests(unittest.TestCase):
|
| 11 |
+
def setUp(self):self.rows=load(ROOT/'data/smolscript.jsonl')
|
| 12 |
+
def test_prompt_ends_with_header_and_never_reads_answers(self):
|
| 13 |
+
for row in self.rows:
|
| 14 |
+
text=prompt(row)
|
| 15 |
+
self.assertTrue(text.endswith(prefix(row)))
|
| 16 |
+
changed={**row,'reference_solution':'SECRET_REFERENCE','tests':[{'input':'SECRET_INPUT','expected':'SECRET_ANSWER'}]}
|
| 17 |
+
self.assertEqual(prompt(changed),text)
|
| 18 |
+
self.assertNotIn('Return code only',text)
|
| 19 |
+
self.assertNotIn('function function',text)
|
| 20 |
+
def test_python_has_no_type_annotation_boilerplate(self):
|
| 21 |
+
row=next(r for r in self.rows if r['language']=='python')
|
| 22 |
+
self.assertEqual(prefix(row),'def solve(n):\n ')
|
| 23 |
+
text=assemble(row,'return abs(2*n)%10\n\nQuestion: explain this code')
|
| 24 |
+
ast.parse(text);self.assertNotIn('Question:',text)
|
| 25 |
+
def test_every_reference_body_roundtrips_without_solution_repairs(self):
|
| 26 |
+
refs={r['id']:r['reference_solution'] for r in load(ROOT/'references/solutions.jsonl')}
|
| 27 |
+
for row in self.rows:
|
| 28 |
+
lang=row['language'];ref=refs[row['id']]
|
| 29 |
+
if lang=='html':tail=ref[1:]
|
| 30 |
+
elif lang=='css':tail=ref
|
| 31 |
+
elif lang=='python':tail=ref.split('\n',1)[1][4:]
|
| 32 |
+
else:
|
| 33 |
+
self.assertTrue(ref.startswith(prefix(row)),row['id'])
|
| 34 |
+
tail=ref[len(prefix(row)):]
|
| 35 |
+
result=assemble(row,tail)
|
| 36 |
+
if lang=='python':
|
| 37 |
+
self.assertEqual(ast.dump(ast.Module(body=ast.parse(ref).body[0].body,type_ignores=[])),ast.dump(ast.Module(body=ast.parse(result).body[0].body,type_ignores=[])),row['id'])
|
| 38 |
+
self.assertEqual(len(ast.parse(ref).body[0].body),len(ast.parse(result).body[0].body),row['id'])
|
| 39 |
+
else:self.assertEqual(result,ref.rstrip()+'\n',row['id'])
|
| 40 |
+
def test_scopes_ignore_strings_and_preserve_nested_blocks(self):
|
| 41 |
+
row=next(r for r in self.rows if r['language']=='javascript' and r['metadata']['family']=='scalar')
|
| 42 |
+
code=assemble(row,'if (n) { return "}"; }\n return 0;\n}\nExplanation: done')
|
| 43 |
+
self.assertIn('return 0;',code);self.assertNotIn('Explanation',code)
|
| 44 |
+
def test_delimiters_inside_regex_raw_and_verbatim_strings(self):
|
| 45 |
+
cases=[('javascript','return /[{}]/.test("}");\n}'),
|
| 46 |
+
('cpp','return std::string(R"tag(} \" {)tag");\n}'),
|
| 47 |
+
('csharp','return @"a "" } "" b";\n}\n}')]
|
| 48 |
+
for lang,tail in cases:
|
| 49 |
+
row=next(r for r in self.rows if r['language']==lang)
|
| 50 |
+
self.assertEqual(assemble(row,tail+'\nExplanation: done'),prefix(row)+tail+'\n',lang)
|
| 51 |
+
|
| 52 |
+
def test_truncated_body_is_not_given_missing_braces(self):
|
| 53 |
+
row=next(r for r in self.rows if r['language']=='javascript')
|
| 54 |
+
self.assertFalse(assemble(row,'return 3;').rstrip().endswith('}'))
|
| 55 |
+
def test_complete_function_and_fenced_output_are_accepted(self):
|
| 56 |
+
row=next(r for r in self.rows if r['language']=='python')
|
| 57 |
+
whole='def solve(n):\n return abs(n)\n'
|
| 58 |
+
self.assertEqual(assemble(row,whole),whole)
|
| 59 |
+
self.assertIn('return "```"',assemble(row,'return "```"'))
|
| 60 |
+
self.assertEqual(assemble(row,'```python\n'+whole+'```'),whole)
|
| 61 |
+
with self.assertRaises(ValueError):assemble(row,'```python\nreturn n')
|
| 62 |
+
|
| 63 |
+
if __name__=='__main__':unittest.main()
|
validators/dataset.py
CHANGED
|
@@ -60,6 +60,8 @@ def check(root):
|
|
| 60 |
decoded=[{**r,'tests':json.loads(r['tests']),'metadata':json.loads(r['metadata'])} for r in parquet]
|
| 61 |
assert decoded==rows,'JSONL/Parquet mismatch'
|
| 62 |
manifest=json.loads((root/'manifest.json').read_text())
|
|
|
|
|
|
|
| 63 |
for name,digest in manifest['files'].items():assert hashlib.sha256((root/name).read_bytes()).hexdigest()==digest,('Hash mismatch',name)
|
| 64 |
return {'static_validation':'passed','examples':len(rows),'languages':dict(Counter(r['language'] for r in rows)),
|
| 65 |
'difficulty':dict(Counter(r['difficulty'] for r in rows)),'categories':dict(categories),
|
|
|
|
| 60 |
decoded=[{**r,'tests':json.loads(r['tests']),'metadata':json.loads(r['metadata'])} for r in parquet]
|
| 61 |
assert decoded==rows,'JSONL/Parquet mismatch'
|
| 62 |
manifest=json.loads((root/'manifest.json').read_text())
|
| 63 |
+
from generation_settings import PROTOCOL
|
| 64 |
+
assert manifest['evaluation_protocol']==PROTOCOL,'Evaluation protocol mismatch'
|
| 65 |
for name,digest in manifest['files'].items():assert hashlib.sha256((root/name).read_bytes()).hexdigest()==digest,('Hash mismatch',name)
|
| 66 |
return {'static_validation':'passed','examples':len(rows),'languages':dict(Counter(r['language'] for r in rows)),
|
| 67 |
'difficulty':dict(Counter(r['difficulty'] for r in rows)),'categories':dict(categories),
|