SlideShare a Scribd company logo
Distributed Tensorflow with Kubernetes
Jakob Karalus, @krallistic,
1
Training Neural Networks
•First steps are quick and easy.
•Single Node Neural Networks
•We want:
•More Data!
•Deeper Models!
•Wider Model!
•Higher Accuracy!
•(Single Node) Compute cant keep up
•Longer Trainingstime -> Longer Cycles -> Lower Productivity
2
Distributed & Parallel
•We need to distribute and train in parallel to be efficient
•Data Parallelism
•Model Parallelsim
•Grid Search
•Predict
•-> Build in TF
•How can we deploy that to a cluster
•Schedule TF onto Nodes
•Service Discovery
•GPUs
•-> Kubernetes
3
Requirements & Content
•Basic Knowledge of Neural Networks
•Knowledge of Tensorflow
•Basic Docker/Kubernetes knowledge
•(Docker) Containers: Mini VM (Wrong!)
•Kubernetes: Schedulurer/Orchestration Tool for Containers
•Only focus on the task of parallel and/or distributed training
•We will not look at architectures like CNN/LTSM etc
4
Tensorflow on a single node
5
•Build your Graph
•Define which Parts on each device
•TF places data
•DMA for coordination/communication
• Define loss, accuracy etc
•Create Session for training
•Feed Data into Session
•Retrieve results
cpu:0 gpu:0
/job:worker/task:0/
Client Code
Parameter Server & Worker Replicas
•Client: Code that builds the Graph, communicates with cluster, builds the session
•Cluster: Set of nodes which have jobs (roles)
•Jobs
•Worker Replicas: compute intensive part
•Parameter Servers(ps): Holds model state and reacts to updates
•Each job can hold 0..* task
•Task
•The actual server process
•Worker Task 0 is by default the chief worker
•Responsible for checkpointing, initialising and health checking
•CPU 0 represents all CPUs on the Node
6
Client Code
Session
Graph
Graph
cpu:0 gpu:0
/job:worker/task:0/
cpu:0
/job:ps/task:0/
In Graph Replication
•Split up input into equal chunks,
•Loops over workers and assign a chunk
•collect results and optimise
•Not the recommended way
•Graph get big, lot of communication overhead
•Each device operates on all data
7
cpu:0 gpu:0
/job:worker/task:0/
cpu:0 gpu:0
/job:worker/task:0/
cpu:0
/job:ps/task:0/
Client Code
Between Replication
•Recommend way of doing replication
•Similiar to MPI
•Each device operates on a partition
•Different Client Program on each worker
•Assign itself to local resources
•Small graph independently
8
cpu:0gpu:0
/job:worker/task:0/
cpu:0 gpu:0
/job:worker/task:0/
cpu:0
/job:ps/task:0/
Client CodeClient Code
Variable Placement
•How to place the Variable onto different devices
•Manual Way
•Easy to start, full flexibility
•Gets annoying soon
•Device setter
•Automatic assign variables to ps and ops to workers
•Simple round robin by default
•Greedy Load Balancing Strategy
•Partitioned Values
•Needed for really large variables (often used in text embeddings)
•Splits variables between multiple Parameter Server
9
Training Modes
Syncronous
Replication
Every Instances reads the same
values for current parameters,
computes the gradient in parallel
and the app them together.
Asycronoues
Replication
Independent training loop in every
Instance, without coordination.
Better performance but lower
accuracy.
10
How to update the parameters between
instances?
Synchronous Training
11
Parameter Server
Add
Update
P
Model Model
Input Input
ΔP ΔP
Asyncronous Training
12
Parameter Server
Update
P
Model Model
Input Input
Update
• Each Updates Independently
• Nodes can read stale nodes from PS
• Possible: Model dont converge
ΔP ΔP
1. Define the Cluster
•Define ClusterSpec
•List Parameter Servers
•List Workers
•PS & Worker are called Jobs
•Jobs can contain one ore more Tasks
•Create Server for every Task
13
2. Assign Operation to every Task
•Same on every Node for In-Graph
•Different Devices for Between-Graph
•Can also be used to set parts to GPU and parts to CPU
14
3. Create a Training Session
•tf.train.MonitoredTrainingSession or tf.train.Supervisor for Asyncronous Training
•Takes care of initialisation
•Snapshotting
•Closing if an error occurs
•Hooks
•Summary Ops, Init Ops
•tf.train.SyncReplicaOptimizer for synchronous training:
•Also create a supervisor that takes over the role a a master between workers.
15
All Together - Server Init
16
All Together - Building Graph
17
All Together - TrainingOP
18
All Together - Session & Training
19
20
Deployment & Distribution
Packaging
•The Application (and all its) dependencies needs to be packaged into a deployable
•Wheels
•Code into deployable Artefact with defined dependencies
•Dependent on runtime
•Container
•Build Image with runtime, dependencies and code
•Additional Tooling for building and running required (Docker)
21
GPU Support
Alpha since 1.6
(experimental before)
Huge Community
One of the fastest
growing community
Auto Scaling
Build in Auto Scaling Feature
based on Ultitisation
Developer friendly API
Quick deployments
through simple and
flexible API.
Open Source
Open Sourced by Google, now
member of Cloud Computing
Foundation.
Bin Packing
Efficient resource utilisation
Kubernetes is a the leading Container Orchestration.
22
Kubernetes
Pods
Pods can be 1 or
more Container
grouped together,
smallest
scheduling Unit..
API First Deployments Service Discovery
Everything is a Object
inside the Rest API.
Declarative
Configuration with
YAML files.
Higher Level
Abstraction to say
run Pod X Times.
Services are used to
make Pods discovery
each other.
Kubernetes in 30 Seconds
23
The Basic you need to know for the Rest of the Talk
—KUBELET FLAG
—feature-gates=
"Accelerators=true"
Out of Scope for a Data Conference
24
How to enable GPU in your K8S cluster?
•Install Docker, nvidia-docker-bridge, cuda
Single Worker Instance
• Prepare our Docker Image
•Use prebuild Tensorflow image and add additional Libraries & Custom Code (gcr.io/tensorflow/tensorflow)
•special images form cpu/gpu builds, see docker hub tags
•Build & Push to a Registry
25
Write Kubernetes Pod Deployment
•Tell kubernetes to use GPU Resource
•Mount NVIDIA Libraries from Host
26
Full Pod Yaml
27
Distributed Tensorflow - Python Code
•Add clusterSpec and server information to code
•Use Flags/Envirmoent Variable to inject dynamically this information
•Write your TF Graph
•Either Manual Placement or automatic
•Dockerfile stays same/similiar
28
Distributed Tensorflow - Kubernetes Deployment
•Slightly different deployments for worker and ps nodes
•Service for each woker/ps task
•Job Name/worker index by flags
29
Distributed Kubernetes - Parameter Server
30
Automation - Tensorflow Operator
•Boilerplate code for larger cluster
•Official Documentation: Jinja Templating
•Tensorflow Operator:
•Higher level description, creates lower level objects.
•Still in the Kubernetes API (though CustomResourceDefinition)
•kubectl get tensorflow
•Comping Soon: https://github.com/krallistic/tensorflow-operator
31
Additional Stuff
•Tensorboard:
•Needs a global shared filesystem
•Instances write into subfolder
•Tensorboard Instances reads full folder
•Performance
•Scales amount of Parameter Servers
•Many CPU nodes can be more cost efficient
32
codecentric AG
Gartenstraße 69a
76135 Karlsruhe
E-Mail: jakob.karalus@codecentric.de
Twitter: @krallistic
Github: krallistic
www.codecentric.de
Address
Contact Info
Questions?
33

More Related Content

PDF
Managing Stateful Services with the Operator Pattern in Kubernetes - Kubernet...
PDF
The Kubernetes Operator Pattern - ContainerConf Nov 2017
PDF
Kafka on Kubernetes: Keeping It Simple (Nikki Thean, Etsy) Kafka Summit SF 2019
PDF
[Lakmal] Automate Microservice to API
PDF
Manage Pulsar Cluster Lifecycles with Kubernetes Operators - Pulsar Summit NA...
PDF
Crafting Kubernetes Operators
PDF
Putting Kafka Together with the Best of Google Cloud Platform
PDF
[Spark Summit 2017 NA] Apache Spark on Kubernetes
Managing Stateful Services with the Operator Pattern in Kubernetes - Kubernet...
The Kubernetes Operator Pattern - ContainerConf Nov 2017
Kafka on Kubernetes: Keeping It Simple (Nikki Thean, Etsy) Kafka Summit SF 2019
[Lakmal] Automate Microservice to API
Manage Pulsar Cluster Lifecycles with Kubernetes Operators - Pulsar Summit NA...
Crafting Kubernetes Operators
Putting Kafka Together with the Best of Google Cloud Platform
[Spark Summit 2017 NA] Apache Spark on Kubernetes

What's hot (19)

PDF
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
PDF
Kafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQL
PDF
Spark day 2017 - Spark on Kubernetes
PPTX
Better Kafka Performance Without Changing Any Code | Simon Ritter, Azul
PDF
DockerDay2015: Getting started with Google Container Engine
PDF
Data(?)Ops with CircleCI
PPTX
Cloud Native 오픈소스 서비스 소개 및 Serverless로 실제 게임 개발하기
PDF
CDK Meetup: Rule the World through IaC
PDF
Integrating Apache Kafka and Elastic Using the Connect Framework
PPTX
A Primer on Kubernetes and Google Container Engine
PDF
Better Kafka Performance Without Changing Any Code | Simon Ritter, Azul
PDF
Scylla Summit 2022: What’s New in ScyllaDB Operator for Kubernetes
PPTX
Distributed Kafka Architecture Taboola Scale
PDF
Monitoring, the Prometheus Way - Julius Voltz, Prometheus
PDF
Kubernetes for Serverless - Serverless Summit 2017 - Krishna Kumar
PDF
2016 08-30 Kubernetes talk for Waterloo DevOps
PDF
Serverless Workflow: New approach to Kubernetes service orchestration | DevNa...
PDF
Cloud Native User Group: Shift-Left Testing IaC With PaC
PPTX
Ofir Makmal - Intro To Kubernetes Operators - Google Cloud Summit 2018 Tel Aviv
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
Kafka Summit SF 2017 - Kafka Stream Processing for Everyone with KSQL
Spark day 2017 - Spark on Kubernetes
Better Kafka Performance Without Changing Any Code | Simon Ritter, Azul
DockerDay2015: Getting started with Google Container Engine
Data(?)Ops with CircleCI
Cloud Native 오픈소스 서비스 소개 및 Serverless로 실제 게임 개발하기
CDK Meetup: Rule the World through IaC
Integrating Apache Kafka and Elastic Using the Connect Framework
A Primer on Kubernetes and Google Container Engine
Better Kafka Performance Without Changing Any Code | Simon Ritter, Azul
Scylla Summit 2022: What’s New in ScyllaDB Operator for Kubernetes
Distributed Kafka Architecture Taboola Scale
Monitoring, the Prometheus Way - Julius Voltz, Prometheus
Kubernetes for Serverless - Serverless Summit 2017 - Krishna Kumar
2016 08-30 Kubernetes talk for Waterloo DevOps
Serverless Workflow: New approach to Kubernetes service orchestration | DevNa...
Cloud Native User Group: Shift-Left Testing IaC With PaC
Ofir Makmal - Intro To Kubernetes Operators - Google Cloud Summit 2018 Tel Aviv
Ad

