Skill Press

No. 532 · hf-mem

Estimate GPU Memory for a Model

A field guide from Hugging Face

Hugging Face

When to use it

Estimate the GPU memory needed to run a Hugging Face model (weights, KV cache and inference overhead) and whether it fits on given GPUs, without downloading it. Use when asked how much VRAM a model needs, whether it fits on a GPU, the longest context that fits, or which GGUF quantization to pick.

Rank
No. 532 of 971
Installs
Not listed yet
Runs in
Claude, Codex, Gemini, Cursor
Length
247 words · 1 min
Files
3
License
MIT

Get this skill

Download the skill folder (.zip, 6 KB) ↓ · SKILL.md only ↓

Agent prompt

Paste into a coding agent with terminal access. Check the upstream requirements for the skill you’re installing.

Prompt
Install the "hf-mem" Agent Skill by Hugging Face, from https://github.com/huggingface/skills.

1. Fetch the whole folder skills/hf-mem — SKILL.md plus every script, reference, and asset beside it, not just SKILL.md. For example:
   skill_checkout=$(mktemp -d)
   git init "$skill_checkout"
   git -C "$skill_checkout" fetch --depth 1 https://github.com/huggingface/skills.git 5291c2b9365e06b175dc04817610c778623f4836
   git -C "$skill_checkout" checkout --detach FETCH_HEAD
2. Copy it into your skills directory as a folder named "hf-mem":
   - Claude Code: ~/.claude/skills/hf-mem/ (all projects) or .claude/skills/hf-mem/ (this project only)
   - Another agent: the directory you load Agent Skills from (folders containing a SKILL.md)
3. Check that hf-mem/SKILL.md exists and its frontmatter says name: hf-mem.
4. Read SKILL.md, then tell me in two or three sentences what the skill does and when it will trigger, and list any dependencies it mentions (Python packages, npm packages, CLIs) that aren't installed yet. Don't install them without asking.

skills CLI

One command; the skills.sh installer detects your agents (Claude Code, Cursor, Codex, and more).

Terminal
npx skills add https://github.com/huggingface/skills/tree/5291c2b9365e06b175dc04817610c778623f4836/skills/hf-mem --skill hf-mem

Claude.ai

Upload the .zip as a custom skill.

  1. In Settings → Capabilities, turn on “Code execution and file creation”.
  2. Download the .zip above.
  3. Go to Customize → Skills, click + → Create skill → Upload a skill, and choose it.
Anthropic’s guide to using skills ↗

The skill, in full

uvx hf-mem <model> -o json [options]

<model> is a Hub ID (org/name, org/name@revision), a Hub URL, a local path, or org/name-GGUF:Q4_K_M for one GGUF quantization.

Options:

  • --gpu-memory 24 (GiB per GPU) or 8x80 (8 GPUs): adds fit.
  • --max-model-len N: context length, defaults to the model’s maximum, which can dominate the total.
  • --batch-size N: concurrent sequences, defaults to 1.
  • --kv-cache-dtype fp8 (vLLM names for Safetensors, llama.cpp cache types such as q8_0 for GGUF).
  • --file <file or variant> and --format safetensors|gguf|onnx to pick the weights.
  • --max-num-batched-tokens 2048 on A100s.
  • Gated or private models need HF_TOKEN or --hf-token.

JSON (sizes in bytes, divide by 2^30 for GiB):

  • total is the GPU memory for one copy of the model: weights + kv_cache + overhead (vLLM for Safetensors, llama.cpp for GGUF, none for ONNX).
  • offloaded are weights the engine keeps in CPU memory: excluded from weights and total, but needed as free system RAM.
  • fit (with --gpu-memory): fits, needed GPUs, max_model_len (the longest context that fits), and the required vs usable memory across the given GPUs. Use required / GPUs for the memory per GPU, not total / GPUs, as each GPU also holds its own overhead and replicated KV cache.
  • GGUF and ONNX repositories with several files return a files list to compare quantizations; pick one with :TAG or --file to get fit.
  • Report warnings to the user, and errors explain how to fix them.

More in Machine Learning

All Machine Learning skills →

More from Hugging Face

From huggingface/skills at 5291c2b, MIT. Install counts from skills.sh.