Works on this device
Local AI Model Resource Calculator
Find out whether a language model fits in the memory of your computer or graphics card. Type the model size, its precision and its shape, and see the memory for the weights, the KV cache and the total.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose Calculate.
Your result
How it was worked out
How to use this calculator
- Choose what you want to work out. Memory to run a model gives the total for weights and KV cache.
- Type the number of parameters in billions (an 8B model is 8) and choose the precision of the weights. For a quantized file, choose Other and type its bits per weight.
- Type the shape of the model from its
config.json: layers, key-value heads and head dimension. The last mode reads these numbers from the file for you. - Type your context length and, if you like, the memory of your graphics card or computer to see whether the model fits.
- The fields start empty: the numbers of models and cards change often, so this page keeps no list of them. Try an example fills in made-up example values.
- To see what a model file holds, choose Read the header of a .safetensors file or Read the header of a .gguf file and choose the file. Only its first 64 MB are read, in this browser, so a file of many gigabytes works too.
Reading the header of a model file
- A .safetensors file starts with 8 bytes that give the length of its header (a whole number, little-endian), then the header as JSON text, then the tensor data. The header names each tensor with its data type (such as BF16), its shape and where its data lies (
data_offsets), and may hold texts under__metadata__. - The tool lists the tensors, adds up their values (the parameter count) and their bytes, and gives the bits per weight = bytes × 8 ÷ parameters. It also says whether the tensors cover the data with no gap, and whether each tensor has as many bytes as its values need in its data type (for BOOL, U8, I8, F8_E5M2, F8_E4M3, I16, U16, F16, BF16, I32, U32, F32, I64, U64 and F64). You can copy or download the header as JSON.
- A .gguf file of GGUF version 3 starts with GGUF, the version, the number of tensors and of metadata entries, then each metadata entry (a key, a value type and a value), then each tensor (its name, dimensions, type and offset), then the tensor data after padding to the alignment (32 bytes unless
general.alignmentsays another number). - The tool lists every metadata entry with its type and value, and every tensor with its type (such as Q4_K), dimensions and number of values. Long texts are cut at 1,000 characters and an array shows its first 8 items; the table says how long each one is. Files of GGUF version 1 or 2, and big-endian files, are refused with a message.
- A model saved in several files has a header in each file. Read each file and add up the parameters.
The formulas
- Weights = parameters × bytes per weight. FP32 uses 4 bytes, FP16 and BF16 use 2, INT8 and FP8 use 1, and 4-bit formats use 0.5.
- Bits per weight of a quantized file = file size in bytes × 8 ÷ parameters. Formats such as the GGUF K-quants mix several bit sizes and add scale values, so their bits per weight are not a whole number. Work them out from your own file.
- KV cache = 2 × layers × key-value heads × head dimension × context length × sequences × bytes per value. The 2 stands for one key and one value vector.
- Grouped-query attention: several attention heads share one key-value head. A model with 32 attention heads and 8 key-value heads keeps a cache 4 times smaller than one where every head keeps its own.
- Upper bound of tokens per second = memory bandwidth ÷ bytes read for each new token. Each new token reads all the weights once (for a mixture-of-experts model, the active ones) and the KV cache so far.
Worked example
A model with 8 billion parameters at FP16 needs 8 × 2 = 16 GB for its weights. With 32 layers, 8 key-value heads, a head dimension of 128 and FP16 values, each token needs 2 × 32 × 8 × 128 × 2 = 131,072 bytes (128 KiB) of KV cache, so 8,192 tokens need exactly 1 GiB (1.07374 GB). The total is 17.0737 GB (15.9012 GiB). On a card with 24 GB it fits, with 6.92626 GB to spare.
With a memory bandwidth of 1,000 GB/s, the same model can make at most 1,000 ÷ 16 = 62.5 tokens per second. Real speed is lower.
The example .safetensors file of Try an example holds a tensor of F16 with the shape 4 × 2 (16 bytes) and one of F32 with the shape 2 (8 bytes): 10 values in 24 bytes, so 24 × 8 ÷ 10 = 19.2 bits per weight. The tensors cover the data with no gap.
Limits you should know
- Runtimes need extra memory for their own code, temporary buffers and activations. Add your own allowance under More options, or compare with what your runtime reports.
- The speed is an upper bound for one sequence at a time. Reading a long prompt is limited by computing power instead, and real runtimes never use the full bandwidth.
- GB means 1,000,000,000 bytes and GiB means 1,073,741,824 bytes. Choose the unit that matches the number you type.
- The header modes read only the header of a model file, never the tensor values, and only from the first 64 MB of the file. The parameter count is not worked out from config.json, because that depends on the details of each model family; read it from the header of the model file instead.
- The example values are made up for trying the tool. They are not the data of a particular model or card.