---
title: "Accelerating Hugging Face Transformers with AWS Inferentia2"
description: "Hugging Face benchmarked popular Transformer models on AWS Inferentia2 (inf2.xlarge) against Inferentia1 (inf1.2xlarge) and an NVIDIA A10G GPU (g5.2xlarge), running 144 p95-latency experiments at batch size 1 across six architectures and sequence lengths from 8 to 512."
url: "https://swe.quest/articles/accelerating-hugging-face-transformers-with-aws-inferentia2-732d2daf15bc9874"
canonical: "https://huggingface.co/blog/accelerate-transformers-with-inferentia2"
source: "Hugging Face"
published: "2023-04-17"
difficulty: "easy"
kind: "Announcement"
reading_minutes: 5
tags: ["inference","hardware","performance","cloud"]
---

# Accelerating Hugging Face Transformers with AWS Inferentia2

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-04-17, 5 min read, Announcement. Original: [https://huggingface.co/blog/accelerate-transformers-with-inferentia2](https://huggingface.co/blog/accelerate-transformers-with-inferentia2)

## Summary

Hugging Face benchmarked popular Transformer models on AWS Inferentia2 (inf2.xlarge) against Inferentia1 (inf1.2xlarge) and an NVIDIA A10G GPU (g5.2xlarge), running 144 p95-latency experiments at batch size 1 across six architectures and sequence lengths from 8 to 512. On average Inferentia2 delivered 4.5x lower latency than the A10G and 4x lower than Inferentia1, with BERT-base about 6x faster up to sequence length 256 and ViT-base about 2x faster than the GPU. The GPU runs were unoptimized fp32. Models compile for Inferentia2 through Optimum Neuron and the AWS Neuron SDK, and instances start at $0.76/hour.

Written by swe.quest, not by the author.

**Difficulty:** Easy: no special background needed; explains what something is and why it matters

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Cloud platforms](https://swe.quest/tags/cloud.md) (Infrastructure)

## Prerequisites

- Transformer models
- model inference latency ([easy posts on Inference & serving](https://swe.quest/tags/inference.md?difficulty=easy))

## Keywords

AWS Inferentia2, Hugging Face Transformers, Optimum Neuron, AWS Neuron SDK, Amazon EC2 Inf2, BERT, Vision Transformer, NVIDIA A10G

## Related posts

- [Accelerate BERT inference with Hugging Face Transformers and AWS Inferentia](https://swe.quest/articles/accelerate-bert-inference-with-hugging-face-transformers-and-aws-inferentia-a06f31ecbe8356b6.md): Hugging Face · 2022-03-16 · Medium · 8 min read · Inference & serving, Hardware, Cloud platforms, Python
  DistilBERT can be compiled to AWS Neuron with torch.neuron.trace and served on an Inferentia-backed SageMaker real-time endpoint, using a custom inference.py that pins one Neuron core per HTTP worker.
- [Accelerating PyTorch Transformers with Intel Sapphire Rapids - part 2](https://swe.quest/articles/accelerating-pytorch-transformers-with-intel-sapphire-rapids-part-2-c41ef6f6c233e349.md): Hugging Face · 2023-02-06 · Medium · 6 min read · Inference & serving, Hardware, Performance engineering, Python
  Intel Sapphire Rapids CPUs with AMX instructions, combined with Hugging Face Optimum Intel running in bfloat16 with JIT compilation, cut p99 inference latency for DistilBERT, BERT and RoBERTa text classification by roughly 3x compared with vanilla Transformers on Ice Lake.
- [Make your llama generation time fly with AWS Inferentia2](https://swe.quest/articles/make-your-llama-generation-time-fly-with-aws-inferentia2-bc8b5e1981a590c0.md): Hugging Face · 2023-11-07 · Medium · 7 min read · Inference & serving, LLMs, Hardware, Cloud platforms, Performance engineering
  optimum-neuron can now compile and export Llama 2 models for text generation on AWS Inferentia2, using static input shapes (batch size, 2048 sequence length that also bounds the KV cache) and a configurable core count and fp16 precision.
- [Hugging Face Text Generation Inference available for AWS Inferentia2](https://swe.quest/articles/hugging-face-text-generation-inference-available-for-aws-inferentia2-4404accc08bd48f1.md): Hugging Face · 2024-02-01 · Medium · 7 min read · Inference & serving, LLMs, Cloud platforms, Python
  Text Generation Inference (TGI) is now generally available on AWS Inferentia2 through Amazon SageMaker, offering an alternative to GPUs for serving open LLMs such as Llama and Mistral.
- [TorchNeuron: running HF models on AWS Trainium is easier than ever](https://swe.quest/articles/torchneuron-running-hf-models-on-aws-trainium-is-easier-than-ever-99ae731bb5ca0252.md): Hugging Face · 2026-10-19 · Medium · 7 min read · Hardware, Model training, Inference & serving, Python
  TorchNeuron is a PyTorch plugin that exposes AWS Trainium as a native \`neuron\` device with eager execution, \`torch.compile\`, and native distributed APIs (DTensor, FSDP2, TP), replacing the PyTorch XLA–based path that required lazy tensors and static graphs.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
