SlideShare a Scribd company logo
2021.08.30
Mana Murakami, Solution Architect , NVIDIA
NVIDIA プロファイラを用いた
PYTORCH 学習最適化手法のご紹介
2
1. プロファイリングの重要性について
2. DLProf & Nsight Systems
3. まとめ
AGENDA
3
よくあるご質問
• GPU を学習に使用したら速くなったが、これ以上速くなるか分からない
• GPU を学習にしようしているが、GPU がどの程度使われているのかよく分からない
• そもそも最適化のステップが分からない
プロファイリングの重要性について
4
よくあるご質問
• GPU を学習に使用したら速くなったが、これ以上速くなるか分からない
• GPU を学習にしようしているが、GPU がどの程度使われているのかよく分からない
• そもそも最適化のステップが分からない
プロファイリングの重要性について
ボトルネック解析の為の便利なツールが
いくつか存在します
5
パフォーマンス最適化の限界
アムダ―ルの法則: トレーニングセッションの一部 (GPU で動作) を高速化すると、残りの部分 (CPU で動
作) が性能ボトルネックになる
プロファイリングの重要性について
Mixed Precision
(TF32/FP16/BF16)
MATH
(linear, conv, matmul)
MEMORY
(pointwise,
reductions)
OTHER
(data pipeline,
communication)
8-16x
1-2x 1x ~2x overall faster
training session time
Single Precision
FP32
GPU CPU
NVIDIA プロファイリング スタック
用途毎に使い分け可能な階層型プロファイル スタック
DLProf Viewer
Deep Learning Profiler (DLProf)
Nsight Systems
NVTX for
Tensorflow NVTX Plugins NVTX for PyTorch
NGC Optimized Framework Containers
NVIDIA COMPUTING PLATFORM
• Nsight Systems と Nsight Compute は CUPTI
(Profiling Tools Interface) ベースの GPU アプリケー
ションの為のプロファイラ
• NVTX (NVIDIA Tools Extension Library) は
ソースコードにアノテーションをする為の CUDA ライブラ
リ
• DLProf は内部で Nsight Systems を実行してプロファイ
ルデータを収集し、データサイエンティストが分かりやすい形
に整形して可視化
NEW
V1.0.0
6
7
性能最適化の為の便利なツール
DL Prof と Nsight Systems
データサイエンティストと
応用研究者
DLProf
<Nsight Systems w/ NVTX>
研究者と開発者
NVTX
Nsight Systems
Nsight Compute
アルゴリズム開発者 特定のドメイン向けのモデル開発や
アプリケーション開発者
8
性能最適化の為の便利なツール
DL Prof と Nsight Systems
データサイエンティストと
応用研究者
DLProf
<Nsight Systems w/ NVTX>
研究者と開発者
NVTX
Nsight Systems
Nsight Compute
アルゴリズム開発者 特定のドメイン向けのモデル開発や
アプリケーション開発者
アルゴリズムやフレームワーク開発者の為のプロファイルツール
オーバーヘッドも低く軽量でCUDA処理の流れを
細かく把握する事ができる
解析結果をデータサイエンティストが理解しやすい形に
整形・可視化して学習コードの最適化を支援
42
DLProf
10
DLProf とは?
DLProf :ディープラーニングモデルの為のプロファイリングツール
解析結果や最適化のアドバイスを表示
TensorFlow, PyTorch, TensorRT をサポート
11
DLProf とは?
ダッシュボード
• GPU 使用率チャート
• wall clock time のうち GPU がアクティブになっている割合の表示、複数 GPU の場合すべての GPU の平均利用率を示す
• オペレーション GPU 時間チャート :
• すべてのオペレーションを「Tensor コアを使用した処理」「Tensor コア使用できたが使用しなかった処理」「Tensor コアを使用する事が出来ない
処理」の 3つに分類してチャートを表示
CUDA カーネルの GPU 時間チャート:
•
• 全 CUDA カーネル実行時間を「カーネル内で Tensor コアを使用した時間」「カーネル内でメモリ処理を行っていた時間」「カーネル内のその他すべての
処理」の 3つに分類してチャートを表示
•
Tensor コア使用率チャート
• Tensor コアを使用した処理の全 GPU 時間に対する割合をチャートで表示
12
DLProf とは?
ダッシュボード
• 性能 サマリー:
• 実行時に重要な主要指標を一覧として表示 (実行時間、Tensor コア使用率、GPU 使用率など)
• イテレーション サマリー:
• 実行中に各イテレーションでかかった時間を示す棒グラフ。Tensor コアを使用した時間、Tensor コア以外でGPUを使用した時間、GPU を使用し
ていない時間のインテレーション毎の内訳が表示される。
• トップ 10 GPU オペレーション :
• 実行時間がかかっている上位10オペレーションをソートして表示。ボトルネックになっている箇所の特定に有効
13
DLProf のインストール
DLProf を使うには?
1. NGC 上で配布されている TensorFlow および PyTorch コンテナに同梱されている DLProf を使う (PyTorch と TensorFlow (1.x/2.x ))
•TensorFlow https://ngc.nvidia.com/catalog/containers/nvidia:tensorflow
•PyTorch https://ngc.nvidia.com/catalog/containers/nvidia:pytorch
2. Python pip 経由のインストール (PyTorch と TF2.x のみ)
• PyTorch の例: (py Index、DLProf および依存パッケージ、 DLProf Viewer Plugin for TensorBoard のインストール)
$ pip installnvidia-pyindex
$ pip installnvidia-dlprof[pytorch]
$ pip installnvidia-tensorboard-plugin-dlprof
14
DLProf のインストール
DLProf を使うには?
1. NGC 上で配布されている TensorFlow および PyTorch コンテナに同梱されている DLProf を使う (PyTorch と TensorFlow (1.x/2.x ))
•TensorFlow https://ngc.nvidia.com/catalog/containers/nvidia:tensorflow
•PyTorch https://ngc.nvidia.com/catalog/containers/nvidia:pytorch
2. Python pip 経由のインストール (PyTorch と TF2.x のみ)
• PyTorch の例: (py Index、DLProf および依存パッケージ、 DLProf Viewer Plugin for TensorBoard のインストール)
$ pip installnvidia-pyindex
$ pip installnvidia-dlprof[pytorch]
$ pip installnvidia-tensorboard-plugin-dlprof
NOTE:
NGCで配布されているDeep LearningコンテナをSingularityで動かす方法はAppendix.のブログを参照のこと
各コンテナに同梱されている DLProf のバージョンは以下のドキュメントで確認可能
https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/
15
DLProf のインストール
DLProf を使うには?
1. NGC 上で配布されている TensorFlow および PyTorch コンテナに同梱されている DLProf を使う (PyTorch と TensorFlow (1.x/2.x ))
•TensorFlow https://ngc.nvidia.com/catalog/containers/nvidia:tensorflow
•PyTorch https://ngc.nvidia.com/catalog/containers/nvidia:pytorch
2. Python pip 経由のインストール (PyTorch と TF1.x のみ)
• PyTorch の例: (py Index、DLProf および依存パッケージ、 DLProf Viewer Plugin for TensorBoard のインストール)
$ pip installnvidia-pyindex
$ pip installnvidia-dlprof[pytorch]
$ pip installnvidia-tensorboard-plugin-dlprof
NOTE:
CUDA toolkit および driver と依存関係がある為、構築環境の CUDA バージョンと互換性があるバー
ジョンを入れる必要がある
(参考)
https://docs.nvidia.com/deeplearning/frameworks/dlprof-release-notes/index.html
16
PyTorch スクリプトのプロファイル手順
DLProf を使うには?
1. プロファイル対象の PyTorch コードに以下を追加
2. DLProf の実行
3. DLProfViewer による結果の可視化
import nvidia_dlprof_pytorch_nvtx as nvtx
nvtx.init(enable_function_stack=True)
with torch.autograd.profiler.emit_nvtx():
for iter in range(iters):
#forward
#backward
$ dlprof --mode=pytorch python main.py
$ dlprofviewer –b 0.0.0.0 –p 8000 dlprof_dldb.sqlite
References:https://docs.nvidia.com/deeplearning/frameworks/dlprof-user-guide/index.html#quickstart_topic
17
PyTorch スクリプトのプロファイル手順
DLProf を使うには?
1. プロファイル対象の PyTorch コードに以下を追加
2. DLProf の実行
3. DLProfViewer による結果の可視化
import nvidia_dlprof_pytorch_nvtx as nvtx
nvtx.init(enable_function_stack=True)
with torch.autograd.profiler.emit_nvtx():
for iter in range(iters):
#forward
#backward
$ dlprof --mode=pytorch python main.py
$ dlprofviewer –b 0.0.0.0 –p 8000 dlprof_dldb.sqlite
DLProfの解析は時間がかかる為、イテレーション数を少なくするのが良い (10~20 mini-batchくらい)
--delayオプションを付けてwarmup部をスキップしてプロファイルする事も可能
References:https://docs.nvidia.com/deeplearning/frameworks/dlprof-user-guide/index.html#quickstart_topic
18
PyTorch スクリプトのプロファイル手順
DLProf を使うには?
1. プロファイル対象の PyTorch コードに以下を追加
2. DLProf の実行
3. DLProfViewer による結果の可視化
import nvidia_dlprof_pytorch_nvtx as nvtx
nvtx.init(enable_function_stack=True)
with torch.autograd.profiler.emit_nvtx():
for iter in range(iters):
#forward
#backward
$ dlprof --mode=pytorch python main.py
$ dlprofviewer –b 0.0.0.0 –p 8000 dlprof_dldb.sqlite
3行追加するだけ
References:https://docs.nvidia.com/deeplearning/frameworks/dlprof-user-guide/index.html#quickstart_topic
19
PyTorch スクリプトのプロファイル手順
DLProf を使うには?
1. プロファイル対象の PyTorch コードに以下を追加
2. DLProf の実行
3. DLProfViewer による結果の可視化
import nvidia_dlprof_pytorch_nvtx as nvtx
nvtx.init(enable_function_stack=True)
with torch.autograd.profiler.emit_nvtx():
for iter in range(iters):
#forward
#backward
$ dlprof --mode=pytorch python main.py
$ dlprofviewer –b 0.0.0.0 –p 8000 dlprof_dldb.sqlite
特にファイル名を指定せずに実行した場合、「dlprof_dldb.sqlite」と「nsys_profile.sqlite」が
出力される
Dlprofviewerには「dlprof_dldb.sqlite」を指定する必要がある
References:https://docs.nvidia.com/deeplearning/frameworks/dlprof-user-guide/index.html#quickstart_topic
20
PyTorch スクリプトのプロファイル手順
DLProf を使うには?
1. プロファイル対象の PyTorch コードに以下を追加
2. DLProf の実行
3. DLProfViewer による結果の可視化
import nvidia_dlprof_pytorch_nvtx as nvtx
nvtx.init(enable_function_stack=True)
with torch.autograd.profiler.emit_nvtx():
for iter in range(iters):
#forward
#backward
$ dlprof --mode=pytorch python main.py
$ dlprofviewer –b 0.0.0.0 –p 8000 dlprof_dldb.sqlite
特にファイル名を指定せずに実行した場合、「dlprof_dldb.sqlite」と「nsys_profile.sqlite」が
出力される
Dlprofviewerには「dlprof_dldb.sqlite」を指定
References:https://docs.nvidia.com/deeplearning/frameworks/dlprof-user-guide/index.html#quickstart_topic
21
例: DLProf + DLProfViewer によるプロファイル結果
GPU 最適化前 (AMP未使用/バッチサイズ小)
全実行時間の殆どがCPU処理
なのが一目で分かる
22
例: DLProf + DLProfViewer によるプロファイル結果
GPU 最適化前 (AMP未使用/バッチサイズ小)
全実行時間の殆どがCPU処理
なのが一目で分かる
“Problem detected:”と”Recommended Change:”
が表示され、問題点が分かる
23
42
NVIDIA NSIGHT
SYSTEMS
24
NSIGHT ツールワークフロー
新しくなった CUDA プロファイルツール群
Nsight Systems
包括的なシステムレベルの性能確認
Nsight Compute
CUDA カーネル詳細性能確認用
Nsight Graphics
フレーム/レンダー詳細性能確認
メトリック/カウンタを用いた
CUDAカーネル単位の詳細
性能確認
グラフィックフレーム単位の
詳細プロファイル
スタート
全体的なパフォーマンスを
再確認
全体的なパフォーマンス
を再確認
https://developer.nvidia.com/nsight-systems
25
Nsight Systems
主な機能:
• システム全体のアルゴリズム最適化
• マルチプロセスのアプリケーション解析のサポート
• アプリケーション内のボトルネックを探しに有効
• 非常に高速なGUIタイムライン上で何百万ものイベントを視覚化
• コマンドライン、IDE(統合型開発環境)の両方に対応
OS: Linux (x86, Power, Arm SBSA, Tegra), Windows, MacOSX (host)
GPUs: Pascal+
新しくなった CUDA プロファイルツール群
$ nsys profile –t cuda,osrt,nvtx,cudnn,cublas –o inference_result.qdstrm –w true
python inference.py
https://developer.nvidia.com/nsight-systems
26
CPU
utilization
Processes &
threads
OS runtime
APIs
CUDA &
cuBLAS APIs
GPU CUDA
Kernels & memory
transfers
CPU IP &
backtrace
sample data
NVTX
annotations
NVTX projected on
GPU CUDA streams
27
開発環境に NSIGHT SYSTEMS がインストールされていない場合
Setting Up and Using Nsight Systems Inside Containers
CUDA 11.4: install
CUDA 11.3: install
CUDA 11.2: install
Mapping an Nsight Systems Host Installation into a Container
NSIGHT SYTEMS
$ apt-get update –y
$ apt-get install -y cuda-nsight-systems-11-3 nsight-systems-2021.1.3
$ apt-get update –y
$ apt-get install -y cuda-nsight-systems-11-2 nsight-systems-2020.4.3
$ docker run --rm -it --network=host --gpus=all -v /opt/nvidia/nsight-systems/2021.1.3:/opt/nvidia/nsight-systems/2021.1.3 
nvcr.io/nvidia/pytorch:21.08-py3 bash
$ apt-get update –y
$ apt-get install -y cuda-nsight-systems-11-4 nsight-systems-2021.2.4
28
NSIGHT SYSTEMS を使うには?
Example
cuda – GPU kernel
osrt – OS runtime
nvtx – NVIDIA Tools Extension
cublas – CUDA BLAS library
https://docs.nvidia.com/nsight-systems/2020.3/profiling/index.html#cli-options
NSIGHT SYTEMS
$ nsys profile -t nvtx,cuda,osrt,cublas 
--stats=true 
-f true 
-o pusch_result 
python main.py
APIs to be traced
Outputs profiling information similar to nvprof
Overwrite the output
Output filename
29
NSIGHT SYSTEMS を使うには?
Example
cuda – GPU kernel
osrt – OS runtime
nvtx – NVIDIA Tools Extension
cublas – CUDA BLAS library
https://docs.nvidia.com/nsight-systems/2020.3/profiling/index.html#cli-options
NSIGHT SYTEMS
$ nsys profile -t nvtx,cuda,osrt,cublas 
--stats=true 
-f true 
-o pusch_result 
python main.py
APIs to be traced
Outputs profiling information similar to nvprof
Overwrite the output
Output filename
Other Userful Options
• --delay (-y) : Collection start delay in seconds
• --duration(-d): Collection duration in seconds.
• --capture-range(-c): none/cudaProfilerApi/nvtx
etc..
30
例: Nsight Systems + NVTX
Nsight Systems プロファイル結果(NVTX あり)
前処理
11.07sec 推論処理(10iteration) 28.924sec
1iteration
アノテーションする事で
タイムライン上で処理を把握しやすくなる!
31
Appendix. 技術ブログ・関連セッション
Deep Learning Examples
• https://github.com/NVIDIA/DeepLearningExamples/
How to Run NGC Deep Learning Containers with Singularity
• https://developer.nvidia.com/blog/how-to-run-ngc-deep-learning-containers-with-singularity/
Profiling and Optimizing Deep Neural Networks with DLProf and PyProf (TensorFlow)
• https://developer.nvidia.com/blog/profiling-and-optimizing-deep-neural-networks-with-dlprof-and-pyprof/
Deep Learning Performance Optimization with Profiling Tools
• https://www.nvidia.com/en-us/on-demand/session/gtcspring21-s31228/
Profiling and Optimizing Deep Neural Networks with DLProf and PyProf
• https://www.nvidia.com/en-us/on-demand/session/gtcspring21-s31341/
PyTorch Performance Tuning Guide
• https://www.nvidia.com/en-us/on-demand/session/gtcspring21-s31831/
NVIDIA プロファイラを用いた Pytorch 学習最適化手法のご紹介
THANK YOU!

More Related Content

What's hot

A100 GPU 搭載! P4d インスタンス 使いこなしのコツ
A100 GPU 搭載! P4d インスタンス使いこなしのコツA100 GPU 搭載! P4d インスタンス使いこなしのコツ
A100 GPU 搭載! P4d インスタンス 使いこなしのコツ
Kuninobu SaSaki
 
NVIDIA GPUで作るHeadless X11 Linux
NVIDIA GPUで作るHeadless X11 LinuxNVIDIA GPUで作るHeadless X11 Linux
NVIDIA GPUで作るHeadless X11 Linux
Tomoki SHISHIKURA
 
最適輸送入門
最適輸送入門最適輸送入門
最適輸送入門
joisino
 
モデル高速化百選
モデル高速化百選モデル高速化百選
モデル高速化百選
Yusuke Uchida
 
【DL輪読会】ViT + Self Supervised Learningまとめ
【DL輪読会】ViT + Self Supervised Learningまとめ【DL輪読会】ViT + Self Supervised Learningまとめ
【DL輪読会】ViT + Self Supervised Learningまとめ
Deep Learning JP
 
モデルアーキテクチャ観点からの高速化2019
モデルアーキテクチャ観点からの高速化2019モデルアーキテクチャ観点からの高速化2019
モデルアーキテクチャ観点からの高速化2019
Yusuke Uchida
 
