Accelerating PyTorch Transformers with Intel Sapphire Rapids - part 2
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.
Related posts
- Accelerating Hugging Face Transformers with AWS Inferentia2
Hugging Face easyNoviceHugging 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.
- CPU Optimized Embeddings with 🤗 Optimum Intel and fastRAG
Hugging Face mediumAdeptPost-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. Accuracy loss stays small: under 0.3% on MTEB reranking and up to 1.55% on retrieval. The guide covers calibration with a qasper subset, loading the model with IPEXModel, and the benchmark setup (ipexrun, TCMalloc, single socket). It also shows how to plug the quantized models into fastRAG's QuantizedBiEncoderRetriever and QuantizedBiEncoderRanker for RAG indexing and reranking.
- Blazing Fast SetFit Inference with 🤗 Optimum Intel on Xeon
Hugging Face mediumAdeptPost-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%.
- Accelerate BERT inference with Hugging Face Transformers and AWS Inferentia
Hugging Face mediumAdeptDistilBERT 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.
- Intel and Hugging Face Partner to Democratize Machine Learning Hardware Acceleration
Hugging Face mediumAdeptIntel 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. A worked example applies post-training dynamic quantization to a DistilBERT review classifier with a 5% tolerable accuracy loss and up to 10 tuning trials. The run converts all 38 Linear and 2 Embedding operators to INT8, dropping accuracy from 0.574 to 0.546 while making evaluation 1.34x faster.