Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Mixed Precisionのすゝめ
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
tereka114
March 15, 2022
Programming
480
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Mixed Precisionのすゝめ
Mixed Precisionのすゝめ
第56回 コンピュータビジョン勉強会@関東での発表資料
tereka114
March 15, 2022
More Decks by tereka114
See All by tereka114
トラブルがあったコンペに学ぶデータ分析
tereka114
2
2.1k
Harnessing Large Language Models for Training-free Video Anomaly Detection
tereka114
1
1.9k
KDD2023学会参加報告
tereka114
2
690
Prompting Large Language Models with Answer Heuristics for Knowledge-based Visual Question Answering
tereka114
0
480
Mobile-Former: Bridging MobileNet and Transformer
tereka114
0
1.2k
DER: Dynamically Expandable Representation for Class Incremental Learning
tereka114
0
280
Jupyter Notebookを納品した話
tereka114
0
590
Multi Scale Recognition with DAG-CNNs
tereka114
0
200
How to use scikit-image for data augmentation
tereka114
0
340
Other Decks in Programming
See All in Programming
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
330
ActionController meets Protocol Buffers
sorah
1
790
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
930
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
220
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
1
280
Next.js: The final boss of Web Performance
guaca
0
390
Performance Optimization With LLMs
xleitix
0
250
小さなアプリを作って公開するまで
onozaty
0
140
Railsバージョンを4倍にした話
optim
0
960
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
310
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.7k
Будущее локальных LLM – Алексей Голобурдин, PythoNN
sobolevn
0
110
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.8k
We Are The Robots
honzajavorek
0
440
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Tell your own story through comics
letsgokoyo
1
1.1k
KATA
mclloyd
PRO
35
16k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
310
Navigating Weather and Climate Data
rabernat
0
590
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
460
Typedesign – Prime Four
hannesfritz
42
3.2k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Practical Orchestrator
shlominoach
192
12k
Transcript
1 Copyright © Acroquest Technology Co., Ltd. All rights reserved.
Mixed Precisionのすゝめ 2020/1/19 Acroquest Technology株式会社 ⼭本 ⼤輝(@tereka114)
⼭本 ⼤輝 (@tereka114) 1. Acroquest Technology株式会社 ① 画像処理・⾃然⾔語処理の研究開発 2. のんびりしているエンジニアの⽇記
http://nonbiri-tereka.hatenablog.com/ 3. Kaggle Master ① Home Credit Default Risk 2nd ② IEEE Signal Processing 10th 4. Interface 2018年12⽉号 AIひょっこり猫カメ ラ Interface 2020年2⽉号 組み込みコンピュータ 技術512
Acroquestのミッション・ビジョン Copyright © Acroquest Technology Co., Ltd. All rights reserved.
3 テクノロジストチームとして ビジネスの⾰新的価値創出に挑戦する ビジョン Acroquestの創り出す技術で 地球を感動で進化させる ミッション
「働きがいのある会社(GPTW)」 ランキング(従業員25〜99⼈部⾨) 1位 を 3回 受賞 1位 1位 1位
⽬次 Copyright © Acroquest Technology Co., Ltd. All rights reserved.
5 1. 本発表の⽬的 2. Mixed Precisionの紹介 3. Mixed Precision(AMP)を使ってみよう 4. まとめ 5. 参考資料
本発表の⽬的 Copyright © Acroquest Technology Co., Ltd. All rights reserved.
6
本発表の⽬的 Copyright © Acroquest Technology Co., Ltd. All rights reserved.
7 1. Mixed Precisionの仕組みの概要を知る。 2. 簡単に使えるAutomatic Mixed Precisionのライブラリを知って、 利⽤のお⼿軽さだと感じてもらう。 3. ⼀つの選択肢として認識・使えるようになってほしい
MIXED PRECISIONの紹介 Copyright © Acroquest Technology Co., Ltd. All rights
reserved. 8
Mixed Precisionとはなにか︖ Copyright © Acroquest Technology Co., Ltd. All rights
reserved. 9 1. Mixed Precisionはfloat32とfloat16を組み合わせて計算する技術 2. 2017年に論⽂「Mixed Precision Training」がNVIDIA + Baido から発表されている。 3. 精度を維持しつつ、メモリ消費量の軽減や、計算速度の⾼速化を実 現した。 • 単純にFloat16による計算を⾏えば精度が下がることが知られている。
Mixed Precisionを何故、使うのか Copyright © Acroquest Technology Co., Ltd. All rights
reserved. 10 1. メモリ消費量の削減ができる。 • 巨⼤なネットワーク(Semantic Segmentationなど)の利⽤が可能になる。 • バッチサイズを増加させることができるため、学習が安定する。 2. 計算速度の⾼速化 • ⼀部をfloat16で計算するので、Tensor Coreの有効活⽤ができる。 • GPUへの転送量が減るので、計算速度の⾼速化が実現できる。
Mixed Precisionの仕組み概要 Copyright © Acroquest Technology Co., Ltd. All rights
reserved. 11 1. float16へ重みをコピー 2. float16でForward処理 3. float16でBackward処理 ※オリジナルの重みは常にfloat32で保持する。
Mixed Precisionの⼯夫 Copyright © Acroquest Technology Co., Ltd. All rights
reserved. 12 1. 演算の⼯夫 • 演算⼦によって、float32, float16で計算するものを選定している。 – ⾏列計算はflaot16 – Pointwise Operation(誤差関数含む)はfloat32 2. Master Weightはfloat32を利⽤ • Float16だと、学習の終盤で勾配が⼩さすぎて重みの更新ができなくなる。 3. 誤差をスケール(X倍)させる。 • 誤差が⼩さすぎると勾配がfloat16で表現ができない。
Mixed Precision実⾏時の精度 Copyright © Acroquest Technology Co., Ltd. All rights
reserved. 13 ・精度はMixed Precisionの 有無で差が出ない。 ・Master Weightのfloat32は 効果がある。
Mixed Precision実⾏時の性能 Copyright © Acroquest Technology Co., Ltd. All rights
reserved. 14 https://devblogs.nvidia.com/nvidia-automatic-mixed-precision-tensorflow/
複数タスクでのMixed Precisionの精度と性能 Copyright © Acroquest Technology Co., Ltd. All rights
reserved. 15 Model Script1 Framework Data Set FP32 Accuracy Mixed Precision Accuracy FP32 Throughput Mixed Precision Throughput Speed-up BERT Q&A2 TensorFlow SQuAD 90.83Top 1% 90.99Top 1% 66.65 sentences/sec 129.16 sentences/sec 1.94 SSD w/RN501 TensorFlow COCO 2017 0.268mAP 0.269mAP 569 images/sec 752 images/sec 1.32 GNMT3 PyTorch WMT16 English to German 24.16BLEU 24.22BLEU 314,831 tokens/sec 738,521 tokens/sec 2.35 Neural Collaborative Filter1 PyTorch MovieLens 20M 0.959HR 0.960HR 55,004,590 samples/sec 99,332,230 samples/sec 1.81 U-Net Industrial1 TensorFlow DAGM 2007 0.965-0.988 0.960-0.988 445 images/sec 491 images/sec 1.10 ResNet-50 v1.51 MXNet ImageNet 76.67Top 1% 76.49Top 1% 2,957 images/sec 10,263 images/sec 3.47 Tacotron 2 / WaveGlow 1.01 PyTorch LJ Speech Dataset 0.3629/- 6.1087 0.3645/- 6.0258 10,843 tok/s257,687 smp/s 12,742 tok/s500,375 smp/s 1.18/1.94 https://docs.nvidia.com/deeplearning/sdk/mixed-precision-training/index.html
MIXED PRECISION(AMP)を 使ってみよう Copyright © Acroquest Technology Co., Ltd. All
rights reserved. 16
Automatic Mixed Precision Copyright © Acroquest Technology Co., Ltd. All
rights reserved. 17 1. NVIDIA社のライブラリで、モデルを⾃動的にMixed Precisionに切り替える。 2. TensorFlow, PyTorch, MXNetはサポートされている。 ① PyTorchはapexのインストールが必要 – https://github.com/NVIDIA/apex ② その他のライブラリに関しても、次のサイトに記述あり – https://developer.nvidia.com/automatic-mixed-precision 3. 導⼊が簡単で、コードの修正もごくわずか。 4. ただし、TensorCoreがあるGPUでしか利⽤ができない
PyTorchにおける実装例 Copyright © Acroquest Technology Co., Ltd. All rights reserved.
18 for images, labels in trainloader: images = images.cuda() labels = labels.cuda() loss = criterion(outputs, labels) loss.backward() optimizer.step() model, optimizer = amp.initialize(model, optimizer, opt_level="O1", verbosity=0) for images, labels in trainloader: images = images.cuda() labels = labels.cuda() loss = criterion(outputs, labels) with amp.scale_loss(loss, optimizer) as scaled_loss: scaled_loss.backward() optimizer.step() ampの初期化コード、 学習前に実⾏ 学習時に追加する実 装
実験 Copyright © Acroquest Technology Co., Ltd. All rights reserved.
19 1. CIFAR10で実験 項⽬ 値 理由 モデル ResNet50 画像認識で頻繁に利⽤されるモデルを利⽤ Batch size 32 適度に設定 Epoch 30 適度に設定 Data Augmentation なし 今回は⽐較した精度を知りたかったので、 Data Augmentationを実施していない。 Optimizer (最適化) Adam (lr=0.001) デフォルトで実験
実験結果 Copyright © Acroquest Technology Co., Ltd. All rights reserved.
20 項⽬ Mixed Precisionなし Mixed Precisionあり 効果 時間 4899s 3864s x1.26 メモリ 2467MB 2177MB x1.13 精度 0.854 0.846
経験ベースの感想 Copyright © Acroquest Technology Co., Ltd. All rights reserved.
21 1. バッチサイズや画像のサイズを担保する必要のあるタスクでは良さ そう。 • ⾼解像度Semantic Segmentationや⼀定のバッチサイズを確保する必要の あるBertでは、⾮常に有効なトリック 2. すべてfloat32計算と⽐較すると少々精度が下がる。コンペティシ ョンで利⽤する際には⽐較・検証するのが望ましい。
まとめ Copyright © Acroquest Technology Co., Ltd. All rights reserved.
22
まとめ Copyright © Acroquest Technology Co., Ltd. All rights reserved.
23 1. Mixed Precisionはfloat32/16を利⽤した計算⽅法 • 精度は維持しつつ、メモリ消費量や計算速度の向上に貢献 • ただし、TensorCoreの利⽤が必須 2. NVIDIA社のライブラリ、Automatic Mixed Precisionで簡単に実 装可能 • ごくわずかな実装で使えるので、使いやすい 3. ぜひ、使ってみてください。
参考資料 Copyright © Acroquest Technology Co., Ltd. All rights reserved.
24
5. 参考資料 Copyright © Acroquest Technology Co., Ltd. All rights
reserved. 25 1. INTRODUCTION TO MIXED PRECISION TRAINING • https://nvlabs.github.io/iccv2019-mixed-precision- tutorial/files/dusan_stosic_intro_to_mixed_precision_training.pdf 2. Mixed Precision Training • https://arxiv.org/abs/1710.03740