25% faster than ONNXRuntime, 35% faster than PyTorch for BERT

A vast majority of AI inference is done on CPUs and the Intel Xeon Scalable Processor family is by far the most widely deployed CPU in data centers today. In this post we will demonstrate nod.ai SHARK running on 3rd Generation Intel Xeon Scalable Processors (Intel Xeon 8375C) and outperforming ONNXRuntime, PyTorch, Tensorflow all of which use Intel’s OneDNN (formerly MKL/MKLDNN) in some form and PlaidML.

SHARK is an open source framework that is built on top of torch-mlir, IREE and nod.ai’s auto-tuner. The nod.ai team is a major contributor to both torch-mlir and IREE. We strive to push all our changes into the upstream repositories though some of the performance optimization changes could be found in our repositories. You are welcome to contribute to all the projects and you can find real-time support in our discord server.

The SHARK compiler and runtime have proven to be the fastest runtime for the state of art BERT / Transformer like models on GPUs. In our earlier post here we demonstrated generating performant code for Nvidia A100 without any vendor libraries like CuDNN. SHARK does inference of the same BERT model in 1.30ms vs ONNX’s 2.38ms and has been validated by independent third parties on a DGX-A100.

HARDWARE

For this study we will use Intel Xeon 8375C processors in AWS C6id.metal Instances. C6id.metal instances provide us full control of the processor without any hypervisor. We run off hyperthreading and turn on the performance governor so we have no variability.

# Disable address space randomization.
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space 

# Disable turbo (if available)
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo

cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | awk -F, '{print $2}' | sort -n | uniq | ( while read X ; do echo $X ; echo 0 | sudo tee  /sys/devices/system/cpu/cpu$X/online ; done )
anush@xeon8375C shark-runtime/build (main) » lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         46 bits physical, 57 bits virtual
  Byte Order:            Little Endian
CPU(s):                  128
  On-line CPU(s) list:   0-63
  Off-line CPU(s) list:  64-127
Vendor ID:               GenuineIntel
  Model name:            Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz
    CPU family:          6
    Model:               106
    Thread(s) per core:  1
    Core(s) per socket:  32
    Socket(s):           2
    Stepping:            6
    CPU max MHz:         3500.0000
    CPU min MHz:         800.0000
    BogoMIPS:            5800.00
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities
Virtualization features: 
  Virtualization:        VT-x
Caches (sum of all):     
  L1d:                   3 MiB (64 instances)
  L1i:                   2 MiB (64 instances)
  L2:                    80 MiB (64 instances)
  L3:                    108 MiB (2 instances)
NUMA:                    
  NUMA node(s):          2
  NUMA node0 CPU(s):     0-31
  NUMA node1 CPU(s):     32-63
Vulnerabilities:         
  Itlb multihit:         Not affected
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Mmio stale data:       Mitigation; Clear CPU buffers; SMT disabled
  Retbleed:              Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl and seccomp
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional, RSB filling
  Srbds:                 Not affected
  Tsx async abort:       Not affected

SOFTWARE

We run Ubuntu 22.04 with latest clang-16 nightlies for the builds. All the SHARK code is generated with AVX-512 instructions. The benchmarks for other frameworks can be run either following the instructions here or by directly building nod-ai/SHARK and nod-ai/SHARK-Runtime. Please reach out on our Discord Channel if you have any questions on reproducing the results.

BERT – We use the same model Huggingface used for their “1ms” BERT. We also use RESNET50 since it has been optimized for years on CPUs so we can demonstrate maturity of the SHARK stack on CPUs.

There are hundreds of other models you can try from the SHARK Tank in easy to use Python packages.

RESULTS

BERT / MiniLM

BERT Inference on Intel Xeon 8375C
+ iree-compile --iree-input-type=mhlo --iree-vm-bytecode-module-output-format=flatbuffer-binary --iree-hal-target-backends=llvm-cpu --mlir-print-debuginfo --mlir-print-op-on-diagnostic=false --iree-llvm-target-cpu-features=+avx512f results/cpu_tuned_model.mlir -o results/cpu_tuned_model.vmfb
+ numactl --physcpubind=0 -l iree-benchmark-module --module_file=/home/harsh/nod-shark-tuner/results/cpu_tuned_model.vmfb --device=local-task --entry_function=predict --function_input=1x128xi32 --function_input=1x128xi32 --function_input=1x128xi32 --task_topology_max_group_count=12
2022-08-16T21:26:55+00:00
Running /home/harsh/venv/tune/lib/python3.10/site-packages/iree/runtime/scripts/iree_benchmark_module/../../iree-benchmark-module
Run on (64 X 3160.15 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x64)
  L1 Instruction 32 KiB (x64)
  L2 Unified 1280 KiB (x64)
  L3 Unified 55296 KiB (x2)
