43
TensorLayer 2.0 Hao Dong Peking University 1

Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

TensorLayer 2.0Hao Dong

Peking University

1

Page 2: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

2

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

How to Use Better

Page 3: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

3

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

How to Use Better

Page 4: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

4

History of Deep Learning Tools

• Automatic Differentiation

Key reasons for TensorFlow● Largest user base● Widest production adoption● Well-maintained documents● Battlefield-proof quality● TPU !

Page 5: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

5

History of Deep Learning Tools

Deep learning high-level elements: neural networks, layers and tensors

http://www.asimovinstitute.org/neural-network-zoo/

Abstraction gap

Low-level interface: dataflow graph, placeholder, session, queue runner, devices …

https://www.tensorflow.org/extend/architecture

Bridged by wrappers: TensorLayer, Keras and TFLearn

• Beyond Automatic Differentiation

Page 6: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

6

History of Deep Learning Tools

Theano TensorFlow

Torch Pytorch

Caffe Caffe2

Time

Keras Tflearn TensorLayer

CNTK2016

2010 2015

2017

2014

2016 Sep

2017

2014

2015 2016

2018

Page 7: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

7

History of Deep Learning Tools

Theano TensorFlow

Torch Pytorch

Caffe Caffe2

Time

CNTK2016

2010 2015

2017

2014 2017

2002

2018

transfer

transfer

transfermerge

TensorFlow 2.02019

Page 8: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

8

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

Page 9: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

9

History of TensorLayer

2016 2019

Time

2015 2019

Page 10: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

10

History of TensorLayer

10

• TensorLayer 2.0

TensorLayer: A Versatile Library for Efficient Deep Learning Development. H. Dong, A. Supratak et al. ACM MM 2017.

Page 11: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

11

History of TensorLayer

GithubDocumentation(English)

Page 12: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

12

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

Page 13: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

13

Future of TensorLayer

GPU TPU Huawei 晟腾 ShengTeng …

• Platform-agnostic• Research oriented

TensorFlow MindSpore …

Page 14: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

14

Future of TensorLayer

Contributors

Page 15: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

15

Future of TensorLayer

Page 16: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

16

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

Page 17: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

17

Static vs. Dynamic ModelsStaticModel

LasagneFashio

n

Page 18: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

18

Static vs. Dynamic ModelsDynamicModel

ChainerFashion

Page 19: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

19

Static vs. Dynamic Models

StaticModel DynamicModel

ChainerFashionLasagn

eFashion

Page 20: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

20

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

Page 21: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

21

Switching Train/Test Models

Page 22: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

22

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

Page 23: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

23

Reuse Weights

ReuseWeightsinStaticModel

Page 24: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

24

Reuse Weights

ReuseWeightsinDynamicModel

Page 25: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

25

Reuse Weights

ReuseWeightsinStaticModel ReuseWeightsinDynamicModel

Page 26: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

26

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

Page 27: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

27

Model Information

PrintModelArchitecture

[{'args': {'dtype': tf.float32,'layer_type': 'normal','name': '_inputlayer_1','shape': [None, 784]},

'class': '_InputLayer','prev_layer': None},

{'args': {'keep': 0.8, 'layer_type': 'normal', 'name': 'dropout_1'},'class': 'Dropout','prev_layer': ['_inputlayer_1_node_0']},

{'args': {'act’: ‘relu','layer_type': 'normal','n_units': 800,'name': 'dense_1'},

'class': 'Dense','prev_layer': ['dropout_1_node_0']},

{'args': {'keep': 0.8, 'layer_type': 'normal', 'name': 'dropout_2'},'class': 'Dropout','prev_layer': ['dense_1_node_0']},

{'args': {'act': ‘relu','layer_type': 'normal','n_units': 800,'name': 'dense_2'},

'class': 'Dense','prev_layer': ['dropout_2_node_0']},

{'args': {'keep': 0.8, 'layer_type': 'normal', 'name': 'dropout_3'},'class': 'Dropout','prev_layer': ['dense_2_node_0']},

{'args': {'act’: ‘relu','layer_type': 'normal','n_units': 10,'name': 'dense_3'},

'class': 'Dense','prev_layer': ['dropout_3_node_0']}]

Page 28: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

28

Model Information

PrintModelInformation

GetSpecificWeights

SaveWeightsOnly

SaveWeights+ Architecture

.trainable_weights

.nontrainable_weights

Page 29: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

29

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

Page 30: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

30

Customize Layer without Weights

Page 31: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

31

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

Page 32: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

32

Customize Layer with Weights

Page 33: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

33

Customize Layer with Weights

Page 34: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

34

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

Page 35: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

35

Dataflow

𝑡𝑖𝑚𝑒ModelTraining

(GPU)DataProcessing

(CPU)GPU Utilization: 70%

ModelTraining(GPU)

DataProcessing(CPU)

GPU Utilization: 50%

• Training without Dataflow

𝑡𝑖𝑚𝑒

Prepareabatchoftrainingdata

Oneiteration GPUIdle

Page 36: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

36

Dataflow

𝑡𝑖𝑚𝑒ModelTraining

(GPU)DataProcessing

(CPU)GPU Utilization: 100%

ModelTraining(GPU)

DataProcessing(CPU)

GPU Utilization: 100%

• Training with Dataflow

𝑡𝑖𝑚𝑒

ModelTraining(GPU)

DataProcessing(CPU)

GPU Utilization: 75%

𝑡𝑖𝑚𝑒

Page 37: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

37

• History of Deep Learning Tools• History of TensorLayer• Future of TensorLayer• Static vs. Dynamic Models• Switching Train/Test Modes• Reuse Weights• Model Information• Customize Layer without Weights• Customize Layer with Weights• Dataflow• Distributed Training

Background

How to Use

Page 38: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

38

Distributed Training

Model part 3Worker 3

Model part 2Worker 2

Model part 1Worker 1

Model Parallelism

Entire ModelWorker 3

Entire ModelWorker 2 Entire ModelWorker 1

Entire ModelWorker 4

Data Parallelism

Page 39: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

39

Distributed Training

Worker 1

Parameter Server

Worker 2 Worker 3

Averages gradients

Worker 1

Parameter Server 1

Worker 2 Worker 3

Averages different parts of the gradients

Parameter Server 2

• Distributed Training: Data Parallelism - Parameter Server

Page 40: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

Distributed Training

40

Worker 1

Worker 2 Worker 3

Worker 1

Worker 2 Worker 3

Worker 1

Worker 2 Worker 3

Step 1 Step 2

Step 3

• Distributed Training: Data Parallelism - Horovod - All ringreduce

Page 41: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

41

Distributed Training

• Distributed Training: Data Parallelism - Horovod - All ringreduce

Model Gradients Averaged GradientsWorker 1

Model Gradients Averaged GradientsWorker 2

Ring-allreduce

Model Gradients Averaged GradientsWorker 3

Page 42: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

42

Please install TensorFlow and TensorLayer and make sure this code is runnable

https://github.com/tensorlayer/tensorlayer/blob/master/examples/basic_tutorials/tutorial_mnist_mlp_static.py

Page 43: Lecture 12 TensorLayer 2.0 50mins - Deep Generative Models · 2021. 4. 29. · TensorLayer2.0. Hao Dong Peking University. 1. 2. •History of Deep Learning Tools •History of TensorLayer

Thanks

43