---
title: "Accelerating PyTorch Transformers with Intel Sapphire Rapids - part 2"
description: "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."
url: "https://swe.quest/articles/accelerating-pytorch-transformers-with-intel-sapphire-rapids-part-2-c41ef6f6c233e349"
canonical: "https://huggingface.co/blog/intel-sapphire-rapids-inference"
source: "Hugging Face"
published: "2023-02-06"
difficulty: "medium"
kind: "Research"
reading_minutes: 6
tags: ["inference","hardware","performance","python"]
---

# Accelerating PyTorch Transformers with Intel Sapphire Rapids - part 2

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-02-06, 6 min read, Research. Original: [https://huggingface.co/blog/intel-sapphire-rapids-inference](https://huggingface.co/blog/intel-sapphire-rapids-inference)

## Summary

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. The benchmark uses EC2 c6i.16xlarge and r7iz.16xlarge-metal instances, short (16-token) and long (128-token) inputs, single and batch-of-8 predictions, and libtcmalloc. Optimum needs only a small wrapper around the existing pipeline code, and the results show single-digit millisecond latency on long sequences without a GPU.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## 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)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- PyTorch basics
- Hugging Face Transformers pipelines

## Keywords

Intel Sapphire Rapids, AMX, Optimum Intel, Intel Extension for PyTorch, bfloat16, Amazon EC2, DistilBERT

## Related posts

- [Accelerating Hugging Face Transformers with AWS Inferentia2](https://swe.quest/articles/accelerating-hugging-face-transformers-with-aws-inferentia2-732d2daf15bc9874.md): Hugging Face · 2023-04-17 · Easy · 5 min read · Inference & serving, Hardware, Performance engineering, Cloud platforms
  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.
- [CPU Optimized Embeddings with 🤗 Optimum Intel and fastRAG](https://swe.quest/articles/cpu-optimized-embeddings-with-optimum-intel-and-fastrag-e206611a492390e0.md): Hugging Face · 2024-03-15 · Medium · 11 min read · Inference & serving, RAG & retrieval, Performance engineering, Hardware, Python
  Post-training static int8 quantization of BGE embedding models (small, base, large) with Optimum Intel, Intel Neural Compressor and IPEX gives up to 4.5x lower latency and up to 4x higher throughput on 4th-gen Xeon CPUs compared with a bf16 PyTorch baseline.
- [Blazing Fast SetFit Inference with 🤗 Optimum Intel on Xeon](https://swe.quest/articles/blazing-fast-setfit-inference-with-optimum-intel-on-xeon-804c53c4c80ba1a3.md): Hugging Face · 2024-04-03 · Medium · 6 min read · Inference & serving, Performance engineering, Hardware, Python
  Post-training static int8 quantization of a SetFit model body with Optimum Intel and Intel Neural Compressor speeds up inference on Xeon CPUs by up to 7.8x in throughput with negligible accuracy loss.
- [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.
- [Intel and Hugging Face Partner to Democratize Machine Learning Hardware Acceleration](https://swe.quest/articles/intel-and-hugging-face-partner-to-democratize-machine-learning-hardware-0de59c0019e6704c.md): Hugging Face · 2022-06-15 · Medium · 7 min read · Inference & serving, Machine learning, Performance engineering, Hardware
  Intel has joined Hugging Face's Hardware Partner Program, and the two are collaborating on Optimum Intel, an open-source library built on Intel Neural Compressor that applies quantization, pruning and distillation to Transformer models on Xeon CPUs.

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)
