How does it work? Jak to funguje?
The calculator works with the model's own metadata straight from its Hugging Face repository. Everything runs in your browser; nothing is sent anywhere except the public read requests to Hugging Face. (For that reason, gated/private models unfortunately can't be loaded.)
- Weights: To work out how much the model's weights
take, we sum the sizes of the weight files (
.safetensors/.gguf) straight from the repo. Because we use the real file sizes, any quantization (AWQ, GPTQ, GGUF, fp8…) is already accounted for. - KV cache: Each token is stored as a key and a value
in every layer, so per token the cost is
2 × n_kv_heads × head_dim × bytes. We multiply by the number of layers, the context length, and the batch size. Grouped-query attention (fewern_kv_headsthan query heads) shrinks it; the KV cache switch sets the bytes per value (fp16 = 2, fp8 = 1, int4 = 0.5). The rest is read straight fromconfig.json. - Hybrid-attention correction: Models with hybrid attention keep the full context only on their few global layers; the other (local) layers store just a fixed window (e.g. 1024 tokens). We split the layers accordingly, so their KV cache is much smaller (most calculators miss this and overestimate at long context).
- Overhead: A rough flat ~1 GB for the CUDA context and activation buffers. Real usage also depends on the inference engine (vLLM, llama.cpp…) and memory fragmentation. So treat the result as a ballpark only.
Kalkulačka pracuje s informacemi o modelu přímo z Hugging Face repozitáře. Vše běží ve vašem prohlížeči; nikam se nic neposílá kromě veřejných požadavků na Hugging Face. (Z tohoto důvodu bohužel nelze načíst gated/soukromé modely.)
- Váhy: Pro výpočet toho, kolik zaberou váhy modelu,
se sečte velikost souborů s vahami (
.safetensors/.gguf) přímo z repozitáře. Protože pracujeme se skutečnou velikostí souborů, je jakákoli kvantizace (AWQ, GPTQ, GGUF, fp8…) už započítaná. - KV cache: Každý token se v každé vrstvě ukládá jako
klíč a hodnota, takže na jeden token je cena
2 × n_kv_heads × head_dim × bajty. Vynásobíme počtem vrstev, délkou kontextu a velikostí dávky (batch). Grouped-query attention (méněn_kv_headsnež dotazovacích hlav) ji zmenšuje; přepínač KV cache nastavuje počet bajtů na hodnotu (fp16 = 2, fp8 = 1, int4 = 0,5). Zbytek je načten přímo zconfig.json. - Korekce pro hybridní attention: Modely s hybridní attention pracují s celkovým kontextem jen na několika globálních vrstvách; ostatní (lokální) vrstvy ukládají pouze pevné okno (např. 1024 tokenů). Vrstvy podle toho rozdělíme, takže jejich KV cache je výrazně menší (na to většina kalkulaček zapomíná a při dlouhém kontextu odhad zbytečně přestřelí).
- Režie: Hrubý paušál ~1 GB na CUDA kontext a aktivační buffery. Skutečná spotřeba navíc závisí na inferenčním enginu (vLLM, llama.cpp…) a fragmentaci paměti. Výsledek je tedy pouze orientační.