Skip to main content

hf-mem

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.

Hugging FaceApache-2.0

SKILL.md

Written by Hugging Face and published in huggingface/skills under the Apache-2.0 license. Treq shows it unchanged except for heading levels and links to files on GitHub.

hf-mem

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.

When hf-mem runs

Claude Code and Codex keep each installed skill's name and description in context. When a request matches the description, the agent loads the full SKILL.md. You can also run it yourself: type /hf-mem in Claude Code or $hf-mem in Codex.

The description says when to use 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.

Install hf-mem

Claude Code

Copy the hf-mem folder into .claude/skills/ in your project. To use it in every project, copy it into ~/.claude/skills/ instead.

git clone --depth 1 https://github.com/huggingface/skills.git /tmp/huggingface-skills
mkdir -p .claude/skills
cp -r /tmp/huggingface-skills/skills/hf-mem .claude/skills/

Codex

Codex reads skills from .agents/skills/ in your repository, and from ~/.agents/skills/ for every repository. It detects new skills on its own. Restart Codex if hf-mem does not appear.

git clone --depth 1 https://github.com/huggingface/skills.git /tmp/huggingface-skills
mkdir -p .agents/skills
cp -r /tmp/huggingface-skills/skills/hf-mem .agents/skills/

Treq

Open Settings and select the Skills tab. The tab appears when Skills installation is on under Settings → Feature Preview. Search for hf-mem and choose Install….

Install for repository writes the skill under .treq/skills/ in the current repository. Install for application makes it available to every repository on this machine. Each new workspace gets a copy in .claude/skills/ and .agents/skills/, so Claude Code and Codex both find it. See Installing Skills from the Library.

Files

hf-mem ships one file, SKILL.md, shown above.

All skills by Hugging Face