Similar to Distributed Tensorflow with Kubernetes - data2day - Jakob Karalus (20)

PDF
Using Deep Learning Toolkits with Kubernetes clusters
PDF
Democratizing machine learning on kubernetes
PDF
Distributed DNN training: Infrastructure, challenges, and lessons learned
PDF
How To Build Efficient ML Pipelines From The Startup Perspective (GTC Silicon...
PDF
Clustering tensor flow con kubernetes y raspberry pi
PDF
High Performance Distributed TensorFlow in Production with GPUs - NIPS 2017 -...
PDF
Distributed TensorFlow on Hadoop, Mesos, Kubernetes, Spark
PPTX
Parallel & Distributed Deep Learning - Dataworks Summit
PDF
Introduction to DL platform
PPTX
Running Distributed TensorFlow with GPUs on Mesos with DC/OS
PDF
Tensorflow 2.0 and Coral Edge TPU
PDF
High Performance Distributed TensorFlow with GPUs - TensorFlow Chicago Meetup...
PPTX
Parallel/Distributed Deep Learning and CDSW
PPTX
An Introduction to TensorFlow architecture
PDF
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on GPUs
PPTX
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
PDF
Containerized architectures for deep learning
PDF
"Scaling ML from 0 to millions of users", Julien Simon, AWS Dev Day Kyiv 2019
PDF
Toronto meetup 20190917
PDF
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
Using Deep Learning Toolkits with Kubernetes clusters
Democratizing machine learning on kubernetes
Distributed DNN training: Infrastructure, challenges, and lessons learned
How To Build Efficient ML Pipelines From The Startup Perspective (GTC Silicon...
Clustering tensor flow con kubernetes y raspberry pi
High Performance Distributed TensorFlow in Production with GPUs - NIPS 2017 -...
Distributed TensorFlow on Hadoop, Mesos, Kubernetes, Spark
Parallel & Distributed Deep Learning - Dataworks Summit
Introduction to DL platform
Running Distributed TensorFlow with GPUs on Mesos with DC/OS
Tensorflow 2.0 and Coral Edge TPU
High Performance Distributed TensorFlow with GPUs - TensorFlow Chicago Meetup...
Parallel/Distributed Deep Learning and CDSW
An Introduction to TensorFlow architecture
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on GPUs
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
Containerized architectures for deep learning
"Scaling ML from 0 to millions of users", Julien Simon, AWS Dev Day Kyiv 2019
Toronto meetup 20190917
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
Ad

Recently uploaded (20)

PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPT
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
PPTX
Supervised vs unsupervised machine learning algorithms
PPTX
Global journeys: estimating international migration
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
Computer network topology notes for revision
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPTX
1_Introduction to advance data techniques.pptx
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPT
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
PPTX
Major-Components-ofNKJNNKNKNKNKronment.pptx
PPT
Quality review (1)_presentation of this 21
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
Supervised vs unsupervised machine learning algorithms
Global journeys: estimating international migration
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
Clinical guidelines as a resource for EBP(1).pdf
STUDY DESIGN details- Lt Col Maksud (21).pptx
Computer network topology notes for revision
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
climate analysis of Dhaka ,Banglades.pptx
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
oil_refinery_comprehensive_20250804084928 (1).pptx
1_Introduction to advance data techniques.pptx
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
Major-Components-ofNKJNNKNKNKNKronment.pptx
Quality review (1)_presentation of this 21
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx

Distributed Tensorflow with Kubernetes - data2day - Jakob Karalus

  • 1. Distributed Tensorflow with Kubernetes Jakob Karalus, @krallistic, 1
  • 2. Training Neural Networks •First steps are quick and easy. •Single Node Neural Networks •We want: •More Data! •Deeper Models! •Wider Model! •Higher Accuracy! •(Single Node) Compute cant keep up •Longer Trainingstime -> Longer Cycles -> Lower Productivity 2
  • 3. Distributed & Parallel •We need to distribute and train in parallel to be efficient •Data Parallelism •Model Parallelsim •Grid Search •Predict •-> Build in TF •How can we deploy that to a cluster •Schedule TF onto Nodes •Service Discovery •GPUs •-> Kubernetes 3
  • 4. Requirements & Content •Basic Knowledge of Neural Networks •Knowledge of Tensorflow •Basic Docker/Kubernetes knowledge •(Docker) Containers: Mini VM (Wrong!) •Kubernetes: Schedulurer/Orchestration Tool for Containers •Only focus on the task of parallel and/or distributed training •We will not look at architectures like CNN/LTSM etc 4
  • 5. Tensorflow on a single node 5 •Build your Graph •Define which Parts on each device •TF places data •DMA for coordination/communication • Define loss, accuracy etc •Create Session for training •Feed Data into Session •Retrieve results cpu:0 gpu:0 /job:worker/task:0/ Client Code
  • 6. Parameter Server & Worker Replicas •Client: Code that builds the Graph, communicates with cluster, builds the session •Cluster: Set of nodes which have jobs (roles) •Jobs •Worker Replicas: compute intensive part •Parameter Servers(ps): Holds model state and reacts to updates •Each job can hold 0..* task •Task •The actual server process •Worker Task 0 is by default the chief worker •Responsible for checkpointing, initialising and health checking •CPU 0 represents all CPUs on the Node 6 Client Code Session Graph Graph cpu:0 gpu:0 /job:worker/task:0/ cpu:0 /job:ps/task:0/
  • 7. In Graph Replication •Split up input into equal chunks, •Loops over workers and assign a chunk •collect results and optimise •Not the recommended way •Graph get big, lot of communication overhead •Each device operates on all data 7 cpu:0 gpu:0 /job:worker/task:0/ cpu:0 gpu:0 /job:worker/task:0/ cpu:0 /job:ps/task:0/ Client Code
  • 8. Between Replication •Recommend way of doing replication •Similiar to MPI •Each device operates on a partition •Different Client Program on each worker •Assign itself to local resources •Small graph independently 8 cpu:0gpu:0 /job:worker/task:0/ cpu:0 gpu:0 /job:worker/task:0/ cpu:0 /job:ps/task:0/ Client CodeClient Code
  • 9. Variable Placement •How to place the Variable onto different devices •Manual Way •Easy to start, full flexibility •Gets annoying soon •Device setter •Automatic assign variables to ps and ops to workers •Simple round robin by default •Greedy Load Balancing Strategy •Partitioned Values •Needed for really large variables (often used in text embeddings) •Splits variables between multiple Parameter Server 9
  • 10. Training Modes Syncronous Replication Every Instances reads the same values for current parameters, computes the gradient in parallel and the app them together. Asycronoues Replication Independent training loop in every Instance, without coordination. Better performance but lower accuracy. 10 How to update the parameters between instances?
  • 12. Asyncronous Training 12 Parameter Server Update P Model Model Input Input Update • Each Updates Independently • Nodes can read stale nodes from PS • Possible: Model dont converge ΔP ΔP
  • 13. 1. Define the Cluster •Define ClusterSpec •List Parameter Servers •List Workers •PS & Worker are called Jobs •Jobs can contain one ore more Tasks •Create Server for every Task 13
  • 14. 2. Assign Operation to every Task •Same on every Node for In-Graph •Different Devices for Between-Graph •Can also be used to set parts to GPU and parts to CPU 14
  • 15. 3. Create a Training Session •tf.train.MonitoredTrainingSession or tf.train.Supervisor for Asyncronous Training •Takes care of initialisation •Snapshotting •Closing if an error occurs •Hooks •Summary Ops, Init Ops •tf.train.SyncReplicaOptimizer for synchronous training: •Also create a supervisor that takes over the role a a master between workers. 15
  • 16. All Together - Server Init 16
  • 17. All Together - Building Graph 17
  • 18. All Together - TrainingOP 18
  • 19. All Together - Session & Training 19
  • 21. Packaging •The Application (and all its) dependencies needs to be packaged into a deployable •Wheels •Code into deployable Artefact with defined dependencies •Dependent on runtime •Container •Build Image with runtime, dependencies and code •Additional Tooling for building and running required (Docker) 21
  • 22. GPU Support Alpha since 1.6 (experimental before) Huge Community One of the fastest growing community Auto Scaling Build in Auto Scaling Feature based on Ultitisation Developer friendly API Quick deployments through simple and flexible API. Open Source Open Sourced by Google, now member of Cloud Computing Foundation. Bin Packing Efficient resource utilisation Kubernetes is a the leading Container Orchestration. 22 Kubernetes
  • 23. Pods Pods can be 1 or more Container grouped together, smallest scheduling Unit.. API First Deployments Service Discovery Everything is a Object inside the Rest API. Declarative Configuration with YAML files. Higher Level Abstraction to say run Pod X Times. Services are used to make Pods discovery each other. Kubernetes in 30 Seconds 23 The Basic you need to know for the Rest of the Talk
  • 24. —KUBELET FLAG —feature-gates= "Accelerators=true" Out of Scope for a Data Conference 24 How to enable GPU in your K8S cluster? •Install Docker, nvidia-docker-bridge, cuda
  • 25. Single Worker Instance • Prepare our Docker Image •Use prebuild Tensorflow image and add additional Libraries & Custom Code (gcr.io/tensorflow/tensorflow) •special images form cpu/gpu builds, see docker hub tags •Build & Push to a Registry 25
  • 26. Write Kubernetes Pod Deployment •Tell kubernetes to use GPU Resource •Mount NVIDIA Libraries from Host 26
  • 28. Distributed Tensorflow - Python Code •Add clusterSpec and server information to code •Use Flags/Envirmoent Variable to inject dynamically this information •Write your TF Graph •Either Manual Placement or automatic •Dockerfile stays same/similiar 28
  • 29. Distributed Tensorflow - Kubernetes Deployment •Slightly different deployments for worker and ps nodes •Service for each woker/ps task •Job Name/worker index by flags 29
  • 30. Distributed Kubernetes - Parameter Server 30
  • 31. Automation - Tensorflow Operator •Boilerplate code for larger cluster •Official Documentation: Jinja Templating •Tensorflow Operator: •Higher level description, creates lower level objects. •Still in the Kubernetes API (though CustomResourceDefinition) •kubectl get tensorflow •Comping Soon: https://github.com/krallistic/tensorflow-operator 31
  • 32. Additional Stuff •Tensorboard: •Needs a global shared filesystem •Instances write into subfolder •Tensorboard Instances reads full folder •Performance •Scales amount of Parameter Servers •Many CPU nodes can be more cost efficient 32
  • 33. codecentric AG Gartenstraße 69a 76135 Karlsruhe E-Mail: [email protected] Twitter: @krallistic Github: krallistic www.codecentric.de Address Contact Info Questions? 33