|
| 1 | +# Order-Adaptive Entropy Gating + XSA-All |
| 2 | + |
| 3 | +**val_bpb: 0.9370** (n-gram7 sliding window, stride=64, 3-seed mean, std=0.0003) | **~15.9 MB** artifact | 8xH100 SXM, 600s |
| 4 | + |
| 5 | +Built on PR #753 with two improvements: XSA extended to all layers and order-adaptive entropy gating for n-gram eval. |
| 6 | + |
| 7 | +## Results (8xH100 80GB SXM) |
| 8 | + |
| 9 | +| Seed | Steps | Sliding s64 BPB | N-gram7 s64 BPB | Artifact | |
| 10 | +|------|-------|-----------------|-----------------|----------| |
| 11 | +| 1337 | 6,783 | 1.1225 | 0.9372 | 15,828,199 | |
| 12 | +| 42 | 6,783 | 1.1219 | 0.9372 | 15,923,891 | |
| 13 | +| 2025 | 6,776 | 1.1223 | 0.9367 | 15,964,115 | |
| 14 | +| **Mean** | | **1.1222 (±0.0003)** | **0.9370 (±0.0003)** | | |
| 15 | + |
| 16 | +| Metric | Value | |
| 17 | +|--------|-------| |
| 18 | +| Step avg | ~88.5ms | |
| 19 | +| Training time | 600s | |
| 20 | +| **Total submission size (seed 1337)** | **15,828,199 bytes** | |
| 21 | + |
| 22 | +## Key Innovation: Order-Adaptive Entropy Gating |
| 23 | + |
| 24 | +Standard n-gram eval uses a single `entropy_center` threshold to decide when to trust the n-gram cache over the transformer. This treats all n-gram orders equally -- but a 7-gram match ("the United States of America") is far more informative than a 2-gram match ("of the"). |
| 25 | + |
| 26 | +**Order-adaptive entropy gating** assigns a different entropy threshold per n-gram order: |
| 27 | + |
| 28 | +``` |
| 29 | +ent_center_n = entropy_center - slope * (matched_order - min_order) |
| 30 | +``` |
| 31 | + |
| 32 | +With `entropy_center=3.0` and `slope=0.25`: |
| 33 | +- **7-gram match**: threshold = 3.0 - 0.25*(7-2) = **1.75** (trust even at moderate model confidence) |
| 34 | +- **5-gram match**: threshold = 3.0 - 0.25*(5-2) = **2.25** |
| 35 | +- **3-gram match**: threshold = 3.0 - 0.25*(3-2) = **2.75** |
| 36 | +- **2-gram match**: threshold = 3.0 - 0.25*(2-2) = **3.00** (only trust when model is very uncertain) |
| 37 | + |
| 38 | +The intuition: high-order n-grams capture specific multi-word patterns that are almost certainly correct. Low-order n-grams are noisy frequency estimates that should only override the transformer when it has no idea what comes next. |
| 39 | + |
| 40 | +### Implementation |
| 41 | + |
| 42 | +Three changes to the n-gram eval loop (all eval-time only, no training changes): |
| 43 | + |
| 44 | +1. **Track matched order per token**: During multi-order backoff (7→6→5→...→2), record which order actually matched for each token position. |
| 45 | + |
| 46 | +2. **Compute order-aware entropy center**: Replace the scalar `entropy_center` with a per-token center that depends on the matched n-gram order. |
| 47 | + |
| 48 | +3. **Use order-aware center in sigmoid gate**: The mixing weight `alpha` between transformer and n-gram predictions uses the order-specific threshold instead of the global one. |
| 49 | + |
| 50 | +```python |
| 51 | +# Standard (single threshold for all orders) |
| 52 | +alpha_i = alpha_max * sigmoid((entropy_i - ent_center) / temp) |
| 53 | + |
| 54 | +# Order-adaptive (threshold varies by matched n-gram order) |
| 55 | +ent_center_i = ent_center - slope * (matched_order_i - min_order) |
| 56 | +alpha_i = alpha_max * sigmoid((entropy_i - ent_center_i) / temp) |
| 57 | +``` |
| 58 | + |
| 59 | +**Score-first legality**: The matched order comes from the n-gram cache (built from already-scored tokens only). The entropy comes from the model's own logits. No future tokens are used. |
| 60 | + |
| 61 | +### Ablation |
| 62 | + |
| 63 | +| Configuration | N-gram7 BPB | Delta vs PR #753 baseline | |
| 64 | +|--------------|------------|--------------------------| |
| 65 | +| PR #753 baseline (XSA_LAST_N=4, ent_center=4.0) | 0.9618 | -- | |
| 66 | +| + XSA-all (XSA_LAST_N=11) + entropy_center=3.0 | 0.9416 | -0.0202 | |
| 67 | +| + **Order-adaptive gating (slope=0.25)** | **0.9353** | **-0.0265** | |
| 68 | + |
| 69 | +## Changes from PR #753 |
| 70 | + |
| 71 | +| | PR #753 | This | |
| 72 | +|---|---|---| |
| 73 | +| N-gram7 BPB | 0.9618 | **0.9353** | |
| 74 | +| Sliding BPB (no n-gram) | 1.1193 | 1.1195 | |
| 75 | +| XSA layers | Last 4 (XSA_LAST_N=4) | **All 11 (XSA_LAST_N=11)** | |
| 76 | +| Entropy center | 4.0 | **3.0** | |
| 77 | +| Order-adaptive gating | No | **Yes (slope=0.25)** | |
| 78 | +| Artifact size | ~15.83 MB | ~15.83 MB | |
| 79 | +| Training | Identical | Identical | |
| 80 | + |
| 81 | +## Architecture (carried from PR #753) |
| 82 | + |
| 83 | +- 11 transformer layers (512d, 8 heads, 4 KV heads) |
| 84 | +- MLP 3x (1536 hidden) with LeakyReLU(0.5)^2 activation |
| 85 | +- Cross-Self-Attention (XSA) with learned memory keys/values |
| 86 | +- Partial RoPE (16/64 dims) |
| 87 | +- LN Scale (1/sqrt(layer+1)) |
| 88 | +- Value Embedding (VE128) on layers 9-10 |
| 89 | +- Bigram Hash Embedding (1536 buckets) |
| 90 | +- EMA(0.997) + SWA(every 50 steps) |
| 91 | +- GPTQ int6 quantization + lzma compression |
| 92 | +- Parameter Banking + Parallel Muon optimizer |
| 93 | +- Late QAT (threshold=0.15) |
| 94 | +- Multi-order n-gram eval with hashed backoff (orders 2-7) |
| 95 | +- Shard ordering for training data |
| 96 | +- DTG (Dynamic Token Gating) |
| 97 | + |
| 98 | +## Configuration |
| 99 | + |
| 100 | +```bash |
| 101 | +NUM_LAYERS=11 BIGRAM_VOCAB_SIZE=1536 XSA_LAST_N=11 \ |
| 102 | +EMA_ENABLED=1 EMA_DECAY=0.997 SWA_ENABLED=1 SWA_EVERY=50 \ |
| 103 | +ROPE_DIMS=16 LN_SCALE=1 LATE_QAT=1 LATE_QAT_THRESHOLD=0.15 \ |
| 104 | +VE_ENABLED=1 VE_DIM=128 VE_LAYERS=9,10 \ |
| 105 | +MUON_WD=0.04 ADAM_WD=0.04 \ |
| 106 | +MATRIX_LR=0.025 SCALAR_LR=0.025 TIED_EMBED_LR=0.035 \ |
| 107 | +MUON_MOMENTUM=0.99 MUON_MOMENTUM_WARMUP_START=0.92 \ |
| 108 | +MUON_MOMENTUM_WARMUP_STEPS=1500 WARMDOWN_ITERS=3500 \ |
| 109 | +ITERATIONS=20000 MAX_WALLCLOCK_SECONDS=600 EVAL_STRIDE=64 \ |
| 110 | +NGRAM_EVAL_ORDER=7 NGRAM_EVAL_ALPHA=0.3 NGRAM_EVAL_MIN_COUNT=2 \ |
| 111 | +NGRAM_EVAL_BUCKETS=4194304 NGRAM_EVAL_ENTROPY_CENTER=3.0 \ |
| 112 | +NGRAM_EVAL_ORDER_ADAPTIVE=1 NGRAM_EVAL_ORDER_ENT_SLOPE=0.25 \ |
| 113 | +SEED=1337 \ |
| 114 | +torchrun --standalone --nproc_per_node=8 train_gpt.py |
| 115 | +``` |
| 116 | + |
| 117 | +## Legality |
| 118 | + |
| 119 | +- **Score-first n-gram cache**: Cache updated ONLY after scoring each sliding window batch. Tokens are never used before being evaluated. |
| 120 | +- **Order-adaptive gating uses only model entropy and cache statistics**: The matched n-gram order comes from already-scored token patterns. The entropy is computed from the model's own logits. No ground truth tokens are accessed for the mixing decision. |
| 121 | +- **No TTT**: This submission does not use test-time training. |
| 122 | +- **Training time**: 600s (within 10-minute cap). |
| 123 | +- **Artifact size**: 15,828,199 – 15,964,115 bytes across seeds (all within 16,000,000 byte cap). |
| 124 | + |
| 125 | +## Credits |
| 126 | + |
| 127 | +- **Base model + n-gram eval + GPTQ + full training stack**: PR #753 by @152334H (Podracing II) |
| 128 | +- **XSA**: PR #430 by @sahiee-dev (extended from last-4 to all layers) |
| 129 | +- **LeakyReLU^2**: PR #493 by @parinzee |
| 130 | +- **Parameter Banking + Parallel Muon**: PR #399 by @abaybektursun |
| 131 | +- **Order-adaptive entropy gating**: This submission |
| 132 | + |
| 133 | +## Included Files |
| 134 | + |
| 135 | +- `train_gpt.py` -- full training + quantization + n-gram evaluation script |
| 136 | +- `train.log` -- training log from seed 1337 |
| 137 | +- `submission.json` -- leaderboard metadata |
| 138 | +- `README.md` -- this file |
0 commit comments