Active Learning 入門
Active Learning 入門Active Learning 入門
Active Learning 入門Shuyo Nakatani
 
モバイル向けEdgeTPUの紹介
モバイル向けEdgeTPUの紹介モバイル向けEdgeTPUの紹介
モバイル向けEdgeTPUの紹介
卓然 郭
 
【メタサーベイ】Vision and Language のトップ研究室/研究者
【メタサーベイ】Vision and Language のトップ研究室/研究者【メタサーベイ】Vision and Language のトップ研究室/研究者
【メタサーベイ】Vision and Language のトップ研究室/研究者
cvpaper. challenge
 
Automatic Mixed Precision の紹介
Automatic Mixed Precision の紹介Automatic Mixed Precision の紹介
Automatic Mixed Precision の紹介
Kuninobu SaSaki
 
[GTCJ2018]CuPy -NumPy互換GPUライブラリによるPythonでの高速計算- PFN奥田遼介
[GTCJ2018]CuPy -NumPy互換GPUライブラリによるPythonでの高速計算- PFN奥田遼介[GTCJ2018]CuPy -NumPy互換GPUライブラリによるPythonでの高速計算- PFN奥田遼介
[GTCJ2018]CuPy -NumPy互換GPUライブラリによるPythonでの高速計算- PFN奥田遼介
Preferred Networks
 
優れた研究論文の書き方
優れた研究論文の書き方優れた研究論文の書き方
優れた研究論文の書き方
Masanori Kado
 
【メタサーベイ】基盤モデル / Foundation Models
【メタサーベイ】基盤モデル / Foundation Models【メタサーベイ】基盤モデル / Foundation Models
【メタサーベイ】基盤モデル / Foundation Models
cvpaper. challenge
 
SSII2022 [SS1] ニューラル3D表現の最新動向〜 ニューラルネットでなんでも表せる?? 〜​
SSII2022 [SS1] ニューラル3D表現の最新動向〜 ニューラルネットでなんでも表せる?? 〜​SSII2022 [SS1] ニューラル3D表現の最新動向〜 ニューラルネットでなんでも表せる?? 〜​
SSII2022 [SS1] ニューラル3D表現の最新動向〜 ニューラルネットでなんでも表せる?? 〜​
SSII
 
【DL輪読会】言語以外でのTransformerのまとめ (ViT, Perceiver, Frozen Pretrained Transformer etc)
【DL輪読会】言語以外でのTransformerのまとめ (ViT, Perceiver, Frozen Pretrained Transformer etc)【DL輪読会】言語以外でのTransformerのまとめ (ViT, Perceiver, Frozen Pretrained Transformer etc)
【DL輪読会】言語以外でのTransformerのまとめ (ViT, Perceiver, Frozen Pretrained Transformer etc)
Deep Learning JP
 
ドメイン適応の原理と応用
ドメイン適応の原理と応用ドメイン適応の原理と応用
ドメイン適応の原理と応用
Yoshitaka Ushiku
 
PFNのML/DL基盤を支えるKubernetesにおける自動化 / DevOpsDays Tokyo 2021
PFNのML/DL基盤を支えるKubernetesにおける自動化 / DevOpsDays Tokyo 2021PFNのML/DL基盤を支えるKubernetesにおける自動化 / DevOpsDays Tokyo 2021
PFNのML/DL基盤を支えるKubernetesにおける自動化 / DevOpsDays Tokyo 2021
Preferred Networks
 
Word Tour: One-dimensional Word Embeddings via the Traveling Salesman Problem...
Word Tour: One-dimensional Word Embeddings via the Traveling Salesman Problem...Word Tour: One-dimensional Word Embeddings via the Traveling Salesman Problem...
Word Tour: One-dimensional Word Embeddings via the Traveling Salesman Problem...
joisino
 
PyTorchLightning ベース Hydra+MLFlow+Optuna による機械学習開発環境の構築
PyTorchLightning ベース Hydra+MLFlow+Optuna による機械学習開発環境の構築PyTorchLightning ベース Hydra+MLFlow+Optuna による機械学習開発環境の構築
PyTorchLightning ベース Hydra+MLFlow+Optuna による機械学習開発環境の構築
Kosuke Shinoda
 
EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monoc...
EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monoc...EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monoc...
EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monoc...
Kazuyuki Miyazawa
 

What's hot (20)

A100 GPU 搭載! P4d インスタンス 使いこなしのコツ
A100 GPU 搭載! P4d インスタンス使いこなしのコツA100 GPU 搭載! P4d インスタンス使いこなしのコツ
A100 GPU 搭載! P4d インスタンス 使いこなしのコツ
 
NVIDIA GPUで作るHeadless X11 Linux
NVIDIA GPUで作るHeadless X11 LinuxNVIDIA GPUで作るHeadless X11 Linux
NVIDIA GPUで作るHeadless X11 Linux
 
最適輸送入門
最適輸送入門最適輸送入門
最適輸送入門
 
モデル高速化百選
モデル高速化百選モデル高速化百選
モデル高速化百選
 
【DL輪読会】ViT + Self Supervised Learningまとめ
【DL輪読会】ViT + Self Supervised Learningまとめ【DL輪読会】ViT + Self Supervised Learningまとめ
【DL輪読会】ViT + Self Supervised Learningまとめ
 
モデルアーキテクチャ観点からの高速化2019
モデルアーキテクチャ観点からの高速化2019モデルアーキテクチャ観点からの高速化2019
モデルアーキテクチャ観点からの高速化2019
 
Active Learning 入門
Active Learning 入門Active Learning 入門
Active Learning 入門
 
モバイル向けEdgeTPUの紹介
モバイル向けEdgeTPUの紹介モバイル向けEdgeTPUの紹介
モバイル向けEdgeTPUの紹介
 
【メタサーベイ】Vision and Language のトップ研究室/研究者
【メタサーベイ】Vision and Language のトップ研究室/研究者【メタサーベイ】Vision and Language のトップ研究室/研究者
【メタサーベイ】Vision and Language のトップ研究室/研究者
 
Automatic Mixed Precision の紹介
Automatic Mixed Precision の紹介Automatic Mixed Precision の紹介
Automatic Mixed Precision の紹介
 
[GTCJ2018]CuPy -NumPy互換GPUライブラリによるPythonでの高速計算- PFN奥田遼介
[GTCJ2018]CuPy -NumPy互換GPUライブラリによるPythonでの高速計算- PFN奥田遼介[GTCJ2018]CuPy -NumPy互換GPUライブラリによるPythonでの高速計算- PFN奥田遼介
[GTCJ2018]CuPy -NumPy互換GPUライブラリによるPythonでの高速計算- PFN奥田遼介
 
優れた研究論文の書き方
優れた研究論文の書き方優れた研究論文の書き方
優れた研究論文の書き方
 
【メタサーベイ】基盤モデル / Foundation Models
【メタサーベイ】基盤モデル / Foundation Models【メタサーベイ】基盤モデル / Foundation Models
【メタサーベイ】基盤モデル / Foundation Models
 
SSII2022 [SS1] ニューラル3D表現の最新動向〜 ニューラルネットでなんでも表せる?? 〜​
SSII2022 [SS1] ニューラル3D表現の最新動向〜 ニューラルネットでなんでも表せる?? 〜​SSII2022 [SS1] ニューラル3D表現の最新動向〜 ニューラルネットでなんでも表せる?? 〜​
SSII2022 [SS1] ニューラル3D表現の最新動向〜 ニューラルネットでなんでも表せる?? 〜​
 
【DL輪読会】言語以外でのTransformerのまとめ (ViT, Perceiver, Frozen Pretrained Transformer etc)
【DL輪読会】言語以外でのTransformerのまとめ (ViT, Perceiver, Frozen Pretrained Transformer etc)【DL輪読会】言語以外でのTransformerのまとめ (ViT, Perceiver, Frozen Pretrained Transformer etc)
【DL輪読会】言語以外でのTransformerのまとめ (ViT, Perceiver, Frozen Pretrained Transformer etc)
 
ドメイン適応の原理と応用
ドメイン適応の原理と応用ドメイン適応の原理と応用
ドメイン適応の原理と応用
 
PFNのML/DL基盤を支えるKubernetesにおける自動化 / DevOpsDays Tokyo 2021
PFNのML/DL基盤を支えるKubernetesにおける自動化 / DevOpsDays Tokyo 2021PFNのML/DL基盤を支えるKubernetesにおける自動化 / DevOpsDays Tokyo 2021
PFNのML/DL基盤を支えるKubernetesにおける自動化 / DevOpsDays Tokyo 2021
 
Word Tour: One-dimensional Word Embeddings via the Traveling Salesman Problem...
Word Tour: One-dimensional Word Embeddings via the Traveling Salesman Problem...Word Tour: One-dimensional Word Embeddings via the Traveling Salesman Problem...
Word Tour: One-dimensional Word Embeddings via the Traveling Salesman Problem...
 
PyTorchLightning ベース Hydra+MLFlow+Optuna による機械学習開発環境の構築
PyTorchLightning ベース Hydra+MLFlow+Optuna による機械学習開発環境の構築PyTorchLightning ベース Hydra+MLFlow+Optuna による機械学習開発環境の構築
PyTorchLightning ベース Hydra+MLFlow+Optuna による機械学習開発環境の構築
 
EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monoc...
EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monoc...EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monoc...
EPro-PnP: Generalized End-to-End Probabilistic Perspective-n-Points for Monoc...
 

Similar to 「NVIDIA プロファイラを用いたPyTorch学習最適化手法のご紹介(修正前 typoあり)」

ディープラーニングイメージで構築する快適・高速な機械学習環境
ディープラーニングイメージで構築する快適・高速な機械学習環境ディープラーニングイメージで構築する快適・高速な機械学習環境
ディープラーニングイメージで構築する快適・高速な機械学習環境
Yaboo Oyabu
 
20170421 tensor flowusergroup
20170421 tensor flowusergroup20170421 tensor flowusergroup
20170421 tensor flowusergroup
ManaMurakami1
 
[GTCJ2018] Optimizing Deep Learning with Chainer PFN得居誠也
[GTCJ2018] Optimizing Deep Learning with Chainer PFN得居誠也[GTCJ2018] Optimizing Deep Learning with Chainer PFN得居誠也
[GTCJ2018] Optimizing Deep Learning with Chainer PFN得居誠也
Preferred Networks
 
エヌビディアが加速するディープラーニング ~進化するニューラルネットワークとその開発方法について~
エヌビディアが加速するディープラーニング ~進化するニューラルネットワークとその開発方法について~エヌビディアが加速するディープラーニング ~進化するニューラルネットワークとその開発方法について~
エヌビディアが加速するディープラーニング ~進化するニューラルネットワークとその開発方法について~
NVIDIA Japan
 
機械学習プロジェクトにおける Cloud AI Platform の使い方 (2018-11-19)
機械学習プロジェクトにおける Cloud AI Platform の使い方 (2018-11-19)機械学習プロジェクトにおける Cloud AI Platform の使い方 (2018-11-19)
機械学習プロジェクトにおける Cloud AI Platform の使い方 (2018-11-19)
Yaboo Oyabu
 
EnrootとPyxisで快適コンテナ生活
EnrootとPyxisで快適コンテナ生活EnrootとPyxisで快適コンテナ生活
EnrootとPyxisで快適コンテナ生活
Kuninobu SaSaki
 
Anaconda & NumbaPro 使ってみた
Anaconda & NumbaPro 使ってみたAnaconda & NumbaPro 使ってみた
Anaconda & NumbaPro 使ってみた
Yosuke Onoue
 
続・PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜 #2
続・PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜 #2続・PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜 #2
続・PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜 #2
Preferred Networks
 
OpenStackを使用したGPU仮想化IaaS環境 事例紹介
OpenStackを使用したGPU仮想化IaaS環境 事例紹介OpenStackを使用したGPU仮想化IaaS環境 事例紹介
OpenStackを使用したGPU仮想化IaaS環境 事例紹介
VirtualTech Japan Inc.
 
What's new in open shift container platform 4.7 japan_20210318
What's new in open shift container platform 4.7 japan_20210318What's new in open shift container platform 4.7 japan_20210318
What's new in open shift container platform 4.7 japan_20210318
Yuhki Hanada
 
Deep Learning Implementations: pylearn2 and torch7 (JNNS 2015)
Deep Learning Implementations: pylearn2 and torch7 (JNNS 2015)Deep Learning Implementations: pylearn2 and torch7 (JNNS 2015)
Deep Learning Implementations: pylearn2 and torch7 (JNNS 2015)
Kotaro Nakayama
 
How to run P4 BMv2
How to run P4 BMv2How to run P4 BMv2
How to run P4 BMv2
Kentaro Ebisawa
 
20170726 py data.tokyo
20170726 py data.tokyo20170726 py data.tokyo
20170726 py data.tokyo
ManaMurakami1
 
はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入
Yu Nobuoka
 
Unity2018/2019における最適化事情
Unity2018/2019における最適化事情Unity2018/2019における最適化事情
Unity2018/2019における最適化事情
Unity Technologies Japan K.K.
 
20160720 aws development-tools-and_hybrid_cdp
20160720 aws development-tools-and_hybrid_cdp20160720 aws development-tools-and_hybrid_cdp
20160720 aws development-tools-and_hybrid_cdp
Yukitaka Ohmura
 
機械学習 / Deep Learning 大全 (6) Library編
機械学習 / Deep Learning 大全 (6) Library編機械学習 / Deep Learning 大全 (6) Library編
機械学習 / Deep Learning 大全 (6) Library編
Daiyu Hatakeyama
 
【Unite Tokyo 2019】運用中超大規模タイトルにおけるUnityアップデート課題の解決手法と事例
【Unite Tokyo 2019】運用中超大規模タイトルにおけるUnityアップデート課題の解決手法と事例【Unite Tokyo 2019】運用中超大規模タイトルにおけるUnityアップデート課題の解決手法と事例
【Unite Tokyo 2019】運用中超大規模タイトルにおけるUnityアップデート課題の解決手法と事例
UnityTechnologiesJapan002
 
実践! Argo cd &amp; rollouts による canary release(cndt2021)
実践! Argo cd &amp; rollouts による canary release(cndt2021) 実践! Argo cd &amp; rollouts による canary release(cndt2021)
実践! Argo cd &amp; rollouts による canary release(cndt2021)
HayatoOkuma1
 

Similar to 「NVIDIA プロファイラを用いたPyTorch学習最適化手法のご紹介(修正前 typoあり)」 (20)

ディープラーニングイメージで構築する快適・高速な機械学習環境
ディープラーニングイメージで構築する快適・高速な機械学習環境ディープラーニングイメージで構築する快適・高速な機械学習環境
ディープラーニングイメージで構築する快適・高速な機械学習環境
 
20170421 tensor flowusergroup
20170421 tensor flowusergroup20170421 tensor flowusergroup
20170421 tensor flowusergroup
 
[GTCJ2018] Optimizing Deep Learning with Chainer PFN得居誠也
[GTCJ2018] Optimizing Deep Learning with Chainer PFN得居誠也[GTCJ2018] Optimizing Deep Learning with Chainer PFN得居誠也
[GTCJ2018] Optimizing Deep Learning with Chainer PFN得居誠也
 
エヌビディアが加速するディープラーニング ~進化するニューラルネットワークとその開発方法について~
エヌビディアが加速するディープラーニング ~進化するニューラルネットワークとその開発方法について~エヌビディアが加速するディープラーニング ~進化するニューラルネットワークとその開発方法について~
エヌビディアが加速するディープラーニング ~進化するニューラルネットワークとその開発方法について~
 
機械学習プロジェクトにおける Cloud AI Platform の使い方 (2018-11-19)
機械学習プロジェクトにおける Cloud AI Platform の使い方 (2018-11-19)機械学習プロジェクトにおける Cloud AI Platform の使い方 (2018-11-19)
機械学習プロジェクトにおける Cloud AI Platform の使い方 (2018-11-19)
 
EnrootとPyxisで快適コンテナ生活
EnrootとPyxisで快適コンテナ生活EnrootとPyxisで快適コンテナ生活
EnrootとPyxisで快適コンテナ生活
 
Anaconda & NumbaPro 使ってみた
Anaconda & NumbaPro 使ってみたAnaconda & NumbaPro 使ってみた
Anaconda & NumbaPro 使ってみた
 
続・PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜 #2
続・PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜 #2続・PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜 #2
続・PFN のオンプレML基盤の取り組み / オンプレML基盤 on Kubernetes 〜PFN、ヤフー〜 #2
 
OpenStackを使用したGPU仮想化IaaS環境 事例紹介
OpenStackを使用したGPU仮想化IaaS環境 事例紹介OpenStackを使用したGPU仮想化IaaS環境 事例紹介
OpenStackを使用したGPU仮想化IaaS環境 事例紹介
 
What's new in open shift container platform 4.7 japan_20210318
What's new in open shift container platform 4.7 japan_20210318What's new in open shift container platform 4.7 japan_20210318
What's new in open shift container platform 4.7 japan_20210318
 
Deep Learning Implementations: pylearn2 and torch7 (JNNS 2015)
Deep Learning Implementations: pylearn2 and torch7 (JNNS 2015)Deep Learning Implementations: pylearn2 and torch7 (JNNS 2015)
Deep Learning Implementations: pylearn2 and torch7 (JNNS 2015)
 
How to run P4 BMv2
How to run P4 BMv2How to run P4 BMv2
How to run P4 BMv2
 
20170726 py data.tokyo
20170726 py data.tokyo20170726 py data.tokyo
20170726 py data.tokyo
 
はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入
 
Unity2018/2019における最適化事情
Unity2018/2019における最適化事情Unity2018/2019における最適化事情
Unity2018/2019における最適化事情
 
20160720 aws development-tools-and_hybrid_cdp
20160720 aws development-tools-and_hybrid_cdp20160720 aws development-tools-and_hybrid_cdp
20160720 aws development-tools-and_hybrid_cdp
 
機械学習 / Deep Learning 大全 (6) Library編
機械学習 / Deep Learning 大全 (6) Library編機械学習 / Deep Learning 大全 (6) Library編
機械学習 / Deep Learning 大全 (6) Library編
 
【Unite Tokyo 2019】運用中超大規模タイトルにおけるUnityアップデート課題の解決手法と事例
【Unite Tokyo 2019】運用中超大規模タイトルにおけるUnityアップデート課題の解決手法と事例【Unite Tokyo 2019】運用中超大規模タイトルにおけるUnityアップデート課題の解決手法と事例
【Unite Tokyo 2019】運用中超大規模タイトルにおけるUnityアップデート課題の解決手法と事例
 
実践! Argo cd &amp; rollouts による canary release(cndt2021)
実践! Argo cd &amp; rollouts による canary release(cndt2021) 実践! Argo cd &amp; rollouts による canary release(cndt2021)
実践! Argo cd &amp; rollouts による canary release(cndt2021)
 
20130126 sc12-reading
20130126 sc12-reading20130126 sc12-reading
20130126 sc12-reading
 

More from ManaMurakami1

20170518 eureka dli
20170518 eureka dli20170518 eureka dli
20170518 eureka dli
ManaMurakami1
 
20161210 jawsai
20161210 jawsai20161210 jawsai
20161210 jawsai
ManaMurakami1
 
20161122 gpu deep_learningcommunity#02
20161122 gpu deep_learningcommunity#0220161122 gpu deep_learningcommunity#02
20161122 gpu deep_learningcommunity#02
ManaMurakami1
 
20161121 open hyperscale#6
20161121 open hyperscale#620161121 open hyperscale#6
20161121 open hyperscale#6
ManaMurakami1
 
20160902 hyperscale #04
20160902 hyperscale #0420160902 hyperscale #04
20160902 hyperscale #04
ManaMurakami1
 
20160728 hyperscale #03
20160728 hyperscale #0320160728 hyperscale #03
20160728 hyperscale #03
ManaMurakami1
 
OHS#2 GREでディープラーニング学習REST APIを作る
OHS#2 GREでディープラーニング学習REST APIを作るOHS#2 GREでディープラーニング学習REST APIを作る
OHS#2 GREでディープラーニング学習REST APIを作る
ManaMurakami1
 

More from ManaMurakami1 (7)

20170518 eureka dli
20170518 eureka dli20170518 eureka dli
20170518 eureka dli
 
20161210 jawsai
20161210 jawsai20161210 jawsai
20161210 jawsai
 
20161122 gpu deep_learningcommunity#02
20161122 gpu deep_learningcommunity#0220161122 gpu deep_learningcommunity#02
20161122 gpu deep_learningcommunity#02
 
20161121 open hyperscale#6
20161121 open hyperscale#620161121 open hyperscale#6
20161121 open hyperscale#6
 
20160902 hyperscale #04
20160902 hyperscale #0420160902 hyperscale #04
20160902 hyperscale #04
 
20160728 hyperscale #03
20160728 hyperscale #0320160728 hyperscale #03
20160728 hyperscale #03
 
OHS#2 GREでディープラーニング学習REST APIを作る
OHS#2 GREでディープラーニング学習REST APIを作るOHS#2 GREでディープラーニング学習REST APIを作る
OHS#2 GREでディープラーニング学習REST APIを作る
 

「NVIDIA プロファイラを用いたPyTorch学習最適化手法のご紹介(修正前 typoあり)」

  • 1. 2021.08.30 Mana Murakami, Solution Architect , NVIDIA NVIDIA プロファイラを用いた PYTORCH 学習最適化手法のご紹介
  • 3. 3 よくあるご質問 • GPU を学習に使用したら速くなったが、これ以上速くなるか分からない • GPU を学習にしようしているが、GPU がどの程度使われているのかよく分からない • そもそも最適化のステップが分からない プロファイリングの重要性について
  • 4. 4 よくあるご質問 • GPU を学習に使用したら速くなったが、これ以上速くなるか分からない • GPU を学習にしようしているが、GPU がどの程度使われているのかよく分からない • そもそも最適化のステップが分からない プロファイリングの重要性について ボトルネック解析の為の便利なツールが いくつか存在します
  • 5. 5 パフォーマンス最適化の限界 アムダ―ルの法則: トレーニングセッションの一部 (GPU で動作) を高速化すると、残りの部分 (CPU で動 作) が性能ボトルネックになる プロファイリングの重要性について Mixed Precision (TF32/FP16/BF16) MATH (linear, conv, matmul) MEMORY (pointwise, reductions) OTHER (data pipeline, communication) 8-16x 1-2x 1x ~2x overall faster training session time Single Precision FP32 GPU CPU
  • 6. NVIDIA プロファイリング スタック 用途毎に使い分け可能な階層型プロファイル スタック DLProf Viewer Deep Learning Profiler (DLProf) Nsight Systems NVTX for Tensorflow NVTX Plugins NVTX for PyTorch NGC Optimized Framework Containers NVIDIA COMPUTING PLATFORM • Nsight Systems と Nsight Compute は CUPTI (Profiling Tools Interface) ベースの GPU アプリケー ションの為のプロファイラ • NVTX (NVIDIA Tools Extension Library) は ソースコードにアノテーションをする為の CUDA ライブラ リ • DLProf は内部で Nsight Systems を実行してプロファイ ルデータを収集し、データサイエンティストが分かりやすい形 に整形して可視化 NEW V1.0.0 6
  • 7. 7 性能最適化の為の便利なツール DL Prof と Nsight Systems データサイエンティストと 応用研究者 DLProf <Nsight Systems w/ NVTX> 研究者と開発者 NVTX Nsight Systems Nsight Compute アルゴリズム開発者 特定のドメイン向けのモデル開発や アプリケーション開発者
  • 8. 8 性能最適化の為の便利なツール DL Prof と Nsight Systems データサイエンティストと 応用研究者 DLProf <Nsight Systems w/ NVTX> 研究者と開発者 NVTX Nsight Systems Nsight Compute アルゴリズム開発者 特定のドメイン向けのモデル開発や アプリケーション開発者 アルゴリズムやフレームワーク開発者の為のプロファイルツール オーバーヘッドも低く軽量でCUDA処理の流れを 細かく把握する事ができる 解析結果をデータサイエンティストが理解しやすい形に 整形・可視化して学習コードの最適化を支援
  • 11. 11 DLProf とは? ダッシュボード • GPU 使用率チャート • wall clock time のうち GPU がアクティブになっている割合の表示、複数 GPU の場合すべての GPU の平均利用率を示す • オペレーション GPU 時間チャート : • すべてのオペレーションを「Tensor コアを使用した処理」「Tensor コア使用できたが使用しなかった処理」「Tensor コアを使用する事が出来ない 処理」の 3つに分類してチャートを表示 CUDA カーネルの GPU 時間チャート: • • 全 CUDA カーネル実行時間を「カーネル内で Tensor コアを使用した時間」「カーネル内でメモリ処理を行っていた時間」「カーネル内のその他すべての 処理」の 3つに分類してチャートを表示 • Tensor コア使用率チャート • Tensor コアを使用した処理の全 GPU 時間に対する割合をチャートで表示
  • 12. 12 DLProf とは? ダッシュボード • 性能 サマリー: • 実行時に重要な主要指標を一覧として表示 (実行時間、Tensor コア使用率、GPU 使用率など) • イテレーション サマリー: • 実行中に各イテレーションでかかった時間を示す棒グラフ。Tensor コアを使用した時間、Tensor コア以外でGPUを使用した時間、GPU を使用し ていない時間のインテレーション毎の内訳が表示される。 • トップ 10 GPU オペレーション : • 実行時間がかかっている上位10オペレーションをソートして表示。ボトルネックになっている箇所の特定に有効
  • 13. 13 DLProf のインストール DLProf を使うには? 1. NGC 上で配布されている TensorFlow および PyTorch コンテナに同梱されている DLProf を使う (PyTorch と TensorFlow (1.x/2.x )) •TensorFlow https://ngc.nvidia.com/catalog/containers/nvidia:tensorflow •PyTorch https://ngc.nvidia.com/catalog/containers/nvidia:pytorch 2. Python pip 経由のインストール (PyTorch と TF2.x のみ) • PyTorch の例: (py Index、DLProf および依存パッケージ、 DLProf Viewer Plugin for TensorBoard のインストール) $ pip installnvidia-pyindex $ pip installnvidia-dlprof[pytorch] $ pip installnvidia-tensorboard-plugin-dlprof
  • 14. 14 DLProf のインストール DLProf を使うには? 1. NGC 上で配布されている TensorFlow および PyTorch コンテナに同梱されている DLProf を使う (PyTorch と TensorFlow (1.x/2.x )) •TensorFlow https://ngc.nvidia.com/catalog/containers/nvidia:tensorflow •PyTorch https://ngc.nvidia.com/catalog/containers/nvidia:pytorch 2. Python pip 経由のインストール (PyTorch と TF2.x のみ) • PyTorch の例: (py Index、DLProf および依存パッケージ、 DLProf Viewer Plugin for TensorBoard のインストール) $ pip installnvidia-pyindex $ pip installnvidia-dlprof[pytorch] $ pip installnvidia-tensorboard-plugin-dlprof NOTE: NGCで配布されているDeep LearningコンテナをSingularityで動かす方法はAppendix.のブログを参照のこと 各コンテナに同梱されている DLProf のバージョンは以下のドキュメントで確認可能 https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/
  • 15. 15 DLProf のインストール DLProf を使うには? 1. NGC 上で配布されている TensorFlow および PyTorch コンテナに同梱されている DLProf を使う (PyTorch と TensorFlow (1.x/2.x )) •TensorFlow https://ngc.nvidia.com/catalog/containers/nvidia:tensorflow •PyTorch https://ngc.nvidia.com/catalog/containers/nvidia:pytorch 2. Python pip 経由のインストール (PyTorch と TF1.x のみ) • PyTorch の例: (py Index、DLProf および依存パッケージ、 DLProf Viewer Plugin for TensorBoard のインストール) $ pip installnvidia-pyindex $ pip installnvidia-dlprof[pytorch] $ pip installnvidia-tensorboard-plugin-dlprof NOTE: CUDA toolkit および driver と依存関係がある為、構築環境の CUDA バージョンと互換性があるバー ジョンを入れる必要がある (参考) https://docs.nvidia.com/deeplearning/frameworks/dlprof-release-notes/index.html
  • 16. 16 PyTorch スクリプトのプロファイル手順 DLProf を使うには? 1. プロファイル対象の PyTorch コードに以下を追加 2. DLProf の実行 3. DLProfViewer による結果の可視化 import nvidia_dlprof_pytorch_nvtx as nvtx nvtx.init(enable_function_stack=True) with torch.autograd.profiler.emit_nvtx(): for iter in range(iters): #forward #backward $ dlprof --mode=pytorch python main.py $ dlprofviewer –b 0.0.0.0 –p 8000 dlprof_dldb.sqlite References:https://docs.nvidia.com/deeplearning/frameworks/dlprof-user-guide/index.html#quickstart_topic
  • 17. 17 PyTorch スクリプトのプロファイル手順 DLProf を使うには? 1. プロファイル対象の PyTorch コードに以下を追加 2. DLProf の実行 3. DLProfViewer による結果の可視化 import nvidia_dlprof_pytorch_nvtx as nvtx nvtx.init(enable_function_stack=True) with torch.autograd.profiler.emit_nvtx(): for iter in range(iters): #forward #backward $ dlprof --mode=pytorch python main.py $ dlprofviewer –b 0.0.0.0 –p 8000 dlprof_dldb.sqlite DLProfの解析は時間がかかる為、イテレーション数を少なくするのが良い (10~20 mini-batchくらい) --delayオプションを付けてwarmup部をスキップしてプロファイルする事も可能 References:https://docs.nvidia.com/deeplearning/frameworks/dlprof-user-guide/index.html#quickstart_topic
  • 18. 18 PyTorch スクリプトのプロファイル手順 DLProf を使うには? 1. プロファイル対象の PyTorch コードに以下を追加 2. DLProf の実行 3. DLProfViewer による結果の可視化 import nvidia_dlprof_pytorch_nvtx as nvtx nvtx.init(enable_function_stack=True) with torch.autograd.profiler.emit_nvtx(): for iter in range(iters): #forward #backward $ dlprof --mode=pytorch python main.py $ dlprofviewer –b 0.0.0.0 –p 8000 dlprof_dldb.sqlite 3行追加するだけ References:https://docs.nvidia.com/deeplearning/frameworks/dlprof-user-guide/index.html#quickstart_topic
  • 19. 19 PyTorch スクリプトのプロファイル手順 DLProf を使うには? 1. プロファイル対象の PyTorch コードに以下を追加 2. DLProf の実行 3. DLProfViewer による結果の可視化 import nvidia_dlprof_pytorch_nvtx as nvtx nvtx.init(enable_function_stack=True) with torch.autograd.profiler.emit_nvtx(): for iter in range(iters): #forward #backward $ dlprof --mode=pytorch python main.py $ dlprofviewer –b 0.0.0.0 –p 8000 dlprof_dldb.sqlite 特にファイル名を指定せずに実行した場合、「dlprof_dldb.sqlite」と「nsys_profile.sqlite」が 出力される Dlprofviewerには「dlprof_dldb.sqlite」を指定する必要がある References:https://docs.nvidia.com/deeplearning/frameworks/dlprof-user-guide/index.html#quickstart_topic
  • 20. 20 PyTorch スクリプトのプロファイル手順 DLProf を使うには? 1. プロファイル対象の PyTorch コードに以下を追加 2. DLProf の実行 3. DLProfViewer による結果の可視化 import nvidia_dlprof_pytorch_nvtx as nvtx nvtx.init(enable_function_stack=True) with torch.autograd.profiler.emit_nvtx(): for iter in range(iters): #forward #backward $ dlprof --mode=pytorch python main.py $ dlprofviewer –b 0.0.0.0 –p 8000 dlprof_dldb.sqlite 特にファイル名を指定せずに実行した場合、「dlprof_dldb.sqlite」と「nsys_profile.sqlite」が 出力される Dlprofviewerには「dlprof_dldb.sqlite」を指定 References:https://docs.nvidia.com/deeplearning/frameworks/dlprof-user-guide/index.html#quickstart_topic
  • 21. 21 例: DLProf + DLProfViewer によるプロファイル結果 GPU 最適化前 (AMP未使用/バッチサイズ小) 全実行時間の殆どがCPU処理 なのが一目で分かる
  • 22. 22 例: DLProf + DLProfViewer によるプロファイル結果 GPU 最適化前 (AMP未使用/バッチサイズ小) 全実行時間の殆どがCPU処理 なのが一目で分かる “Problem detected:”と”Recommended Change:” が表示され、問題点が分かる
  • 24. 24 NSIGHT ツールワークフロー 新しくなった CUDA プロファイルツール群 Nsight Systems 包括的なシステムレベルの性能確認 Nsight Compute CUDA カーネル詳細性能確認用 Nsight Graphics フレーム/レンダー詳細性能確認 メトリック/カウンタを用いた CUDAカーネル単位の詳細 性能確認 グラフィックフレーム単位の 詳細プロファイル スタート 全体的なパフォーマンスを 再確認 全体的なパフォーマンス を再確認 https://developer.nvidia.com/nsight-systems
  • 25. 25 Nsight Systems 主な機能: • システム全体のアルゴリズム最適化 • マルチプロセスのアプリケーション解析のサポート • アプリケーション内のボトルネックを探しに有効 • 非常に高速なGUIタイムライン上で何百万ものイベントを視覚化 • コマンドライン、IDE(統合型開発環境)の両方に対応 OS: Linux (x86, Power, Arm SBSA, Tegra), Windows, MacOSX (host) GPUs: Pascal+ 新しくなった CUDA プロファイルツール群 $ nsys profile –t cuda,osrt,nvtx,cudnn,cublas –o inference_result.qdstrm –w true python inference.py https://developer.nvidia.com/nsight-systems
  • 26. 26 CPU utilization Processes & threads OS runtime APIs CUDA & cuBLAS APIs GPU CUDA Kernels & memory transfers CPU IP & backtrace sample data NVTX annotations NVTX projected on GPU CUDA streams
  • 27. 27 開発環境に NSIGHT SYSTEMS がインストールされていない場合 Setting Up and Using Nsight Systems Inside Containers CUDA 11.4: install CUDA 11.3: install CUDA 11.2: install Mapping an Nsight Systems Host Installation into a Container NSIGHT SYTEMS $ apt-get update –y $ apt-get install -y cuda-nsight-systems-11-3 nsight-systems-2021.1.3 $ apt-get update –y $ apt-get install -y cuda-nsight-systems-11-2 nsight-systems-2020.4.3 $ docker run --rm -it --network=host --gpus=all -v /opt/nvidia/nsight-systems/2021.1.3:/opt/nvidia/nsight-systems/2021.1.3 nvcr.io/nvidia/pytorch:21.08-py3 bash $ apt-get update –y $ apt-get install -y cuda-nsight-systems-11-4 nsight-systems-2021.2.4
  • 28. 28 NSIGHT SYSTEMS を使うには? Example cuda – GPU kernel osrt – OS runtime nvtx – NVIDIA Tools Extension cublas – CUDA BLAS library https://docs.nvidia.com/nsight-systems/2020.3/profiling/index.html#cli-options NSIGHT SYTEMS $ nsys profile -t nvtx,cuda,osrt,cublas --stats=true -f true -o pusch_result python main.py APIs to be traced Outputs profiling information similar to nvprof Overwrite the output Output filename
  • 29. 29 NSIGHT SYSTEMS を使うには? Example cuda – GPU kernel osrt – OS runtime nvtx – NVIDIA Tools Extension cublas – CUDA BLAS library https://docs.nvidia.com/nsight-systems/2020.3/profiling/index.html#cli-options NSIGHT SYTEMS $ nsys profile -t nvtx,cuda,osrt,cublas --stats=true -f true -o pusch_result python main.py APIs to be traced Outputs profiling information similar to nvprof Overwrite the output Output filename Other Userful Options • --delay (-y) : Collection start delay in seconds • --duration(-d): Collection duration in seconds. • --capture-range(-c): none/cudaProfilerApi/nvtx etc..
  • 30. 30 例: Nsight Systems + NVTX Nsight Systems プロファイル結果(NVTX あり) 前処理 11.07sec 推論処理(10iteration) 28.924sec 1iteration アノテーションする事で タイムライン上で処理を把握しやすくなる!
  • 31. 31 Appendix. 技術ブログ・関連セッション Deep Learning Examples • https://github.com/NVIDIA/DeepLearningExamples/ How to Run NGC Deep Learning Containers with Singularity • https://developer.nvidia.com/blog/how-to-run-ngc-deep-learning-containers-with-singularity/ Profiling and Optimizing Deep Neural Networks with DLProf and PyProf (TensorFlow) • https://developer.nvidia.com/blog/profiling-and-optimizing-deep-neural-networks-with-dlprof-and-pyprof/ Deep Learning Performance Optimization with Profiling Tools • https://www.nvidia.com/en-us/on-demand/session/gtcspring21-s31228/ Profiling and Optimizing Deep Neural Networks with DLProf and PyProf • https://www.nvidia.com/en-us/on-demand/session/gtcspring21-s31341/ PyTorch Performance Tuning Guide • https://www.nvidia.com/en-us/on-demand/session/gtcspring21-s31831/ NVIDIA プロファイラを用いた Pytorch 学習最適化手法のご紹介