ApX 标志ApX 标志

趋近智

LLM 推理: 显存与性能计算器

推理时模型权重的精度。较低的精度使用更少的显存但可能会影响质量。

KV缓存精度。较低的精度可减少显存, 尤其适用于长序列。

硬件配置

选择GPU或自定义显存

GPU数量

1

并行推理的GPU数量

输入参数

批量大小:

1

每步同时处理的输入数 (影响吞吐量和延迟)

1
2
4
6
8

序列长度:

1,024

每个输入的最大token数; 影响KV缓存和激活 (也受注意力结构影响) 。

8K
16K
33K
66K
131K

并发用户数:

1

同时进行推理的用户数 (影响内存和每用户性能)

1
2
4
6
8

高级配置

推理模拟

(FP16 权重 / FP16 KV缓存) 16GB / 360 GB/s / 26 TFLOPS 自定义GPU

输入序列长度: 1,024 个token

配置模型和硬件以启用模拟

LLM Memory Allocation & Hardware Sizing Methodology

The ApX Calculator models GPU memory consumption, distributed cluster topologies, and inference latency using analytical formulas validated against empirical PyTorch, vLLM, and TensorRT-LLM execution traces.

1. Static Model Weight Allocation

Static resident VRAM depends on total parameter count, precision bit-width, and quantization tensor scale overhead.

VRAM_weights = (Parameters * Bits_per_Weight) / (8 * 1024³) * (1 + Overhead)

Precision formats supported include FP16/BF16 (16-bit), FP8 E4M3/E5M2 (8-bit), INT8 (8-bit), INT4/AWQ/GPTQ (4-bit + scale tensors), and GGUF quantization levels (Q2_K through Q8_0).

2. Dynamic KV Cache Allocation

KV cache scales with sequence length, concurrent batch size, and attention topology.

// MHA / GQA:
KV_Cache = 2 * Layers * KV_Heads * Head_Dim * Batch * Seq_Len * Bytes

// MLA (DeepSeek-V2 / V3):
KV_Cache = Layers * (d_c + d_R) * Batch * Seq_Len * Bytes

Accounts for Multi-Head Attention (MHA), Grouped-Query Attention (GQA), and Multi-Head Latent Attention (MLA) with latent KV compression.

3. Distributed Parallelism Topologies

Multi-GPU cluster configurations distribute memory and compute across nodes:

StrategyMemory DistributionPrimary Interconnect
Tensor Parallelism (TP)Splits weights and KV cache by N_TPNVLink / Intra-node
Pipeline Parallelism (PP)Partitions layers across nodesPCIe / InfiniBand
Expert Parallelism (EP)Distributes MoE routed expertsAll-to-All Fabric
Context Parallelism (CP)Segments long-context token sequencesRing Attention / Collective

4. Roofline Inference & Latency Modeling

Inference execution separates into compute-bound prefill and bandwidth-bound decode:

Prefill_Latency ≈ (2 * Params * Prompt_Tokens) / Effective_TFLOPS

Decode_Throughput ≈ GPU_Bandwidth_GBs / (Weights_GB + Active_KV_GB)

Simulates Time-to-First-Token (TTFT), tokens per second per stream, speculative decoding acceptance rates, and offloading latency across PCIe and NVMe buses.

Frequently Asked Technical Questions

What makes the ApX VRAM Calculator more accurate than basic parameter calculators?

Most basic tools only perform naive multiplication of parameter counts and bit-widths. The ApX VRAM & Infrastructure Calculator models full dynamic runtime allocations, including attention topology variations (MHA, GQA, and DeepSeek MLA), activation checkpoints, distributed multi-node parallelism splits (TP, PP, DP, EP, CP), quantization metadata scaling overhead, speculative decoding speedups, and real-world benchmarked execution constraints verified against vLLM and PyTorch.

How is KV cache calculated for Multi-Head Latent Attention (MLA)?

Unlike standard Multi-Head Attention (MHA) which stores separate key and value vectors for every head, MLA projects keys and values into a compressed latent space of dimension d_c (e.g. 512) and appends a decoupled rotary key vector d_R (e.g. 64). During generation, only (d_c + d_R) elements are retained in the KV cache per token per layer, reducing dynamic memory consumption by 80% to 90% compared to MHA.

What are the memory and bandwidth requirements for Tensor Parallelism?

Tensor Parallelism shards linear layer matrix multiplications across GPUs. Each forward pass requires two All-Reduce communications per transformer layer. Because of the frequent collective communication, Tensor Parallelism is typically constrained to GPUs connected via high-bandwidth intra-node links such as NVLink (900 GB/s on Hopper H100, 450 GB/s on Ampere A100).

How does fine-tuning VRAM differ between Full Parameter, LoRA, and QLoRA?

Full parameter fine-tuning with 32-bit AdamW requires approximately 16 to 18 bytes per parameter (2 bytes weights, 2 bytes gradients, 12 bytes optimizer states, plus activation memory). LoRA freezes base weights at 16-bit and allocates optimizer states only for rank-r adapter matrices. QLoRA further quantizes the base model to 4-bit NormalFloat (NF4), reducing base parameter footprint to ~0.55 bytes per parameter while maintaining 16-bit or 32-bit adapter training.

Why is autoregressive token generation memory-bandwidth bound?

During single-token decoding, every layer weight must be transferred from GPU VRAM to the compute registers to perform matrix-vector arithmetic with an arithmetic intensity close to 1 FLOP/byte. The maximum theoretical token generation speed is governed by GPU memory bandwidth divided by total active memory transferred per step.

How does the calculator size Mixture of Experts (MoE) models like DeepSeek-V3 or Mixtral?

For MoE architectures, all expert weights remain resident in memory across GPUs (or partitioned with Expert Parallelism EP). Dynamic computation FLOPs and active KV cache are calculated strictly based on the top-k activated experts per token, incorporating all-to-all dispatch overhead and shared attention layers.

Can I run large models (70B or 405B) on Apple Silicon Mac unified memory?

Apple Silicon Macs (e.g. M2/M3/M4 Max and Ultra with up to 128 GB or 192 GB) share system memory directly between CPU and GPU without PCIe bottlenecking. The calculator models macOS memory wiring limits, allowing sizing for 70B models at INT4/Q4_K_M (~40 GB footprint) to verify unified memory and bandwidth headroom.

How does ApX evaluate quantization formats like GGUF, AWQ, GPTQ, and FP8?

The integrated Accuracy & Perplexity Scorecard tracks exact memory savings alongside measured perplexity degradation on standard benchmarks (such as Wikitext-2 and C4), empirically evaluating the trade-off between VRAM reduction and output fidelity.

How do I calculate the minimum number of GPUs needed for a target tokens-per-second SLA?

Using roofline capacity modeling, the calculator divides the memory streamed per token by aggregate cluster memory bandwidth across Tensor Parallelism (TP) shards. The setup planner suggests optimal cluster dimensions or quantization formats if bandwidth limits fall short of latency SLAs.

性能与内存结果

0.0%

显存

就绪

0 GB

共 12 GB 显存

生成速度: ...

首个令牌时间: ~0ms

总吞吐量: ...

估算 GPU 租赁: 不适用