Transformers documentation

Hardware

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.20.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Hardware

Transformers runs on CPUs, NVIDIA GPUs, AMD GPUs, Apple Silicon, Google TPUs, AWS Trainium instances, and more through their PyTorch backends.

  • For training, TrainingArguments detects the backend automatically.
  • For inference, automatic detection doesn’t cover every backend, so pass the device string to choose one explicitly. This page lists the device string and package for each backend, what TrainingArguments configures it for, and how Transformers decides which device to use.

Find your hardware

Each backend has a device string that you pass to device_map or device. CPU and Apple Silicon work with the standard torch package. The other backends require a PyTorch extension package that registers the backend with PyTorch.

HardwareDevice stringPackage
CPUcputorch
NVIDIA GPUcudatorch
AMD GPUcudatorch (ROCm build)
AWS Trainiumneurontorch-neuronx
Google TPUtputorch-tpu
Intel GPUxputorch
Apple Siliconmpstorch
Intel Gaudihpuhabana-torch-plugin
Huawei Ascend NPUnputorch-npu
Cambricon MLUmlutorch-mlu
Moore Threads GPUmusatorch-musa

If a hardware backend is missing from this table and you believe Transformers supports it, please open an issue.

How Transformers picks a device

Transformers picks a device differently for training and inference.

Training

TrainingArguments detects the backend automatically through Accelerate. In a distributed run, each process uses the device Accelerate assigns to it. In a single process, TrainingArguments picks the first available backend, and falls back to CPU if none is available. Set use_cpu=True to force training on CPU.

Inference

from_pretrained() loads a model on CPU by default.

Set device_map="auto" to place it on the available accelerators. Automatic placement relies on Accelerate to detect CUDA, Intel XPU, Intel Gaudi (HPU), and Apple Silicon (MPS), among others, but it doesn’t cover every backend. For other backends, such as AWS Trainium, pass the device string to device_map explicitly.

from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-0.6B", device_map="neuron")
Update on GitHub