> For the complete documentation index, see [llms.txt](https://docs.macrocosmos.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.macrocosmos.ai/subnets/readme/subnet-1-current-competitions/wiki-compression-competition.md). Agents can also search and read this documentation through its [MCP server](https://docs.macrocosmos.ai/~gitbook/mcp).

# Wiki Compression Competition

## Wiki Compression Competition

**A better model of the text is a smaller file.** An entropy coder spends as many bits on the next byte as its predictor's uncertainty demands: a confident, correct guess costs a fraction of a bit, a hedge costs several. The best entries on the Large Text Compression Benchmark get there by mixing a neural network with hand-built models. This competition takes the hand-built part away.

The Wiki Compression competition asks miners to compress English Wikipedia **losslessly**, with a neural network as the **only** predictor. Miners submit a next-byte predictor as an **ONNX graph**, and the platform runs it behind a **fixed rANS entropy coder** that is the same for everyone, on a real compress → decompress round trip. The score is the compression ratio, so the only way up the leaderboard is a model that predicts Wikipedia better, within a fixed compute budget per byte on one CPU thread.

### **Evaluation Overview**

Each evaluation draws **512 chunks of 4,096 bytes** (2 MiB in total) from a pool of English Wikipedia, compresses them with your model, decompresses the result and checks it byte for byte.

| Condition            | Value, and whether it moves between rounds                                                   |
| -------------------- | -------------------------------------------------------------------------------------------- |
| Text pool            | Bytes 100,000,000 – 500,000,000 of `enwik9` (the XML dump, wiki markup included). **Fixed.** |
| The 512 chunks drawn | **Re-drawn every round.** The same for every submission within a round.                      |
| Difficulty mix       | 8 chunks from each of 64 compressibility bands. **Fixed.**                                   |
| Chunk size           | 4,096 bytes. **Fixed.**                                                                      |
| Deadline per call    | 240 s. **Fixed.**                                                                            |

* **The pool is public; the draw is not.** You may train on the pool. What you cannot know is which 512 chunks a round will draw, and a 32 MB model cannot hold 400 MB of text: it has to learn how Wikipedia is written.
* **Rounds differ in text, not in difficulty.** Chunks are grouped into 64 bands by how compressible a fixed reference model finds them, and every round draws the same number from every band. The reference model's score moves by about 0.5% from round to round.
* **`enwik8` is yours.** The first 100 MB of `enwik9` is not in the pool; use it to develop and validate.
* Within a round, **every submission is scored on the same chunks**, and the incumbent is re-scored on them alongside the challengers.

### **Step by Step**

1. The referee draws the round's 512 chunks and sends them to the player in one `compress` call.
2. The player steps your model through all 512 chunks side by side, one batched model call per byte position, and codes each chunk into its own stream.
3. The referee sends the 512 streams back in one `decompress` call. The player runs your model again, this time on the bytes it has decoded so far, and returns the text.
4. The referee checks every chunk byte for byte.
5. The referee compresses a random subset of up to 64 chunks again, in a different order, as a batch of their own, and compares each chunk's code length with the first pass.
6. It computes the score.

Every chunk is compressed on its own, from the same blank state. Nothing learned in one chunk is available in another, and nothing carries over from `compress` to `decompress` except the streams.

At each byte position, your model is called with:

| Name        | Direction | Type    | Shape          | Meaning                                                                              |
| ----------- | --------- | ------- | -------------- | ------------------------------------------------------------------------------------ |
| `tokens`    | input     | int64   | `[batch]`      | The previous byte of each stream, 0–255. At the first position of a chunk it is 256. |
| `state_in`  | input     | float32 | `[batch, S]`   | Your model's memory. All zeros at the first position.                                |
| `logits`    | output    | float32 | `[batch, 256]` | Unnormalised scores for the next byte.                                               |
| `state_out` | output    | float32 | `[batch, S]`   | Handed back to you as `state_in` at the next position.                               |

* `S` is fixed by your graph: any value from 1 to 262,144. Pack whatever you need to remember into it — a recurrent state, a window of recent bytes, attention keys — and unpack it inside the graph.
* The player turns each row of logits into probabilities with a softmax, then into integer frequencies that sum to 65,536 with at least 1 per byte value. A row that contains a NaN or an infinity is coded as if every byte were equally likely.
* Your model runs with **ONNX Runtime 1.28.0 on one CPU thread**.

### **Model Rules**

Rules 1–4 are checked when a submission is uploaded, and again whenever it defends the top spot at the start of a round: a model that breaks one is rejected with the reason, before it is evaluated. Rule 5 is checked in every evaluation (step 5 above).

1. **Operators** from the standard ONNX domain, from this set only: matrix multiplies (`MatMul`, `Gemm`, `MatMulInteger`, `QLinearMatMul`) and recurrent cells (`GRU`, `LSTM`, `RNN`); lookups and writes (`Gather`, `GatherElements`, `ScatterElements`, `ScatterND`); normalisation, softmax and reductions; element-wise maths, activations, comparisons, logic and `Cast`/`Where`; shape and layout operators; quantisation operators. No `Loop` or `Scan`, and no random-number operators. `If` is accepted only when tensor shapes alone decide it, which is what PyTorch emits for `squeeze()` on a dimension it cannot prove is 1.
2. **Fixed shapes.** Once the number of chunks is known, every tensor's shape is fixed; no shape may depend on the data.
3. **Work per byte at most 1,600,000**, counted from the graph with the number of chunks fixed:

   * 1 per multiply-add in a matrix multiply;
   * per output element, 12 for arithmetic, comparison and layout operators, and 60 for `Exp`, `Log`, `Pow`, `Tanh`, `Sigmoid`, `Gelu`, `Erf` and the like;
   * per input element, 36 for softmax and 250 for `LayerNormalization`;
   * per lookup or write index, 250 into a tensor of up to 262,144 values and 5,000 into a larger one;
   * 11,000 per operator per step, shared by the chunks.

   Work must grow in proportion to the number of chunks. The reference model needs about 757,000.
4. **Every weight is used** by an operator.
5. **Each chunk is modelled on its own:** a chunk's predictions must not depend on the other chunks in the evaluation or on how many there are. If any chunk's code length changes by more than 0.01% when it is re-run in the smaller batch, the evaluation scores 0.

### **Constraints**

* Terminal reasons, reported per evaluation:
  * `completed`: every chunk came back exactly and the streams are smaller than the text.
  * `not_lossless`: at least one chunk did not come back byte for byte.
  * `no_compression`: every chunk came back, but the streams were not smaller than the text.
  * `compress_failed` / `decompress_failed`: the call errored, missed its deadline, or returned the wrong number of streams or chunks.
  * `chunk_dependence`: a chunk's code length changed by more than 0.01% when it was re-run in a smaller batch (rule 5).
  * `player_not_ready`: the model could not be served, for example because it does not match the interface. The player log says what was wrong.
* Three calls per evaluation, each with a **240 s deadline**: `compress`, `decompress`, and a `compress` of up to 64 chunks for rule 5.
* Timeouts: **1,100 s** for the referee, **1,260 s** for the player and **600 s** for the model-rules check.
* Player and referee each run on **2 CPU / 2 GiB / no GPU / no network**. Your model gets one of the player's two CPUs.
* Memory scales with `S`: the player holds 512 × `S` float32 values for `state_in`, and again for `state_out`.

### **Scoring**

```
raw_score     = total original bytes / total compressed bytes     over all 512 chunks, higher is better
bits_per_byte = 8 / raw_score

raw_score = 0 if any chunk is not restored exactly, if the streams are not smaller than the text,
            if a chunk's code length depends on its batch, or if any call fails or misses its deadline
```

* **Nothing else enters the score** — in particular not how fast your model ran, as long as every call met the deadline.
* To take the lead, a challenger must beat the current top raw score by more than 1%. `baseline_raw_score` is **0.0**, so round 1 goes to anything that compresses.
* At the start of each round the incumbent is automatically re-submitted, re-checked against the model rules and re-scored on the new draw, so the comparison is always like-for-like.
* The `score_to_beat` is displayed in the Apex CLI dashboard under competition information.

### **Miner Submissions**

* A single **ONNX graph** with the interface above. The `batch` axis must be **dynamic**.
* One self-contained file: model-local functions and external data files are not accepted. `torch.onnx.export(..., dynamo=True)` writes the weights to a separate `.data` file unless you pass `external_data=False`.
* Maximum size **32 MB**. The architecture is not constrained beyond the model rules.
* Submission fee: **$20.00 USD**.
* Default round length: **2 days**. Submissions are revealed 2 **days** after evaluation.
* The submission rate limit is **4 submissions per hotkey within 24 hours**, across all competitions.
* After each round, every evaluation exposes:
  * the result metadata: compression ratio, bits per byte, chunks restored exactly, the ratio per compressibility band, and the status and latency of each call;
  * `history/chunks.jsonl`: one row per chunk with its band, its size, the size of your stream for it, the size the reference model reaches on it, and whether it was restored exactly;
  * the player log: one line per call with its latency and status, plus the reason if your model was not accepted.
* Logs are opened after the current round is completed.

**Tips for Miners**

* **Be deterministic.** Decompression re-runs your model, so the same inputs must give bit-identical logits; check "restored exactly" locally.
* **Keep chunks apart.** Nothing may flow between batch rows; `tools/local_eval.py` runs the same independence check as the referee.
* **Budget work, not size.** The 1,600,000 work limit binds long before 32 MB does. `tools/local_eval.py` prints your work and checks all five rules.
* **Validate on held-out text:** train on `enwik8` and score on its tail (`--offset 90000000`).
* **Start from the reference model:** `baseline/train_baseline.py`.
* The full environment — the entropy coder, the referee, the pool builder, the model rules and the reference model — is public at [apex-competition-wiki-compression-public](https://github.com/macrocosm-os/apex-competition-wiki-compression-public).
* Local tools in that repo: `tools/local_eval.py` checks the model rules and scores a model in-process, `tools/run_local.sh` runs the real player and referee containers, and `tools/read_records.py` lists your worst chunks from an evaluation's `history/chunks.jsonl`.
