GPT-2 by Ciro Santilli 37 2025-08-08
The following is for a "classic" GPT-2-style model, the following estimates the number attention multiplications.
For each layer (L):
So the total sum is:
L * (
  h * (
    2 * d_model * d_head +
    n_ctx * d_head +
    d_model * d_model +
    n_ctx * d_model
  ) +
  2 * d_model * d_ff
)
This is coded at: llm_count_mults.py.
This example attempts to keep temperature to a fixed point by turning on a fan when a thermistor gets too hot.
You can test it easily if you are not in a place that is too hot by holding the thermistor with your finger to turn on the fan.
You can use a simple LED to represent the fan if you don't have one handy.
In Ciro's ASCII art circuit diagram notation:
            +----------FAN-----------+
            |                        |
            |                        |
RPI_PICO_W__gnd__gpio26Adc__3.3V@36__gpio2
            |    |          |
            |    |          |
            |    |          |
            |    +-THERMISTOR
            |    |
            |    |
            R_10-+
For inferencing just a single prompt, things appear to be very obviously memory bound, i.e. bound by the transfer speeds of VRAM to GPU cache for loading model parameters into GPU so they can be used, supposing that the model fits in VRAM, which is the case for many popular models.
It is however possible to make fuller utilization of the GPU's compute power by running multiple independent queries in parallel, this way you load the subset of model weights that you need, and then use those to do part of the inference for multiple input prompts. With this it should be possible to reach full utilization.
LLM inference batching means running multiple independent queries in parallel on a given model.
This can be used to overcome the fact that most single prompt inference will be heavily memory bound, see also: Section "Theoretical peak performance of GPT inference". Batching helps increase the GPU compute utilization and balance it out with the memory.
This section discusses techniques that can be used to make LLMs infer with lower latency or greater throughput.
In discrete GPUs, VRAM is RAM memory that lives on the GPU's PCB.
They are located in separate chips to the GPU's compute, since just like for CPUs, you can't put both on the same chip as the manufacturing processes are different and incompatible.
Integrated GPUs don't have VRAM and just instead use the same RAM as the CPU.

There are unlisted articles, also show them or only show them.