"""Tables that depend on manifests/evidence rather than trial outcomes: taxonomy, models, datasets, coverage.""" from __future__ import annotations import json, pandas as pd from pathlib import Path from ..util import ROOT, read_json, write_json, utc_now TAB = ROOT / "results/tables" TAXONOMY = [ # id, representation, access regime, training, compatibility, composable (fan-in), status ("A0", "none (task only)", "n/a", "none", "any", "n/a", "measured"), ("A1", "raw text", "blind", "none", "any receiver", "concatenation", "measured"), ("A2", "text head/tail", "blind", "none", "any", "concatenation", "measured"), ("A3", "extractive sentences (BM25/centrality)", "blind or aware", "none", "any", "concatenation", "measured"), ("A4", "abstractive summary", "blind or aware", "none (prompted sender)", "any", "concatenation", "measured"), ("A5", "typed facts + source spans + unknowns (JSON)", "blind or aware", "none (prompted sender)", "any", "record merge", "measured"), ("A6", "reference index + metered retrieval", "blind index, aware retrieval", "none", "any + source access", "shared memory", "measured"), ("A7", "raw text, zstd transport codec", "blind", "none", "any", "concatenation", "measured"), ("A8", "LLMLingua-2 token dropping", "blind", "pretrained compressor (official)", "any", "concatenation", "measured"), ("B0", "native bf16 KV cache", "blind", "none", "same checkpoint", "no", "measured"), ("B1", "serialized KV cache (manifest-checked)", "blind", "none", "same checkpoint + revision", "no", "measured (process + 2-node)"), ("B2", "packed quantized KV (8/4/2 bit)", "blind", "none", "same checkpoint", "no", "measured"), ("B3", "sink+recent retention (StreamingLLM-inspired)", "blind", "none", "same checkpoint", "no", "measured"), ("B4", "random retention (control)", "blind", "none", "same checkpoint", "no", "measured"), ("B5", "attention-informed retention (SnapKV rule)", "aware (blind variant tested)", "none", "same checkpoint", "no", "measured"), ("B6", "pyramid layer budgets (PyramidKV rule)", "aware", "none", "same checkpoint", "no", "measured"), ("B9", "selection then packed quantization", "aware", "none", "same checkpoint", "no", "measured"), ("C0", "sender cache fed as receiver cache", "blind", "none", "incompatible (negative control)", "no", "measured (control)"), ("C2", "linear KV mapper (ridge, un-rotated K/V)", "blind", "ridge on train caches", "trained pair (Qwen 1.5B→3B)", "no", "measured"), ("C3", "mapper + attention selection", "aware", "ridge on train caches", "trained pair", "no", "measured"), ("—", "SwaT cross-family mapper", "blind", "~300M mapper (not public)", "Granite→SmolLM", "no", "not run: no checkpoint/licence"), ("—", "Attention-Matching compaction", "blind", "none (optimization)", "same model", "no", "not run: CUDA/vLLM code; MLX port out of scope"), ("—", "C2C fuser", "blind", "released fusers (Qwen3)", "Qwen3 receivers", "no", "not run: CUDA; receiver still prefills source"), ("—", "H2O eviction", "cumulative", "none", "same checkpoint", "no", "not run: requires attention scores during whole prefill"), ("—", "KIVI per-channel key quantization", "blind", "none", "same checkpoint", "no", "not run: CUDA kernels; motivation confirmed by B2 Qwen result"), ] def taxonomy(): t = pd.DataFrame(TAXONOMY, columns=["id", "representation", "question_access", "training", "compatibility", "composable", "status_in_wp30"]) t.to_csv(TAB / "table1_taxonomy.csv", index=False); return t def models(): ev = read_json(ROOT / "evidence/models.json") rows = [] for alias, m in ev["models"].items(): rows.append({"alias": alias, "repo": m["repo_id"], "revision": m["revision"][:12], "family": m["model_type"], "layers": m["num_layers"], "kv_heads": m["num_kv_heads"], "q_heads": m["num_attention_heads"], "head_dim": m["head_dim"], "weights": m["weight_dtype"], "max_pos": m["max_position_embeddings"], "rope_theta": m["rope_theta"], "cache_bytes_per_token_bf16": 2 * m["num_layers"] * m["num_kv_heads"] * m["head_dim"] * 2, "prefill_ms_8k": round(m["context_lengths"]["8192"]["prefill_ms"]), "prefill_ms_16k": round(m["context_lengths"]["16384"]["prefill_ms"]), "mlx": m["mlx_version"], "mlx_lm": m["mlx_lm_version"]}) t = pd.DataFrame(rows); t.to_csv(TAB / "table2_models.csv", index=False); return t def datasets(): man = read_json(ROOT / "data/manifests/splits.json"); df = pd.DataFrame(man["items"]) g = df.groupby(["family", "split"]).agg(documents=("document_id", "count"), questions=("n_questions", "sum"), median_chars=("char_len", "median")).reset_index() g.to_csv(TAB / "table3_datasets.csv", index=False); return g def main(): TAB.mkdir(parents=True, exist_ok=True) taxonomy(); models(); datasets(); print("static tables written") if __name__ == "__main__": main()