Load Average: 3.20, 1.58, 1.24
----------------------------------------------------------------------------
Benchmark                                  Time             CPU   Iterations
----------------------------------------------------------------------------
BM_predict/process_time/real_time       9.42 ms         90.4 ms           74
engine,version,device,precision,optimizer,io_binding,model_name,inputs,threads,batch_size,sequence_length,datetime,test_times,QPS,average_latency_ms,latency_variance,latency_90_percentile,latency_95_percentile,latency_99_percentile
onnxruntime,1.12.1,cpu,fp32,False,True,microsoft/MiniLM-L12-H384-uncased,1,64,1,128,2022-08-17 06:28:25.386588,100,84.64,11.81,0.00,12.30,13.40,18.82
torchscript,1.13.0.dev20220816+cpu,cpu,fp32,,,microsoft/MiniLM-L12-H384-uncased,1,64,1,128,2022-08-17 06:28:32.945569,100,78.20,12.79,0.16,11.65,12.68,32.05
tensorflow,2.11.0-dev20220816,cpu,fp32,,,microsoft/MiniLM-L12-H384-uncased,1,64,1,128,2022-08-17 06:28:47.660006,100,29.53,33.87,0.00,36.58,37.47,38.84
MLIR,2.11.0-dev20220816,cpu,fp32,,,microsoft/MiniLM-L12-H384-uncased,1,1,1,128,2022-08-17 06:29:21.344592,100,79.15,12.63,0.00,12.67,12.71,13.66

ResNet50

anush@xeon8375C shark-runtime/build (main) » ./tools/iree-compile -iree-input-type=mhlo -iree-mlir-to-vm-bytecode-module -iree-hal-target-backends=llvm-cpu -iree-llvm-target-cpu-features=host -iree-llvm-link-embedded=true -iree-llvm-debug-symbols=false -iree-vm-bytecode-module-strip-source-map=true -iree-vm-emit-polyglot-zip=false --iree-llvm-target-cpu-features="+avx512f" resnet/resnet.mlir -o resnet.vmfb

anush@xeon8375C shark-runtime/build (main) » numactl --physcpubind=0 -l ./tools/iree-benchmark-module --module_file=resnet.vmfb --device=local-task --entry_function=predict --function_input="1x224x224x3xf32" --task_topology_max_group_count=18
2022-08-17T07:08:17+00:00
Running ./tools/iree-benchmark-module
anush@xeon8375C shark-runtime/build (main) » numactl --physcpubind=0 -l  ./tools/iree-benchmark-module --module_file=minilm_cpu.vmfb --entry_function=predict --function_input=1x128xi32 --function_input=1x128xi32 --function_input=1x128xi32  --device=local-task:// --task_topology_max_group_count=12
2022-08-17T14:03:55+00:00
Running ./tools/iree-benchmark-module
Run on (64 X 3449.26 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x64)
  L1 Instruction 32 KiB (x64)
  L2 Unified 1280 KiB (x64)
  L3 Unified 55296 KiB (x2)
Load Average: 0.11, 0.09, 0.03
----------------------------------------------------------------------------
Benchmark                                  Time             CPU   Iterations
----------------------------------------------------------------------------
BM_predict/process_time/real_time       10.5 ms         75.2 ms           66
(plaidenv) anush@xeon8375C envs/plaidenv » plaidbench --results output --examples 128 --batch-size 1 keras resnet50

Running 128 examples with resnet50, batch size 1, on backend plaid
INFO:plaidml:Opening device "llvm_cpu.0"
Model loaded, skipping folding in batch_norm
Compiling network... Warming up... Running...
Example finished, elapsed: 2.320s (compile), 1.523s (execution)

-----------------------------------------------------------------------------------------
Network Name         Inference Latency         Time / FPS          
-----------------------------------------------------------------------------------------
resnet50             11.90 ms                  10.48 ms / 95.41 fps
Correctness: PASS, max_error: 8.240351235144772e-06, max_abs_error: 1.1920928955078125e-06, fail_ratio: 0.0
anush@xeon8375C ~/github/transformer-benchmarks
 % python resnet50.py  
No config specified, defaulting to: cats-image/image
Reusing dataset cats-image (/home/anush/.cache/huggingface/datasets/huggingface___cats-image/image/1.9.0/68fbc793fb10cd165e490867f5d61fa366086ea40c73e549a020103dcb4f597e)
100%|[00:00<00:00, 1146.61it/s]
PyTorch: time/iter in ms : 23.123490182976973

Summary

This post shows how you can unlock the potential of your Intel Xeon Scalable processors using fully open source SHARK runtime and achieve unparalleled performance. These gains are compounding as you run millions of inferences over large fleets of Xeon CPUs. Reach out to us at stdin@nod.ai or sign up to see how we can help unlock your investment in Intel Xeon CPUs.

Comments are closed.