cd /news/artificial-intelligence/is-transformers-using-gpu-by-default · home › topics › artificial-intelligence › article
[ARTICLE · art-181571] src=discuss.huggingface.co ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

Is Transformers using GPU by default?

Hugging Face Transformers models loaded with AutoModelForSequenceClassification.from_pretrained() start on the CPU, not the GPU, so the model must be moved to "cuda:0" once and each tokenized batch moved to the same device, according to a Hugging Face documentation-based walkthrough. For 10,000 sentences, the walkthrough recommends starting with batches of 32 and measuring sentences per second, since short one-at-a-time predictions make a one-minute GPU utilization average hard to interpret. If utilization still looks low, printing model.device and inputs["input_ids"].device inside the loop should both show cuda:0.

recommendation

Move the model to cuda:0 once and each tokenized batch to model.device, then batch 32 sentences at a time and measure sentences per second instead of one-minute GPU utilization.

more in playbook: Inference and self-hosting
read1 min views2 publishedDec 4, 2026

With AutoModelForSequenceClassification.from_pretrained() as shown above, the model starts on the CPU. Move it to cuda:0 once, then move each batch of tokenized inputs to the same device.

For 10,000 sentences, I’d start with batches of 32 and measure sentences per second. Short, one-at-a-time predictions can make a one-minute GPU utilization average hard to interpret. Hugging Face

import torchmodel = model.to("cuda:0").eval()batch_size = 32predictions = []with torch.inference_mode():    for start in range(0, len(sentences), batch_size):        batch = sentences[start : start + batch_size]        inputs = tokenizer(            batch, padding=True, truncation=True, return_tensors="pt"        ).to(model.device)        label_ids = model(**inputs).logits.argmax(dim=-1).cpu().tolist()        predictions.extend(model.config.id2label[i] for i in label_ids)

If utilization still looks low, print model.device and inputs["input_ids"].device inside the loop. Both should show cuda:0.

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @hugging face 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/is-transformers-usin…] indexed:0 read:1min 2026-12-04 · —