Skip to content

Instantly share code, notes, and snippets.

View rahulunair's full-sized avatar
🏠
Working from home

Rahul Nair rahulunair

🏠
Working from home
View GitHub Profile

benchmark

Based on huggingface repo for performance evaluation, actual benchmark run script placed at repo. How to reproduce performance:

  1. prepare dataset according to link.
  2. update GLUE_DIR to actual dataset path in run_inference.sh.
  3. change env settings, the default setting is using 20 cores;

MKL v.s. MKLDNN

Inference performance result on Xeon 6148 (2x20 cores), single socket and single thread.

@rahulunair
rahulunair / pytorch_cpu_perf_bkm.md
Created July 8, 2022 06:12 — forked from mingfeima/pytorch_cpu_perf_bkm.md
BKM for PyTorch CPU Performance

General guidelines for CPU performance on PyTorch

This file serves a BKM to get better performance on CPU for PyTorch, mostly focusing on inference or deployment. Chinese version available here.

1. Use channels last memory format

Right now, on PyTorch CPU path, you may choose to use 3 types of memory formats.

  • torch.contiguous_format: default memory format, also referred as NHCW.
  • torch.channels_last: also referred as NHWC.
  • torch._mkldnn: mkldnn blocked format.
@rahulunair
rahulunair / pytorch_check_mkl_mkldnn.md
Created July 8, 2022 06:09 — forked from mingfeima/pytorch_check_mkl_mkldnn.md
BKMs to check whether mkl or mkldnn is enabled on PyTorch

BKMs to check whether mkl or mkldnn is enabled on PyTorch

PyTorch can be installed via different channels: conda, pip, docker, source code...

By default, mkl and mkl-dnn are enabled; But this might not always be true, so it is still useful to learn how to check this by yourself:

1. How to check whether mkl is enabled?

### check where your torch is installed
python -c 'import torch; print(torch.__path__)'
@rahulunair
rahulunair / pytorch_performance_profiling.md
Created July 8, 2022 06:06 — forked from mingfeima/pytorch_performance_profiling.md
How to do performance profiling on PyTorch

(Internal Tranining Material)

Usually the first step in performance optimization is to do profiling, e.g. to identify performance hotspots of a workload. This gist tells basic knowledge of performance profiling on PyTorch, you will get:

  • How to find the bottleneck operator?
  • How to trace source file of a particular operator?
  • How do I indentify threading issues? (oversubscription)
  • How do I tell a specific operator is running efficiently or not?

This tutorial takes one of my recent projects - pssp-transformer as an example to guide you through path of PyTorch CPU peformance optimization. Focus will be on Part 1 & Part 2.

@rahulunair
rahulunair / part_4_bfloat16_kernel_optimization.md
Created July 8, 2022 06:04 — forked from mingfeima/part_4_bfloat16_kernel_optimization.md
PyTorch CPU Performance Optimization Tutorial - Section IV
@rahulunair
rahulunair / part_3_vectorization_techniques.md
Created July 8, 2022 06:04 — forked from mingfeima/part_3_vectorization_techniques.md
PyTorch CPU Performance Optimization Tutorial - Section III
@rahulunair
rahulunair / part_2_parallelization_techniques.md
Created July 8, 2022 06:04 — forked from mingfeima/part_2_parallelization_techniques.md
PyTorch CPU Performance Optimization Tutorial - Section II
@rahulunair
rahulunair / pytorch_channels_last_perf_optimization.md
Created July 8, 2022 06:03 — forked from mingfeima/pytorch_channels_last_perf_optimization.md
PyTorch Channels Last memory format perf optimization and oneDNN integration plan.

PyTorch Channels Last Memory Format Performance Optimization on CPU Path

("mkldnn" has been renamed to "oneDNN", but exsiting PyTorch APIs still use "mkldnn", future work will align PyTorch user level APIs to "oneDNN")

Table of Contents

  • PyTorch Channels Last memory format introduction
  • oneDNN API for NHWC layout
  • Generic Channels Last memory format optimization with ATen native
  • oneDNN NHWC integration

NB: Memory format refers to data representation that describes how multidimensional arrays (nD) are stored in linear (1D) memory address space. Memory format has the same semantic with layout in oneDNN. Layout in PyTorch has other semantic ofdescribing dense or sparse with the attributes: 'torch.strided', 'torch.sparse_coo'.

@rahulunair
rahulunair / mini_sequence_labeler.py
Created January 24, 2019 20:56 — forked from hal3/mini_sequence_labeler.py
PyTorch implementation of a sequence labeler (POS taggger).
"""
PyTorch implementation of a sequence labeler (POS taggger).
Basic architecture:
- take words
- run though bidirectional GRU
- predict labels one word at a time (left to right), using a recurrent neural network "decoder"
The decoder updates hidden state based on:
- most recent word