"""Size Ripple-65B's KV cache, weights, pools and decode ceilings from its config.json and safetensors headers. Used for content/standalone/06-serving-in-production/13-ripple-65b-serving (2026-11-07). Runs on a laptop, standard library only, no GPU, no weight download: it reads config.json, the safetensors index and the safetensors *headers* (HTTP range requests, a few MB in all) from the Hugging Face repos at pinned revisions, and does the arithmetic. python3 ripple65b_kv.py # everything below, Ripple plus the two MoE comparisons python3 ripple65b_kv.py --config config.json # layer map and bytes per token from a local config only python3 ripple65b_kv.py --kv-gib 20 --max-model-len 131072 --max-num-batched-tokens 8192 # what vLLM's startup line should say for that KV memory Cache rules (vLLM @ 03bd3c6, vllm/model_executor/models/ricursive.py: `per_layer_sliding_window` only on "sliding_attention" layers; RoPE only there too): a full-attention layer stores K and V for every token (2 x 8 KV heads x 128 x 2 B = 4,096 B in BF16), a sliding layer for its last `sliding_window` tokens only. vLLM's pool (vllm/v1/core/kv_cache_planning.py, _get_kv_cache_groups_uniform_page_size): 16 full + 64 sliding layers -> 5 groups of 16 layers sharing one block pool; a block is 16 layers x block_size tokens x 4,096 B. Per request at max_model_len L it reserves cdiv(L, bs) blocks for the full group and, per sliding group, cdiv(min(window - 1 + max_in_flight_tokens, L), bs) + 1 (vllm/v1/kv_cache_interface.py, SlidingWindowSpec; max_in_flight_tokens = max_concurrent_batches x max_num_batched_tokens, and max_concurrent_batches is 2 with async scheduling on the V2 model runner at PP 1, vllm/config/vllm.py). The script prints both 1 and 2 batches in flight. The logged "GPU KV cache size" is max_concurrency x L (vllm/v1/core/kv_cache_utils.py, get_kv_cache_capacity). Decode ceilings are bandwidth only: one step reads every weight except the embedding table once, plus each sequence's cache (64 KiB per token of context in the full layers, min(L, window) x 4 KiB in each sliding layer). """ import argparse import json import math import struct import urllib.request RIPPLE = { "BF16": ("ricursiveAI/Ripple-65B-Preview", "da94cc013a8fda04a502f0a185083c7099ea06c1"), "NVFP4": ("ricursiveAI/Ripple-65B-Preview-NVFP4", "99eea4477a001a41b86914e41feb4b2ed86105e5"), "DFlash2": ("ricursiveAI/Ripple-65B-Preview-DFlash2", "35609b3be3dd08a822b3ba1257c1ea5dd6f87632"), } MOES = { # the twins at equal memory: same ssssF pattern (Kolibri-1), and the MoE we measured (quantizing-moe) "Kolibri-1 FP8": ("Aleph-Alpha/Kolibri-1", "abfe85f673fd79a3e1cdb98289e7a1c635345ee1"), "Qwen3.6-35B-A3B NVFP4 (NVIDIA)": ("nvidia/Qwen3.6-35B-A3B-NVFP4", "1355db6a052410cfd62085d94b58866fd0f2c3c5"), } # Memory per GPU (GB) and bandwidth (TB/s), vendor figures; GX10 = DGX Spark GB10 (128 GB unified, 121.6 GiB visible) DEVICES = {"GX10 (GB10)": (130.6, 0.273, 0.70), "H200": (141, 4.8, 0.90), "B200": (180, 8.0, 0.90), "B300": (288, 8.0, 0.90)} GX10_EFFECTIVE_TBS = 0.17 # weights read per second at batch 1, measured 160-190 GB/s in quantizing-moe (vLLM 0.32.0) PR_ACCEPTANCE = {"main before #65745 (NoPE layer rotated)": 4.98, "#65745 (no_rope_layers honored)": 7.34} GiB, MiB, KiB = 2**30, 2**20, 2**10 def fetch(url, rng=None): req = urllib.request.Request(url, headers={"Range": f"bytes={rng}"} if rng else {}) with urllib.request.urlopen(req) as r: return r.read() def hf(repo, rev, name): return f"https://huggingface.co/{repo}/resolve/{rev}/{name}" def config(repo, rev): c = json.loads(fetch(hf(repo, rev, "config.json"))) return c.get("text_config", c) | {"quantization_config": c.get("quantization_config")} def tensors(repo, rev): """name -> (dtype, shape, bytes) from every shard's header; no weights.""" try: shards = sorted(set(json.loads(fetch(hf(repo, rev, "model.safetensors.index.json")))["weight_map"].values())) except Exception: shards = ["model.safetensors"] out = {} for s in shards: url = hf(repo, rev, s) n = struct.unpack("