Toolvito

Works on this device

GPU Memory Calculator

Find out how much graphics card memory (VRAM) a model needs, to run it or to train it, and whether it fits on your cards. Every number comes from a stated formula.

Enter your values

Weights plus the KV cache, spread over one or more graphics cards.

Your values

The size of the model in billions of parameters, from its model card or file name (8B is 8). Example only.

The number format the weights are stored in when the model runs.

num_hidden_layers in the model’s config.json. Example only.

num_key_value_heads in config.json. With grouped-query attention it is smaller than the number of attention heads. Example only.

head_dim in config.json, or hidden_size ÷ num_attention_heads. Example only.

The number of tokens you plan to keep: prompt and answer together.

1 for one chat. More for a server that answers several requests at once.

Most runtimes keep the cache in FP16 or BF16 unless you choose a smaller type.

The number of cards that share the work.

The memory (VRAM) of one card, from the maker’s data sheet. Leave it blank for no check.

More options

Your own allowance for the runtime, temporary buffers and activations, as a share of weights and KV cache. It is a guess, not part of the formulas.

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.

How to use this calculator

  1. Choose GPU memory to run a model or GPU memory to train or fine-tune a model.
  2. Type the number of parameters in billions and choose the precision. Type the shape of the model from its config.json where the form asks for it.
  3. Type the number of graphics cards and the memory of one card from its data sheet to see whether it fits.
  4. The fields for models and cards start empty, because this page keeps no list of them. Try an example fills in made-up example values.

Memory to run a model

  • Weights = parameters × bytes per weight (FP32 4, FP16 or BF16 2, INT8 or FP8 1, 4-bit 0.5, or your own bits ÷ 8).
  • KV cache = 2 × layers × key-value heads × head dimension × context length × sequences × bytes per value.
  • Over several cards the total is divided evenly. Real splits are never quite even, so treat the share of each card as a lower limit.
  • For running a model on one computer, with an upper bound of the speed and a reader for config.json, see the Local AI Model Resource Calculator.

Memory to train a model

  • Model states for each parameter: weights, gradients and optimizer values. With mixed precision (FP16 or BF16) and Adam this is 2 + 2 bytes plus an FP32 master copy (4) and two FP32 Adam values (4 + 4): 16 bytes for each parameter. This is the count in the ZeRO paper by Rajbhandari and others (2020).
  • FP32 training with Adam also gives 16 bytes (4 + 4 + 4 + 4). SGD with momentum keeps one value for each parameter, plain SGD none.
  • ZeRO sharding divides parts of the model states over the cards: stage 1 the optimizer values and the master copy, stage 2 the gradients too, stage 3 the weights too.
  • Activations of each transformer layer, by the formula of Korthikanti and others (2022): s·b·h·(34 + 5·a·s ÷ h) bytes, where s is the sequence length, b the micro-batch size, h the hidden size and a the number of attention heads. With selective recomputation it is 34·s·b·h, with full recomputation 2·s·b·h. The formula counts 16-bit values without tensor or sequence parallelism and leaves out the embedding and output layers. You can also type your own measured number.

Worked example

Training a model of 7 billion parameters with mixed precision and Adam needs 7 × 16 = 112 GB for the model states. With 32 layers, a hidden size of 4,096, 32 attention heads, a sequence of 2,048 tokens and a micro-batch of 1, the activations are 2,048 × 4,096 × (34 + 5 × 32 × 2,048 ÷ 4,096) = 956,301,312 bytes for each layer, or 30.6016 GB for 32 layers. Each card then needs 142.602 GB, which does not fit on an 80 GB card.

With ZeRO stage 3 over 8 cards, the model states take 112 ÷ 8 = 14 GB on each card, so each card needs 44.6016 GB.

Limits you should know

  • Frameworks need extra working memory, and memory can break into pieces that cannot be used. Leave some room.
  • Fine-tuning methods that train only a few added parameters (such as LoRA), offloading to the CPU, and tensor or pipeline parallelism are not worked out here.
  • GB means 1,000,000,000 bytes and GiB means 1,073,741,824 bytes. Choose the unit that matches the number on your data sheet.
  • The example values are made up for trying the tool. They are not the data of a particular model or card.

Related tools