hf-mem

Hugging Face CLI to estimate the required memory to load Safetensors or GGUF model weights for inference from the Hugging Face Hub

By huggingface · 645 installs

npx skills add huggingface/skills --skill hf-mem

Source repository · Upstream listing

hf mem estimates the required memory for inference, including model weights and an optional KV cache, for Safetensors and GGUF for models on the Hugging Face Hub using HTTP Range requests i.e., without downloading or loading any weights locally. When to use? User asks how much VRAM or memory a model needs to run User wants to know if a model fits on their GPU or a given instance User references a Hugging Face model ID or URL and asks about inference requirements What are the requirements? uv installed (for uvx ) HF TOKEN env var or hf token flag (for gated or private models only) How to run? Run with model id pointing to the Hugging Face Hub repository which will check that it either contains Safetensors (via model.safetensors , model.safetensors.index.json if sharded, or model index.json for Diffusers) or GGUF model weights within. If the repository contains GGUF model weights in multiple precisions / quantizations, the estimations will be on a per file basis, whereas for inference you won't load all of those but rather only a single precision. This being said, for GGUF you might as well need to provide gguf file to target the specific file (or path if sharded) you want to run. Additionally, hf mem comes with an experimental flag that will also calculate the KV cache memory requirements too, useful for large language models, meaning it applies to LLMs ( ...ForCausalLM ), VLMs ( ...ForConditionalGeneration ), and GGUF models. As per the context window, it will be read from the default or overridden with max model len a la vLLM. And, same goes for the KV cache precision, which will default to the model precision unless manually set via kv cache dtype a la vLLM too. For Safetensors use as: And, for GGUF use as: Examples For Transformers with Safetensors weights: For Diffusers with Safetensors weights: For Sentence Transformers with Safetensors weights: With experimental to include the KV cache estimation for LLMs and VLMs: And, for LLMs or VLMs with GGUF weights: