Build a memory and layout calculator
CPU · your Macscript120 minrequiredGoal · A Python script that, given a model config and GPU type, prints the weight and KV cache memory and recommends TP/PP/DP values.
- 1Write a function that reads a Hugging Face config.json and returns parameter count (check against the reported count for Llama-3-8B and 70B).
- 2Add KV cache bytes per token = 2 * n_layers * n_kv_heads * head_dim * bytes_per_elem; multiply by batch * context.
- 3Model GPUs as (memory_GB, intra_node_bw_GBps, inter_node_bw_GBps) for A10G 24 GB, A100 80 GB, H100 80 GB.
- 4Implement the rule search over TP in {1,2,4,8} and PP in {1,2,4} that keeps weights plus KV cache under 90 percent of memory, preferring the smallest TP, then the smallest PP.
- 5Estimate per-layer TP communication bytes as 2 * batch * d_model * bytes_per_elem per all-reduce and print total bytes per decode step.
- 6Run for Llama-3-8B at 8k context and Llama-3-70B at 32k context on each GPU type and tabulate the results.
- Deliverable
- layout_calc.py plus a markdown table of recommendations for six (model, GPU) pairs.
- Check
- Llama-3-70B bf16 reports about 140 GB of weights and is placed on TP=4 for 80 GB GPUs at 32k context (TP=2 leaves only ~4 GB under the 90 percent cap, less than one 32k sequence of KV at ~10.7 GB); Llama-3-8B fits on a single 24 GB GPU at short context but not at 8k with batch 32.