Skip to content

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

Hugging Face 20 min read Research mediumAdept

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

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.

Assumes: Transformer models like BERTPyTorch or TensorFlowCPU threading basics

Related posts

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

    Hugging Face mediumAdept

    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.

  • Blazing Fast SetFit Inference with 🤗 Optimum Intel on Xeon

    Hugging Face mediumAdept

    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. The walkthrough calibrates on 100 rotten_tomatoes samples, quantizes a bge-small SetFit model with the IPEX backend, and benchmarks it against fp32 Transformers and IPEX bf16 with TorchScript. At batch size 1, latency drops from 15.69 ms to 4.55 ms (3.45x), model size shrinks from 127 MB to 45 MB, and sst2 accuracy moves only from 88.4% to 88.1%.

  • 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.

  • 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.

  • Accelerating PyTorch distributed fine-tuning with Intel technologies

    Hugging Face mediumAdept

    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. The walkthrough builds a 4-node EC2 c6i.16xlarge cluster, installs oneAPI toolkits, PyTorch 1.9, IPEX and torch-ccl, sets oneCCL environment variables, patches run_glue.py for rank handling, and launches jobs with mpirun. Fine-tuning on GLUE MRPC drops from 7m46s on one node to 4m39s on two (1.7x) and 2m36s on four (3x). The larger QQP task shows similar scaling, from 11h22m to 3h51m on four nodes (2.95x).

The quest for software engineering knowledge.

Look:
Layout: