# Qwen3.8-27B on one Trainium2 chip, built from scratch by VibeSys VibeSys agents wrote a serving engine for [Qwen3.8-27B](https://huggingface.co/Qwen/Qwen3.8-27B) (BF16, text only) on one `trn2.3xlarge`: one Trainium2 chip, 4 logical NeuronCores, 96 GiB of HBM. They started from an empty repository, with the Hugging Face Transformers implementation as the correctness reference. Existing serving engines and model libraries, such as vLLM Neuron and NxD Inference, were off limits. - **Workload:** 64 concurrent requests, 1k prompt tokens and 1k generated tokens each. - **Metric:** output throughput (`output_tokens_per_s`). This is generated tokens divided by the benchmark's end-to-end wall time, prefill included. - **Accuracy gate, every round:** greedy outputs and teacher-forced logprobs are compared against Transformers on 12 prompts, including 4k-token and cache-resume cases. - **Acceptance rule:** a candidate must beat the current best by more than the 2% noise bar. - **Agents:** all agents ran on Claude Opus 5.5. The 37 rounds took about 53 hours and $230 in API usage. **Result:** 195 tok/s for the first working engine (round 1), 861 tok/s for the final engine (round 37). The benchmark's wall time fell from 336 s to 76 s. ## One run in two parts The experiment is one continuous run of 37 rounds. VibeSys ran it as two processes: | Part | Rounds | What happened | |:--|:--|:--| | 1 | 1–7 | Starts from an empty repository and reaches 425 tok/s by round 3. | | 2 | 8–37 | Restarts from part 1's best code, a summary of what part 1 learned ([`evidence/PRIOR_RUN.md`](evidence/PRIOR_RUN.md)), and an NKI GDN decode kernel that part 1 wrote but left off by default. | Everything in this directory uses the global round numbers 1–37. The only exception is the raw logs, which keep each part's own numbering: round *N* in part 2's logs is global round *N* + 7. ## What's here | Path | Contents | |:--|:--| | [`engine/`](engine/) | The final engine (round 37). `server.py` is the entry point; `qwen_trn/` has the model, runtime and scheduler. The NKI kernels are `nki_gdn.py` (GDN decode), `nki_attn.py` (decode attention) and `nki_gemm.py` (prefill GEMM). `tests/` has the agents' microbenchmarks and CPU tests. | | [`engine/.vibesys/tasks/default/`](engine/.vibesys/tasks/default/) | The task VibeSys was given: the objective and interface contract (`OBJECTIVE.md`), the accuracy checker, the benchmark and the task `Dockerfile`. | | [`code-history/`](code-history/) | How the engine's code evolved, as one patch per step (below). Applying them in order to an empty directory reproduces `engine/` exactly. | | [`evidence/`](evidence/) | The agents' own evidence: timings, microbenchmarks, profiles and bit-comparisons (below). | | [`logs/`](logs/) | VibeSys framework logs for both parts (below). | ## Rounds "Best" is the best accepted throughput after that round (tok/s). A round with no measurement produced no candidate that reached the official benchmark. | Round | Measured (tok/s) | Best | Code change | Notes | |--:|:--|--:|:--|:--| | 1 | 194.8 ✓ | 194.8 | [round01](code-history/round01.patch) | First working engine, 50 minutes in | | 2 | 223.6 ✓ | 223.6 | [round02](code-history/round02.patch) | | | 3 | 425.4 ✓ | 425.4 | [round03](code-history/round03.patch) | GDN state updates as a dense masked `where`, one-pass decode recurrence | | 4 | 425.3 | 425.4 | | | | 5–7 | | 425.4 | | NKI GDN decode kernel written, but it flipped a near-tie token in the accuracy gate | | 8 | | 425.4 | [round08-start](code-history/round08-start.patch) | Part 2 starts: part 1's best code plus the NKI GDN kernel, off by default | | 9 | | 425.4 | | | | 10 | 461.2 ✓ | 461.2 | [round10](code-history/round10.patch) | Dense GDN prefill inverse | | 11 | 498.5 ✓ | 498.5 | [round11](code-history/round11.patch) | | | 12 | 500.5 ✓ | 500.5 | | | | 13 | 584.4 ✓ | 584.4 | [round13](code-history/round13.patch) | Bit-identical NKI GDN decode kernel | | 14 | 745.0, 740.7 ✓ | 740.7 | [round14](code-history/round14.patch) | NKI decode attention (+27%) | | 15 | 747.1 | 740.7 | | | | 16 | 777.7 ✓ | 777.7 | [round16](code-history/round16.patch) | Pipelined decode (non-blocking copy and event wait) | | 17 | 782.5 | 777.7 | | | | 18 | | 777.7 | | | | 19 | 777.2 ✓ | 777.7 | | | | 20 | 769.2 | 777.7 | | | | 21–22 | | 777.7 | | | | 23 | 813.7 ✓ | 813.7 | [round23](code-history/round23.patch) | Bit-exact prefill data movement | | 24–26 | 813.1, 813.0, 815.9 | 813.7 | | | | 27 | 816.4 ✓ | 816.4 | [round27](code-history/round27.patch) | | | 28 | 821.3 ✓ | 821.3 | [round28](code-history/round28.patch) | | | 29 | 840.9 ✓ | 840.9 | [round29](code-history/round29.patch) | Prefill all-reduce split | | 30 | 840.7, 840.5 | 840.9 | | | | 31 | 857.1 ✓ | 857.1 | [round31](code-history/round31.patch) | Prefill gate/up projection split | | 32–36 | 856.9, 855.9, 856.5, 870.7, 856.2, 854.0 | 857.1 | | None accepted | | 37 | 860.7 ✓ | 860.7 | [round37](code-history/round37.patch) | NKI GEMM for the GDN input projection. Final engine. | ✓ = accepted. ## Code history Each patch in [`code-history/`](code-history/) is the change to the engine (outside `evidence/` and the task bundle) between two points in the final engine's lineage. It is named after the round in which its end point was measured. A patch can include accepted work from rounds in between: for example, `round13.patch` also contains round 12's change. To rebuild the final engine: ```bash mkdir engine-replay && cd engine-replay && git init -q for p in round01 round02 round03 round08-start round10 round11 round13 round14 round16 \ round23 round27 round28 round29 round31 round37; do git apply ../code-history/$p.patch done ``` ## Evidence The agents named their evidence directories after hypotheses (`hN`), not rounds. This table maps them: | Directory | Round | | Directory | Round | |:--|--:|:--|:--|--:| | `evidence/h2` | 2 | | `evidence/h7` | 13 | | `evidence/h3` | 3 | | `evidence/h8` | 14 | | `evidence/h4` | 4 | | `evidence/h10` | 16 | | `evidence/h5` | 5 | | `evidence/h16` | 23 | | `evidence/h6` | 6 | | `evidence/h20` | 27 | | `evidence/h3r` | 10 | | `evidence/h21` | 28 | | `evidence/h4s` | 11 | | `evidence/h22` | 29 | | `evidence/h5r` | 12 | | `evidence/h24` | 31 | | | | | `evidence/h30` | 37 | Round 31 also dumped 14 tensors of about 150 MB each to `evidence/h24/mb/`. Those are not included. ## Logs | Path | Contents | |:--|:--| | `logs/part1-rounds01-07/`, `logs/part2-rounds08-37/` | One directory per part. | | `core-events.jsonl` | Every framework event in order: rounds, measurements, gate results and adoptions, plus every agent invocation, tool call, tool result and agent output. This is the full record of what the agents did. | | `run*.log` | The framework's own log. Part 2 has one file per process: the first run and two resumes after a stall in round 35 (part 2's round 28). | | `usage.jsonl` | Token usage per agent call. | Commit hashes in the logs refer to the original run repositories, which are not public. Identifying information (names, email addresses, EC2 hostnames, IP addresses and instance IDs) has been redacted. The raw agent output streams are not included. ## Run it ```bash cd engine # Optional: reuse weights already on the host instead of downloading 55 GB. ln -s /path/to/Qwen3.8-27B .vibesys/tasks/default/reference/model ``` By hand, from `engine/` inside the task image built from `.vibesys/tasks/default/Dockerfile` (the checker and benchmark start and stop `server.py` themselves; pass `--base-url` to use a running server): ```bash python3 .vibesys/tasks/default/accuracy_checker/checker.py python3 .vibesys/tasks/default/benchmark/run.py --request-factory-engine /path/to/session_runner ```