Hugging Face Accelerate does not make GPU inference faster on its own. For inference, its Big Model Inference feature decides where each layer of a model lives (GPU memory first, then CPU RAM, then disk) and moves weights onto the GPU when a layer needs them, so a model that would not fit on your graphics card can still run. For GPU accelerated computing, speed is a separate question.
What Accelerate Does When You Load and Run a Model for Inference
Standard PyTorch loading builds the model with random weights and then loads the pretrained weights, so two full copies sit in RAM at once. Hugging Face’s concept guide puts a 6-billion-parameter model at 24GB of RAM per copy, 48GB in total. Accelerate changes three steps of that process.
First, the init_empty_weights() context manager creates the model on PyTorch’s meta device, which holds only metadata, so the skeleton costs no RAM whatever its size. Second, load_checkpoint_and_dispatch() loads a full or sharded checkpoint into that empty model and sends each layer’s weights to a device as they load, so peak RAM is the size of the biggest shard, not the whole model. Hugging Face’s own example is BLOOM: 176 billion parameters and 352GB in bfloat16, split across 72 checkpoint files, so loading needs only enough RAM for the largest shard, 7.19GB.
Third, dispatch_model attaches hooks to every module and submodule that run before and after each forward pass. Those hooks move a module’s inputs to the device holding its weights. They also move CPU-offloaded weights to GPU 0 just before the forward pass and back afterwards, and bring disk-offloaded weights from disk to RAM to GPU 0, freeing the memory once the pass ends. All of this applies to inference only, and most of the computation runs under torch.no_grad() so intermediate activations do not take GPU memory. In Transformers, setting device_map="auto" in from_pretrained turns the whole mechanism on.
The practical reading: Accelerate’s inference job is placing and moving weights. The hooks run before and after your model’s own forward pass, so placement adds overhead rather than speed.
Does Accelerate Make Inference Faster, or Just Make the Model Fit?
It makes the model fit. In Hugging Face’s BLOOM inference post, on 8x80GB A100s, Accelerate in bf16 ran at about 230 ms per token at the smallest batch size and about 11 ms at the largest batch it fitted, while DeepSpeed-Inference in fp16 ran at about 44 ms and 1.7 ms at the same batch sizes. The post puts the gap down to DeepSpeed-Inference’s tensor parallelism and custom CUDA kernels, compared with Accelerate’s generic pipeline approach. The same authors still describe Accelerate as “super fast as well”, because its simple, naive pipeline parallelism works out of the box with any model.
That is the fair summary. Accelerate gives decent throughput and works out of the box with any model. A runtime built for one inference pattern will beat it when speed is what you are paying for.
In the studies below, quantisation cut memory but sometimes cost speed. LLM.int8() (Dettmers et al., 2022) cut the memory needed for inference by half while keeping full-precision quality, yet its quantisation overhead slowed models under 6.7B parameters compared with an FP16 baseline. Bench360 (2025) found that INT8 and INT4 let a 24GB GPU hold models 2 to 4 times larger, while time per output token and energy could rise by more than 350%, most of all for Qwen2.5-32B in INT4. Accelerate’s own layerwise casting hook works the same way: it stores weights in a low-precision type such as float8 and upcasts them for compute, which saves memory at some risk to output quality.
device_map=”auto”: Fill Order, Options and When Offload Slows Inference Down
With device_map="auto", Accelerate uses the maximum space on the GPUs first. It stores any remaining weights in CPU RAM, and once RAM runs out it writes the rest to disk as memory-mapped tensors. The usage guide calls the hard drive “the absolute slowest option”. When you have more than one GPU, the device map has these options:
"auto"or"balanced": weights split so each GPU is used equally."balanced_low_0": equal split except for the first GPU, which gets as few weights as possible. This is useful when you work with the model’s outputs on one GPU, for example withgenerate."sequential": GPUs fill in order, so the last ones might not be used at all.
The automatic map also reserves room for offloaded layers. If any layer goes to the CPU, room is always left on GPU 0 for the largest CPU-offloaded layer. If any layer goes to disk, room is always left in CPU RAM for the largest disk-offloaded layer. The hard floor is that the largest single layer has to fit on your GPU.
Why Offload Costs so Much Speed
Offloading is slow for a structural reason. Accelerate does no prefetching: offloaded weights reach the GPU only when they are needed, not before. Disk offload also reads weights from disk on every forward pass, and it can be very slow without fast disk-to-CPU links such as NVMe. The BLOOM post reports users running BLOOM on just 2 A100s at 15 seconds per token, compared with 10 ms per token on 8x80GB A100s.
FlexGen (Sheng et al., 2023) ran OPT-175B with offloading, and there Hugging Face Accelerate could not use a batch size larger than 2 without running out of memory. At a 5,000-second latency budget it could not finish a single batch. The authors note that Accelerate offloads a fraction of the weights, puts cache and activations only on the GPU, and does not support GPUs spread across different machines. SpecOffload (2025) used Accelerate version 1.5.2 as one of its baselines. It found that existing offloading systems kept average GPU core utilisation during decoding at 13% at most. Its own 58.67% was 8.14 times Accelerate’s figure, which puts Accelerate at roughly 7% (58.67 ÷ 8.14). On an RTX 4090 over PCIe 4.0 x16, loading one FFN layer of Mixtral 8x22B from CPU to GPU took 240 ms, while computing it took 0.1 ms.
If you call the same model in a loop, cpu_offload_with_hook() keeps the model on the execution device after the forward pass. It offloads the model again only when you call the hook’s offload method.
A device map that spills to disk means the model is too large for your GPUs and CPU RAM combined.
How to Run Multi-GPU Inference with Hugging Face Accelerate
Hugging Face’s distributed inference guide describes three ways to use several GPUs:
- Replication. You load the whole model onto each GPU and send each one a different chunk of the batch. This is the most memory-hungry option, because every GPU holds a full copy.
- Splitting the model. You load parts of the model onto each GPU and process one input at a time.
- Scheduled pipeline parallelism. You split the model and feed in several inputs, so each chunk works on one input while the next waits its turn. The guide says this is more efficient and faster than the plain split.
Splitting a model across GPUs with device_map="auto" gives you the second option. Its model parallelism is naive and unoptimised: only one GPU works at a time while the others sit idle. Adding GPUs this way buys capacity, not speed, so do not expect a split across four cards to beat one card that could hold the model. For pipeline parallelism that keeps all GPUs busy, Accelerate points to its memory-efficient pipeline parallelism guide and notes that the approach is less flexible.
The Accelerate README shows how to launch on two GPUs: accelerate launch --multi_gpu --num_processes 2 examples/nlp_example.py.
If you need several GPUs working on one layer at once, use tensor parallelism, not Accelerate’s one-GPU-at-a-time device map. Transformers’ tensor parallelism slices each layer so several accelerators work on it together, and it needs fast intra-node communication because GPUs exchange partial results at every layer. Hugging Face says it speeds up inference significantly, especially with large batches or long sequences. vLLM’s documentation gives configuration advice. If the model fits on one GPU, you probably do not need distributed inference. If it fits on one node with several GPUs, set tensor_parallel_size to the GPU count. If the GPUs lack NVLink (the docs cite the L40S), pipeline parallelism gives higher throughput.
What Code Changes Does Accelerate Need for an Existing Inference Script?
The changes depend on where the script starts: Transformers or plain PyTorch. The README calls Accelerate a thin wrapper, not a high-level framework, with the whole API in one class, Accelerator. That class is built for running training loops in distributed environments. Big-model inference uses a separate set of functions.
From a Transformers Script
Add device_map="auto" to from_pretrained. If any weights will map to disk, also set offload_folder to a directory, because Transformers stores the offloaded weights there.
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
"your-model-id",
device_map="auto",
offload_folder="offload", # needed only if some weights map to disk
)
From a Plain PyTorch Script
- Build the model inside
init_empty_weights()so the skeleton takes no RAM. - Call
load_checkpoint_and_dispatch()with your checkpoint and a device map. It loads the weights, places them and adds the hooks the split model needs to run. - Leave layer-to-layer device moves to the hooks, which put each layer’s inputs on the right device even when the model spans several GPUs.
from accelerate import init_empty_weights, load_checkpoint_and_dispatch
with init_empty_weights():
model = MyModel(config)
model = load_checkpoint_and_dispatch(
model, checkpoint="path/to/checkpoint", device_map="auto"
)
For a distributed, multi-process script, Accelerate’s tutorial on adapting PyTorch code gives the pattern. Create an Accelerator(), replace hard-coded device = "cuda" with accelerator.device, and pass your PyTorch objects through accelerator.prepare().
When Should You Use vLLM Instead of Accelerate for Production Inference?
Move to a dedicated serving engine once the job turns from “make this model run” into “serve many requests at an acceptable cost and latency”. The reason lies in how LLM decoding uses the GPU. The decode phase handles one token per request per step, so it is typically memory-bound, and the GPU spends most of its time waiting for weight transfers. Larger batches improve GPU utilisation, but each request needs more KV cache memory. The PagedAttention paper (Kwon et al., 2023) found that existing systems used only 20.4% to 38.2% of their KV cache memory for actual token states. vLLM manages that cache in blocks, like operating-system pages, and raised serving throughput by 2 to 4 times over FasterTransformer and Orca.
Against vanilla PyTorch with Hugging Face Transformers, a 2025 energy study found that vLLM improves both throughput and energy efficiency. Applying the right inference optimisations cut total energy by up to 73% compared with that unoptimised baseline. The best engine, though, depends on the scenario.
| Your situation | Reasonable choice | Evidence |
|---|---|---|
| Model does not fit, latency not critical | Accelerate device_map="auto", which fills CPU RAM before disk |
Placement lets any model run if its largest layer fits on the GPU, with added overhead |
| Model fits on one GPU | Run on that single GPU; no distribution needed | vLLM docs |
| Many concurrent users, API or multi-tenant serving | vLLM | 2 to 24 times TGI’s throughput in a 2025 vLLM-versus-TGI study; 24x for LLaMA-2-7B at 200 concurrent requests; most robust multi-user engine in Bench360 (2025) |
| Interactive use at low concurrency, time to first token matters | TGI or LMDeploy | TGI had 1.3 to 2 times lower time to first token at low concurrency; LMDeploy led single-request responsiveness in Bench360 |
| Batch throughput on mid-range GPUs (L4, A10) | SGLang | Highest tokens per second across batch sizes on L4 and A10 in Bench360 |
| Huge model, one commodity GPU, latency-insensitive batch jobs | A throughput-oriented offloading engine such as FlexGen | Built for batch processing on constrained hardware |
Read the table as a starting point, not a verdict. Bench360’s authors conclude that no single setup is best for local inference and that the choice needs data-driven evaluation against your deployment requirements. They also tested only single-GPU deployments, leaving multi-GPU and CPU offload out. The vLLM-versus-TGI figures come from one comparative study, so treat its 24-times headline as the extreme-load case it measured, not a typical gap. To compare throughput, latency and memory across accelerators, LynxBenchAI measures AI performance on the hardware itself.
Before You Blame the Model, Profile the Serving Path
When a Hugging Face inference service hits cost or latency pressure, it rarely needs a new model. We would audit the path the requests actually take first: is the model offloading, is only one GPU active, are requests batched at all? TechnoLynx’s GPU performance engineering work does that audit on the deployed stack. It looks at batching, offload, device placement, serving configuration and runtime choice, and looks for cost and latency improvements before anyone recommends replacing the model.
The levers sit below the model layer and are independently tunable. TurboTransformers (Fang et al., 2021) found a GPU completely idle 80.64% of the time for BERT inference at batch size 1 on a V100. The PyTorch performance tuning guide covers fused kernels through torch.compile and avoiding unnecessary CPU-GPU synchronisation, and says its techniques often take only a few lines of code. The 2025 energy study found that CUDA graphs help most at lower batch sizes, where kernel launch cost is relatively larger.
The question to answer before changing anything is which of these a profile shows you are paying for. A model running at single-digit GPU utilisation because of disk offload needs a different fix from one that is fully resident but serving one request at a time.
FAQ
Does Inference Use the GPU or the CPU?
With Accelerate’s device map, each forward pass runs on a GPU. Weights offloaded to CPU RAM or disk are copied to GPU 0 before each forward pass and moved back afterwards.
Can You Run an LLM Without a GPU?
Accelerate lists CPU-only and multi-CPU setups among its supported configurations. Whether the speed is acceptable depends on the model’s size and the machine’s memory bandwidth, so measure it on your own workload before committing.