---
title: "Scaling up BERT-like model Inference on modern CPU - Part 2"
description: "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)."
url: "https://swe.quest/articles/scaling-up-bert-like-model-inference-on-modern-cpu-part-2-ffac41dbe0cf5362"
canonical: "https://huggingface.co/blog/bert-cpu-scaling-part-2"
source: "Hugging Face"
published: "2021-11-04"
difficulty: "medium"
kind: "Research"
reading_minutes: 20
tags: ["inference","performance","hardware","memory-management","machine-learning"]
---

# Scaling up BERT-like model Inference on modern CPU - Part 2

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

## Summary

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). Benchmarks on a Xeon Platinum 8380 compare eager frameworks (PyTorch, TensorFlow, TensorFlow with oneDNN, Intel TensorFlow) and graph frameworks (TorchScript, TensorFlow graph) across batch sizes and sequence lengths. Adding cores generally lowers latency, but spanning both sockets adds inter-socket overhead that only pays off for larger workloads. Graph-mode TensorFlow leads at low core counts, while TorchScript scales better as cores increase, though the gaps between frameworks are mostly small.

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)
- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)

## Prerequisites

- Transformer models like BERT
- PyTorch or TensorFlow
- CPU threading basics ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))

## Keywords

Intel Ice Lake, oneDNN, oneMKL, TorchScript, Intel OpenMP, tcmalloc, jemalloc, BERT

## Related posts

- [Scaling-up BERT Inference on CPU (Part 1)](https://swe.quest/articles/scaling-up-bert-inference-on-cpu-part-1-f3c3c811ee6d4759.md): Hugging Face · 2021-04-20 · Medium · 19 min read · Inference & serving, Performance engineering, Hardware, Linux
  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.
- [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.
- [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.
- [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.
- [Accelerating PyTorch distributed fine-tuning with Intel technologies](https://swe.quest/articles/accelerating-pytorch-distributed-fine-tuning-with-intel-technologies-6164e2f4281509af.md): Hugging Face · 2021-11-19 · Medium · 9 min read · Model training, Hardware, Performance engineering, Python, Cloud platforms
  Fine-tuning transformer models can be distributed across a cluster of Intel Ice Lake Xeon CPU servers using the Intel Extension for PyTorch and the oneCCL communication backend, making CPU clusters a cost-effective option for shorter transfer-learning jobs.

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)
