Deploying Large Language Models (LLMs) requires careful consideration of GPU memory requirements. This guide breaks down the mathematical formulas used to calculate VRAM consumption for both inference and training, using the Qwen3-VL-32B-Instruct model as a practical example.
Why VRAM Calculation Matters
Before deploying an LLM, you need to answer critical questions:
- How much GPU memory will my model consume?
- Can I run this model on my current hardware?
- Which quantization method provides the best memory-performance tradeoff?
- How many concurrent users can I support?
This guide provides the mathematical foundation to answer these questions accurately.
Example Model: Qwen3-VL-32B-Instruct
We'll use Qwen3-VL-32B-Instruct as our reference model throughout this guide. This multimodal model combines vision and language capabilities with the following architecture:
| Parameter | Value | Description |
|---|---|---|
| Model Parameters | 33.4 billion | Total parameters (33,357,390,064 per HF safetensors) |
| Hidden Size | 5,120 | Dimension of hidden representations |
| Intermediate Size | 25,600 | FFN intermediate dimension (5x hidden size) |
| Number of Layers | 64 | Total transformer blocks |
| Attention Heads | 64 | Number of query attention heads |
| KV Heads | 8 | Number of key-value heads (GQA) |
| Head Dimension | 128 | Dimension per attention head |
| Max Context Length | 262,144 | Maximum sequence length (256k tokens) |
| Architecture | Grouped Query Attention | Uses GQA for efficient inference |
Configuration Source: The model configuration is extracted from the text_config section of the model's config.json file on Hugging Face Hub.
Core Memory Components
VRAM consumption for LLMs consists of four primary components:
1. Model Weights Memory
The base memory required to store the model's parameters.
Model Weights (bytes) = Number of Parameters Γ Bytes per Parameter
Bytes per Parameter depends on the data type (quantization level):
| Data Type | Bytes per Parameter | Precision |
|---|---|---|
| float32 | 4 bytes | Full precision |
| float16/bfloat16 | 2 bytes | Half precision |
| int8/fp8 | 1 byte | 8-bit quantization |
| int4/fp4 | 0.5 bytes | 4-bit quantization |
Example Calculation for Qwen3-VL-32B:
Number of Parameters: 33,357,390,064 (~33.4B)
float32: 33,357,390,064 Γ 4.0 = 133,429,560,256 bytes = 133.43 GB
float16: 33,357,390,064 Γ 2.0 = 66,714,780,128 bytes = 66.71 GB
int8: 33,357,390,064 Γ 1.0 = 33,357,390,064 bytes = 33.36 GB
int4: 33,357,390,064 Γ 0.5 = 16,678,695,032 bytes = 16.68 GB
2. KV Cache Memory
The Key-Value cache stores intermediate attention states for efficient autoregressive generation. This is the most significant dynamic memory component during inference.
KV Cache (bytes) = 2 Γ Batch Size Γ Sequence Length Γ Num Layers Γ Num KV Heads Γ Head Dimension Γ KV Data Type Size
Breaking Down the Formula:
- 2Γ: Separate storage for Keys and Values
- Batch Size: Number of concurrent requests
- Sequence Length: Maximum context length (input + output)
- Num Layers: Number of transformer blocks
- Num KV Heads: Number of key-value heads (8 for GQA in Qwen3-VL)
- Head Dimension: Size of each attention head (128)
- KV Data Type Size: Bytes per value (typically 2 for float16)
Example Calculation for Qwen3-VL-32B:
Scenario: 1 user, 8,192 token context, float16 KV cache
Batch Size: 1
Sequence Length: 8,192 tokens
Num Layers: 64
Num KV Heads: 8 (Grouped Query Attention)
Head Dimension: 128
KV Data Type: float16 (2 bytes)
KV Cache = 2 Γ 1 Γ 8,192 Γ 64 Γ 8 Γ 128 Γ 2
= 2 Γ 1 Γ 8,192 Γ 64 Γ 8 Γ 256
= 2 Γ 1,073,741,824 bytes
= 2,147,483,648 bytes
= 2.15 GB (decimal; = 2.00 GiB binary)
Scaling with Batch Size:
| Batch Size | Users | KV Cache Memory (float16) |
|---|---|---|
| 1 | 1 concurrent user | 2.15 GB |
| 4 | 4 concurrent users | 8.59 GB |
| 8 | 8 concurrent users | 17.18 GB |
| 16 | 16 concurrent users | 34.36 GB |
Scaling with Sequence Length:
| Sequence Length | Context Size | KV Cache Memory (batch=1, float16) |
|---|---|---|
| 2,048 | 2k tokens | 0.54 GB |
| 8,192 | 8k tokens | 2.15 GB |
| 32,768 | 32k tokens | 8.59 GB |
| 131,072 | 128k tokens | 34.36 GB |
3. Activation Memory
Memory required for intermediate computations during forward passes.
PyTorch Activation Memory = Batch Size Γ Sequence Length Γ (18 Γ Hidden Size + 4 Γ Intermediate Size)
Example Calculation for Qwen3-VL-32B:
Scenario: 1 user, 8,192 token context
Batch Size: 1
Sequence Length: 8,192
Hidden Size: 5,120
Intermediate Size: 25,600
Activation Memory = 1 Γ 8,192 Γ (18 Γ 5,120 + 4 Γ 25,600)
= 8,192 Γ (92,160 + 102,400)
= 8,192 Γ 194,560
= 1,593,835,520 bytes
= 1.59 GB (base value)
Data Type Multipliers:
Different quantization levels have different activation memory footprints:
| Data Type | Multiplier | Effective Activation Memory |
|---|---|---|
| float32 | 2.0Γ | 1.59 Γ 2.0 = 3.19 GB |
| float16/bfloat16 | 1.0Γ | 1.59 Γ 1.0 = 1.59 GB |
| int8/fp8 | 1.0Γ | 1.59 Γ 1.0 = 1.59 GB |
| int4/fp4 (weight-only) | 1.0Γ | 1.59 Γ 1.0 = 1.59 GB |
4. Non-PyTorch Memory Overhead
System-level memory overhead for CUDA context, cuBLAS, and other framework components.
Non-PyTorch Memory β 1.00 GB (constant)
This is a fixed overhead independent of model size or batch configuration. The interactive calculator models it slightly differently: 1.2 GB scaled by the quantization format's overhead factor (see below), i.e. ~1.26 GB for int8.
Complete Inference Memory Formula
Combining all components, the total VRAM required for inference:
Total Inference VRAM = (Model Weights + KV Cache + Non-PyTorch Memory + Activations) / GPU Utilization
GPU Utilization Factor: Typically set to 0.9 (90%) to provide safety margin for memory fragmentation and unexpected spikes.
Note (matching the interactive calculator): The worked examples on this page use this hand-planning convention. The calculator at the top of the tool page instead (a) multiplies weight bytes by a per-format overhead factor for scale/zero-point storage β fp8 Γ1.03, int8 Γ1.05, NVFP4 Γ1.1, int4/AWQ Γ1.12 β (b) models the non-PyTorch overhead as 1.2 GB Γ that factor, and (c) does not divide by a utilization factor (its "Hardware Utilization" slider only derates bandwidth/throughput, never capacity). Expect the tool's int8/8k/batch-1 figure (~39 GB) to differ modestly from the hand calculation (~42 GB); both are conservative estimates, not guarantees.
Example: Qwen3-VL-32B Inference (int8 quantization)
Configuration:
- Quantization: int8 (1 byte per parameter)
- Batch Size: 1 user
- Sequence Length: 8,192 tokens
- KV Cache Data Type: float16
- GPU Utilization: 0.9
Step-by-Step Calculation:
1. Model Weights:
33,357,390,064 Γ 1 byte = 33,357,390,064 bytes = 33.36 GB
2. KV Cache (float16):
2 Γ 1 Γ 8,192 Γ 64 Γ 8 Γ 128 Γ 2 = 2,147,483,648 bytes = 2.15 GB
3. Activations (int8 uses 1.0Γ multiplier):
1 Γ 8,192 Γ (18 Γ 5,120 + 4 Γ 25,600) Γ 1.0 = 1,593,835,520 bytes = 1.59 GB
4. Non-PyTorch Memory:
β 1.00 GB
5. Total (before GPU utilization adjustment):
33.36 + 2.15 + 1.59 + 1.00 = 38.10 GB
6. Adjusted for GPU Utilization (90%):
38.10 / 0.9 = 42.33 GB
Result: You need approximately 42 GB of VRAM to run Qwen3-VL-32B in int8 quantization with 8k context for a single user.
Example: Qwen3-VL-32B Inference (int4 quantization)
Configuration:
- Quantization: int4 (0.5 bytes per parameter)
- Batch Size: 4 users
- Sequence Length: 8,192 tokens
- KV Cache Data Type: float16
- GPU Utilization: 0.9
Step-by-Step Calculation:
1. Model Weights:
33,357,390,064 Γ 0.5 bytes = 16,678,695,032 bytes = 16.68 GB
2. KV Cache (float16, batch=4):
2 Γ 4 Γ 8,192 Γ 64 Γ 8 Γ 128 Γ 2 = 8,589,934,592 bytes = 8.59 GB
3. Activations (int4 uses 1.0Γ multiplier, batch=4):
4 Γ 8,192 Γ (18 Γ 5,120 + 4 Γ 25,600) Γ 1.0 = 6,375,342,080 bytes = 6.38 GB
4. Non-PyTorch Memory:
β 1.00 GB
5. Total (before GPU utilization adjustment):
16.68 + 8.59 + 6.38 + 1.00 = 32.65 GB
6. Adjusted for GPU Utilization (90%):
32.65 / 0.9 = 36.28 GB
Result: You need approximately 36 GB of VRAM to run Qwen3-VL-32B in int4 quantization with 8k context for 4 concurrent users.
Training Memory Requirements
Training requires significantly more memory than inference due to:
- Gradients: Same size as model weights
- Optimizer States: 2Γ model weights (for Adam optimizer)
- Larger Activation Memory: ~1.5Γ inference activations
- Training Overhead: 30% safety buffer
Note (assumptions): The training memory calculations in this section assume a standard inβGPU training setup and do NOT apply memory-saving or bandwidth-optimizing techniques such as CPU/NVMe offloading, sliding-window or chunked attention, specialized lowβmemory optimizers or ZeRO-style partitioning, aggressive gradient checkpointing beyond the basic multiplier used above, or custom attention kernels that change KV storage. If you plan to use any of these methods, expected VRAM requirements can be materially lower and should be recalculated for your specific setup.
Breakdown:
- 3Γ Model Weights: Weights + Gradients + Optimizer States (Adam)
- 1.3Γ: Training overhead factor (30% buffer)
Example: Qwen3-VL-32B Training (float16)
Configuration:
- Quantization: float16 (2 bytes per parameter)
- Batch Size: 1
- Sequence Length: 8,192 tokens
- GPU Utilization: 0.9
Step-by-Step Calculation:
1. Model Weights (Γ3 for training):
33,357,390,064 Γ 2 bytes Γ 3 = 200,144,340,384 bytes = 200.14 GB
2. KV Cache (float16):
2 Γ 1 Γ 8,192 Γ 64 Γ 8 Γ 128 Γ 2 = 2,147,483,648 bytes = 2.15 GB
3. Activations (float16 uses 1.0Γ multiplier, Γ1.5 for training):
1 Γ 8,192 Γ (18 Γ 5,120 + 4 Γ 25,600) Γ 1.0 Γ 1.5 = 2,390,753,280 bytes = 2.39 GB
4. Non-PyTorch Memory:
β 1.00 GB
5. Subtotal:
200.14 + 2.15 + 2.39 + 1.00 = 205.68 GB
6. Apply Training Overhead (Γ1.3):
205.68 Γ 1.3 = 267.38 GB
7. Adjusted for GPU Utilization (90%):
267.38 / 0.9 = 297.09 GB
Result: You need approximately 297 GB of VRAM to train Qwen3-VL-32B in float16 with 8k context and batch size 1.
GPU Memory Comparison Table
Here's a comprehensive comparison for Qwen3-VL-32B across different quantization methods:
| Quantization | Weights | KV Cache | Activations | Overhead | Total Inference | Total Training |
|---|---|---|---|---|---|---|
| float32 | 133.43 GB | 2.15 GB | 3.19 GB | 1.00 GB | 155.30 GB | 589.66 GB |
| float16 | 66.71 GB | 2.15 GB | 1.59 GB | 1.00 GB | 79.39 GB | 297.09 GB |
| int8 | 33.36 GB | 2.15 GB | 1.59 GB | 1.00 GB | 42.33 GB | 152.56 GB |
| int4 | 16.68 GB | 2.15 GB | 1.59 GB | 1.00 GB | 23.80 GB | 80.28 GB |
Configuration: Batch size 1, Sequence length 8,192 tokens, GPU utilization 0.9
Practical GPU Recommendations
Based on the calculations above, here are suitable GPU configurations for Qwen3-VL-32B:
Inference Deployment
| Quantization | Required VRAM | Recommended GPUs | Use Case |
|---|---|---|---|
| int4 (24 GB) | 32 GB comfortable | 1Γ RTX 5090 (32 GB) or RTX PRO 6000 (96 GB) | Cost-effective inference |
| int8 (42 GB) | 48 GB minimum | 1Γ L40S (48 GB) or RTX PRO 6000 (96 GB) | Higher quality inference |
| float16 (79 GB) | 96 GB tight / 141 GB with headroom | 1Γ RTX PRO 6000 Blackwell (96 GB) or 1Γ H200 (141 GB) | Full precision inference |
Training Deployment
| Quantization | Required VRAM | Recommended GPUs | Configuration |
|---|---|---|---|
| int4 (80 GB) | 141 GB | 1Γ H200 (141 GB) | Single GPU training |
| int8 (153 GB) | 282 GB | 2Γ H200 (141 GB) | Multi-GPU training |
| float16 (297 GB) | 423 GB | 3Γ H200 (141 GB) | Full precision training |
Key Takeaways
- Model Weights Scale Linearly: Doubling parameters doubles weight memory
- KV Cache Scales with Context: KV cache memory grows linearly with context length
- Batch Size Multiplies KV Cache: Each concurrent user adds KV cache overhead
- Quantization Dramatically Reduces Memory: int4 uses ~1/8th the memory of float32
- Training Needs ~3-4Γ Inference Memory: Due to gradients and optimizer states
- GPU Utilization Buffer is Critical: Always reserve 10-20% safety margin
Advanced Considerations
Grouped Query Attention (GQA) Impact
Qwen3-VL-32B uses Grouped Query Attention with 8 KV heads instead of 64 query heads. This reduces KV cache memory by 8Γ compared to standard Multi-Head Attention:
Standard MHA: 64 KV heads β KV Cache = 17.18 GB (8k context, float16)
GQA (Qwen3): 8 KV heads β KV Cache = 2.15 GB (8k context, float16)
Memory Savings: 15.03 GB (87.5% reduction)
Long Context Scaling
Qwen3-VL-32B supports up to 262k tokens. Here's how KV cache scales:
| Context Length | KV Cache (float16, batch=1) | Recommended VRAM |
|---|---|---|
| 8k tokens | 2.15 GB | 48 GB GPU |
| 32k tokens | 8.59 GB | 64 GB GPU |
| 128k tokens | 34.36 GB | 96 GB GPU |
| 256k tokens | 68.72 GB | 128 GB GPU |
KV Cache Quantization
Using fp8 for KV cache can halve memory usage:
float16 KV Cache (8k, batch=1): 2.15 GB
fp8 KV Cache (8k, batch=1): 1.07 GB
Savings: 50% memory reduction with minimal quality loss
Conclusion
Accurate VRAM calculation is essential for efficient LLM deployment. By understanding the mathematical foundations:
- Choose the right quantization for your quality-memory tradeoff
- Plan for KV cache scaling with concurrent users and context length
- Budget for training overhead if fine-tuning
- Select appropriate GPUs based on actual requirements
- Always include safety margins to prevent OOM errors
Use these formulas to estimate memory requirements for any Hugging Face model by extracting configuration parameters and applying the calculations shown in this guide.
Related
- LLM Inference Math: From Theory to Hardware β the compute side of the same roofline.
- LLM Inference Calculator & Break-Even Analyzer β run the numbers for your model and card.
References and Tools
- Model Configuration: Qwen3-VL-32B-Instruct config.json
- Hugging Face Hub: Model metadata and parameter counts available via API
- GPU Specifications: Check manufacturer specifications for exact VRAM capacities
- Quantization Methods: GPTQ, AWQ, GGUF for different precision levels