---
title: "Scaling-up BERT Inference on CPU (Part 1)"
description: "Getting more BERT inference throughput out of a multi-socket Xeon server depends on controlling how model instances are placed on cores and memory, not on adding cores to a single instance."
url: "https://swe.quest/articles/scaling-up-bert-inference-on-cpu-part-1-f3c3c811ee6d4759"
canonical: "https://huggingface.co/blog/bert-cpu-scaling-part-1"
source: "Hugging Face"
published: "2021-04-20"
difficulty: "medium"
kind: "Research"
reading_minutes: 19
tags: ["inference","performance","hardware","linux"]
---

# Scaling-up BERT Inference on CPU (Part 1)

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2021-04-20, 19 min read, Research. Original: [https://huggingface.co/blog/bert-cpu-scaling-part-1](https://huggingface.co/blog/bert-cpu-scaling-part-1)

## Summary

Getting more BERT inference throughput out of a multi-socket Xeon server depends on controlling how model instances are placed on cores and memory, not on adding cores to a single instance. Benchmarks on an AWS c5.metal (2×24-core Xeon 8275) show PyTorch beating TensorFlow out of the box. The post explains why SMT/hyper-threading gives no benefit for GEMM-bound inference and how NUMA topology affects performance. It shows how to use numactl for thread affinity and NUMA-aware memory allocation, then examines core-count (strong) scaling and running multiple parallel model instances on non-overlapping core subsets to raise throughput.

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)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Linux](https://swe.quest/tags/linux.md) (Infrastructure)

## Prerequisites

- BERT/Transformer basics
- PyTorch or TensorFlow
- Linux CPU topology ([easy posts on Linux](https://swe.quest/tags/linux.md?difficulty=easy))

## Keywords

BERT, PyTorch, TensorFlow, numactl, NUMA, Hyper-Threading, ONNX Runtime, Hugging Face Transformers

## Related posts

- [Scaling up BERT-like model Inference on modern CPU - Part 2](https://swe.quest/articles/scaling-up-bert-like-model-inference-on-modern-cpu-part-2-ffac41dbe0cf5362.md): Hugging Face · 2021-11-04 · Medium · 20 min read · Inference & serving, Performance engineering, Hardware, Memory management, Machine learning
  Software-side tuning for BERT-like transformer inference on Intel Ice Lake Xeon CPUs covers memory allocators (jemalloc, tcmalloc, mimalloc), parallelization libraries (Intel OpenMP, oneTBB) and optimized math kernels (oneMKL, oneDNN).
- [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 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.
- [Introducing the next-gen Meta Training and Inference Accelerator](https://swe.quest/articles/introducing-the-next-gen-meta-training-and-inference-accelerator-bf598e586267b839.md): Meta Engineering · 2024-04-10 · Hard · 9 min read · Hardware, Inference & serving, Recommendations & ranking, Compilers
  Meta's second-generation MTIA inference accelerator, built on TSMC 5nm at 1.35GHz and 90W, more than doubles compute and memory bandwidth over v1.
- [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.

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)
