Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 19 min read Research mediumAdept

Scaling-up BERT Inference on CPU (Part 1)

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.

Assumes: BERT/Transformer basicsPyTorch or TensorFlowLinux CPU topology

Related posts

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

    Hugging Face mediumAdept

    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.

  • Accelerate BERT inference with Hugging Face Transformers and AWS Inferentia

    Hugging Face mediumAdept

    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. Because the Neuron SDK lacked dynamic shape support, inputs must be padded to a fixed sequence length (128 here) chosen at compile time. On an ml.inf1.xlarge the endpoint averaged 5-6 ms model latency per request. That is faster than CPU, and running four model copies across the chip's four Neuron cores gives higher throughput than GPUs. The recommendation is to move BERT-like encoder workloads to Inferentia when that latency is acceptable.

  • Accelerating Hugging Face Transformers with AWS Inferentia2

    Hugging Face easyNovice

    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.

  • Introducing the next-gen Meta Training and Inference Accelerator

    Meta Engineering hardMaster

    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. It keeps utilization high at small batch sizes for ranking and recommendation models by pairing an 8x8 processing-element grid with outsized SRAM (256 MB on-chip at 2.7 TB/s, 384 KB local per PE), a faster network-on-chip and 128 GB LPDDR5. The chips ship in 72-accelerator racks over PCIe Gen5 and run a PyTorch 2.0 stack with a user-space driver and a Triton-MTIA compiler backend, which got production traffic running within days and reached 16 regions in under nine months. Early results show 3x chip performance over v1 and 6x serving throughput with 1.5x performance per watt at the platform level.

  • Accelerating PyTorch Transformers with Intel Sapphire Rapids - part 2

    Hugging Face mediumAdept

    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.

The quest for software engineering knowledge.

Look:
Layout: