SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
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!

Contenu connexe

Tendances

全力解説!Transformer
全力解説!Transformer全力解説!Transformer
全力解説!TransformerArithmer Inc.
 
AHC-Lab M1勉強会 論文の読み方・書き方
AHC-Lab M1勉強会 論文の読み方・書き方AHC-Lab M1勉強会 論文の読み方・書き方
AHC-Lab M1勉強会 論文の読み方・書き方Shinagawa Seitaro
 
3D CNNによる人物行動認識の動向
3D CNNによる人物行動認識の動向3D CNNによる人物行動認識の動向
3D CNNによる人物行動認識の動向Kensho Hara
 
【メタサーベイ】Video Transformer
 【メタサーベイ】Video Transformer 【メタサーベイ】Video Transformer
【メタサーベイ】Video Transformercvpaper. challenge
 
[DL輪読会]Pay Attention to MLPs (gMLP)
[DL輪読会]Pay Attention to MLPs	(gMLP)[DL輪読会]Pay Attention to MLPs	(gMLP)
[DL輪読会]Pay Attention to MLPs (gMLP)Deep Learning JP
 
学習時に使ってはいないデータの混入「リーケージを避ける」
学習時に使ってはいないデータの混入「リーケージを避ける」学習時に使ってはいないデータの混入「リーケージを避ける」
学習時に使ってはいないデータの混入「リーケージを避ける」西岡 賢一郎
 
Deep Learning による視覚×言語融合の最前線
Deep Learning による視覚×言語融合の最前線Deep Learning による視覚×言語融合の最前線
Deep Learning による視覚×言語融合の最前線Yoshitaka Ushiku
 
【DL輪読会】時系列予測 Transfomers の精度向上手法
【DL輪読会】時系列予測 Transfomers の精度向上手法【DL輪読会】時系列予測 Transfomers の精度向上手法
【DL輪読会】時系列予測 Transfomers の精度向上手法Deep Learning JP
 
【DL輪読会】"Masked Siamese Networks for Label-Efficient Learning"
【DL輪読会】"Masked Siamese Networks for Label-Efficient Learning"【DL輪読会】"Masked Siamese Networks for Label-Efficient Learning"
【DL輪読会】"Masked Siamese Networks for Label-Efficient Learning"Deep Learning JP
 
SSII2022 [SS2] 少ないデータやラベルを効率的に活用する機械学習技術 〜 足りない情報をどのように補うか?〜
SSII2022 [SS2] 少ないデータやラベルを効率的に活用する機械学習技術 〜 足りない情報をどのように補うか?〜SSII2022 [SS2] 少ないデータやラベルを効率的に活用する機械学習技術 〜 足りない情報をどのように補うか?〜
SSII2022 [SS2] 少ないデータやラベルを効率的に活用する機械学習技術 〜 足りない情報をどのように補うか?〜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
 
[DL輪読会]MetaFormer is Actually What You Need for Vision
[DL輪読会]MetaFormer is Actually What You Need for Vision[DL輪読会]MetaFormer is Actually What You Need for Vision
[DL輪読会]MetaFormer is Actually What You Need for VisionDeep Learning JP
 
【DL輪読会】Novel View Synthesis with Diffusion Models
【DL輪読会】Novel View Synthesis with Diffusion Models【DL輪読会】Novel View Synthesis with Diffusion Models
【DL輪読会】Novel View Synthesis with Diffusion ModelsDeep Learning JP
 
分散学習のあれこれ~データパラレルからモデルパラレルまで~
分散学習のあれこれ~データパラレルからモデルパラレルまで~分散学習のあれこれ~データパラレルからモデルパラレルまで~
分散学習のあれこれ~データパラレルからモデルパラレルまで~Hideki Tsunashima
 
動作認識の最前線:手法,タスク,データセット
動作認識の最前線:手法,タスク,データセット動作認識の最前線:手法,タスク,データセット
動作認識の最前線:手法,タスク,データセットToru Tamaki
 
semantic segmentation サーベイ
semantic segmentation サーベイsemantic segmentation サーベイ
semantic segmentation サーベイyohei okawa
 
[DL輪読会]"CyCADA: Cycle-Consistent Adversarial Domain Adaptation"&"Learning Se...
 [DL輪読会]"CyCADA: Cycle-Consistent Adversarial Domain Adaptation"&"Learning Se... [DL輪読会]"CyCADA: Cycle-Consistent Adversarial Domain Adaptation"&"Learning Se...
[DL輪読会]"CyCADA: Cycle-Consistent Adversarial Domain Adaptation"&"Learning Se...Deep Learning JP
 
近年のHierarchical Vision Transformer
近年のHierarchical Vision Transformer近年のHierarchical Vision Transformer
近年のHierarchical Vision TransformerYusuke Uchida
 
動画認識サーベイv1(メタサーベイ )
動画認識サーベイv1(メタサーベイ )動画認識サーベイv1(メタサーベイ )
動画認識サーベイv1(メタサーベイ )cvpaper. challenge
 

Tendances (20)

全力解説!Transformer
全力解説!Transformer全力解説!Transformer
全力解説!Transformer
 
AHC-Lab M1勉強会 論文の読み方・書き方
AHC-Lab M1勉強会 論文の読み方・書き方AHC-Lab M1勉強会 論文の読み方・書き方
AHC-Lab M1勉強会 論文の読み方・書き方
 
3D CNNによる人物行動認識の動向
3D CNNによる人物行動認識の動向3D CNNによる人物行動認識の動向
3D CNNによる人物行動認識の動向
 
【メタサーベイ】Video Transformer
 【メタサーベイ】Video Transformer 【メタサーベイ】Video Transformer
【メタサーベイ】Video Transformer
 
[DL輪読会]Pay Attention to MLPs (gMLP)
[DL輪読会]Pay Attention to MLPs	(gMLP)[DL輪読会]Pay Attention to MLPs	(gMLP)
[DL輪読会]Pay Attention to MLPs (gMLP)
 
学習時に使ってはいないデータの混入「リーケージを避ける」
学習時に使ってはいないデータの混入「リーケージを避ける」学習時に使ってはいないデータの混入「リーケージを避ける」
学習時に使ってはいないデータの混入「リーケージを避ける」
 
Deep Learning による視覚×言語融合の最前線
Deep Learning による視覚×言語融合の最前線Deep Learning による視覚×言語融合の最前線
Deep Learning による視覚×言語融合の最前線
 
【DL輪読会】時系列予測 Transfomers の精度向上手法
【DL輪読会】時系列予測 Transfomers の精度向上手法【DL輪読会】時系列予測 Transfomers の精度向上手法
【DL輪読会】時系列予測 Transfomers の精度向上手法
 
【DL輪読会】"Masked Siamese Networks for Label-Efficient Learning"
【DL輪読会】"Masked Siamese Networks for Label-Efficient Learning"【DL輪読会】"Masked Siamese Networks for Label-Efficient Learning"
【DL輪読会】"Masked Siamese Networks for Label-Efficient Learning"
 
SSII2022 [SS2] 少ないデータやラベルを効率的に活用する機械学習技術 〜 足りない情報をどのように補うか?〜
SSII2022 [SS2] 少ないデータやラベルを効率的に活用する機械学習技術 〜 足りない情報をどのように補うか?〜SSII2022 [SS2] 少ないデータやラベルを効率的に活用する機械学習技術 〜 足りない情報をどのように補うか?〜
SSII2022 [SS2] 少ないデータやラベルを効率的に活用する機械学習技術 〜 足りない情報をどのように補うか?〜
 
【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)
 
[DL輪読会]MetaFormer is Actually What You Need for Vision
[DL輪読会]MetaFormer is Actually What You Need for Vision[DL輪読会]MetaFormer is Actually What You Need for Vision
[DL輪読会]MetaFormer is Actually What You Need for Vision
 
【DL輪読会】Novel View Synthesis with Diffusion Models
【DL輪読会】Novel View Synthesis with Diffusion Models【DL輪読会】Novel View Synthesis with Diffusion Models
【DL輪読会】Novel View Synthesis with Diffusion Models
 
分散学習のあれこれ~データパラレルからモデルパラレルまで~
分散学習のあれこれ~データパラレルからモデルパラレルまで~分散学習のあれこれ~データパラレルからモデルパラレルまで~
分散学習のあれこれ~データパラレルからモデルパラレルまで~
 
動作認識の最前線:手法,タスク,データセット
動作認識の最前線:手法,タスク,データセット動作認識の最前線:手法,タスク,データセット
動作認識の最前線:手法,タスク,データセット
 
semantic segmentation サーベイ
semantic segmentation サーベイsemantic segmentation サーベイ
semantic segmentation サーベイ
 
[DL輪読会]"CyCADA: Cycle-Consistent Adversarial Domain Adaptation"&"Learning Se...
 [DL輪読会]"CyCADA: Cycle-Consistent Adversarial Domain Adaptation"&"Learning Se... [DL輪読会]"CyCADA: Cycle-Consistent Adversarial Domain Adaptation"&"Learning Se...
[DL輪読会]"CyCADA: Cycle-Consistent Adversarial Domain Adaptation"&"Learning Se...
 
近年のHierarchical Vision Transformer
近年のHierarchical Vision Transformer近年のHierarchical Vision Transformer
近年のHierarchical Vision Transformer
 
動画認識サーベイv1(メタサーベイ )
動画認識サーベイv1(メタサーベイ )動画認識サーベイv1(メタサーベイ )
動画認識サーベイv1(メタサーベイ )
 
Semantic segmentation
Semantic segmentationSemantic segmentation
Semantic segmentation
 

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

ディープラーニングイメージで構築する快適・高速な機械学習環境
ディープラーニングイメージで構築する快適・高速な機械学習環境ディープラーニングイメージで構築する快適・高速な機械学習環境
ディープラーニングイメージで構築する快適・高速な機械学習環境Yaboo Oyabu
 
20170421 tensor flowusergroup
20170421 tensor flowusergroup20170421 tensor flowusergroup
20170421 tensor flowusergroupManaMurakami1
 
[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、ヤフー〜 #2Preferred 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_20210318Yuhki 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
 
20170726 py data.tokyo
20170726 py data.tokyo20170726 py data.tokyo
20170726 py data.tokyoManaMurakami1
 
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 2021Preferred Networks
 
はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入はてなにおける継続的デプロイメントの現状と Docker の導入
はてなにおける継続的デプロイメントの現状と Docker の導入Yu Nobuoka
 
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_cdpYukitaka 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
 

Similaire à 「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
 
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
 
はてなにおける継続的デプロイメントの現状と 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)
 

Plus de ManaMurakami1

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

Plus de 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 学習最適化手法のご紹介