SlideShare a Scribd company logo
BUILDING GOOGLE CLOUD ML ENGINE
FROM SCRATCH WITH PIPELINE.AI
ODSC CONFERENCE
LONDON, ENGLAND
OCTOBER 13, 2017
CHRIS FREGLY,
FOUNDER @ PIPELINE.AI
INTRODUCTIONS: ME
§ Chris Fregly, Research Engineer @ PipelineAI
§ Formerly Netflix, Databricks, IBM Spark Center
§ Advanced Spark and TensorFlow Meetup
Please Join Our 40,000+ Members Globally!
Contact Me
chris@pipeline.ai
@cfregly
*San Francisco
*Chicago
*Austin
*Washington DC
*London
INTRODUCTIONS: YOU
§ Software Engineer or Data Scientist interested in optimizing
and deploying TensorFlow models to production
§ Assume you have a working knowledge of TensorFlow
CONTENT BREAKDOWN
§ PipelineAI Features
§ 50% Training Optimizations (GPUs, Pipeline, XLA+JIT)
§ 50% Prediction Optimizations (XLA+AOT, TF Serving)
§ Why Heavy Focus on Predicting?
§ Training: boring batch O(num_data_scientists)
§ Inference: exciting real-time O(num_users_of_app)
100% OPEN SOURCE CODE
§ https://github.com/PipelineAI/pipeline/
§ Please 🌟 this GitHub Repo!
§ All slides, code, notebooks, and Docker images here:
https://github.com/PipelineAI/pipeline/tree/master/gpu
AGENDA
§ PipelineAI Features
§ Experiment Safely in Production
§ Tune Both Model + Runtime Parameters
§ Compare Models Both Offline + Online
§ Shift Traffic (Across Clouds) to Winning Model
§ Optimize TensorFlow Training
§ GPUs + Ingestion + Training Pipeline
§ XLA JIT Compiler
§ Optimize TensorFlow Inference
§ XLA AOT Compiler + Graph Transform Tool (GTT)
§ TensorFlow Serving
PIPELINE.AI
EXPERIMENT SAFELY IN PRODUCTION
§ Setup Experiments Directly from Jupyter Notebooks
§ Deploy to 1% Prod Traffic
§ Or Deploy in Shadow Mode
§ Tear-Down Experiments Quickly
AGENDA
§ PipelineAI Features
§ Experiment Safely in Production
§ Tune Both Model + Runtime Parameters
§ Compare Models Both Offline + Online
§ Shift Traffic (Across Clouds) to Winning Model
§ Optimize TensorFlow Training
§ GPUs + Ingestion + Training Pipeline
§ XLA JIT Compiler
§ Optimize TensorFlow Inference
§ XLA AOT Compiler + Graph Transform Tool (GTT)
§ TensorFlow Serving
MODEL + RUNTIME PACKAGING
§ Package Model + Runtime into Immutable Docker Image
§ Same Package: Local, Dev, and Prod
§ No Dependency Surprises in Production
OPTIMIZE MODEL + RUNTIME AS ONE
§ Tune Model Params + Runtime Configs Together
§ Generate Native CPU + GPU Code
§ Quantize Model Weights + Activations
§ Swap Runtimes: TF Serving, TensorRT, CPU, GPU, TPU
NVIDIA TENSORRT RUNTIME
§ Performs Post-Training Optimizations
§ GPU-Optimized Prediction Runtime
§ Alternative to TensorFlow Serving
AGENDA
§ PipelineAI Features
§ Experiment Safely in Production
§ Tune Both Model + Runtime Parameters
§ Compare Models Both Offline + Online
§ Shift Traffic (Across Clouds) to Winning Model
§ Optimize TensorFlow Training
§ GPUs + Ingestion + Training Pipeline
§ XLA JIT Compiler
§ Optimize TensorFlow Inference
§ XLA AOT Compiler + Graph Transform Tool (GTT)
§ TensorFlow Serving
COMPARE MODELS OFFLINE + ONLINE
§ Offline Metrics
§ Training Accuracy
§ Validation Accuracy
§ Online / Real-Time Metrics
§ Prediction Precision
§ Latency + Throughput
PREDICTION PROFILING + TUNING
§ Pinpoint Performance Bottlenecks
§ Fine-Grained Prediction Metrics
§ 3 Logic Steps in a Prediction
1. transform_request()
2. predict()
3. transform_response()
AGENDA
§ PipelineAI Features
§ Experiment Safely in Production
§ Tune Both Model + Runtime Parameters
§ Compare Models Both Offline + Online
§ Shift Traffic (Across Clouds) to Winning Model
§ Optimize TensorFlow Training
§ GPUs + Ingestion + Training Pipeline
§ XLA JIT Compiler
§ Optimize TensorFlow Inference
§ XLA AOT Compiler + Graph Transform Tool (GTT)
§ TensorFlow Serving
SHIFT TRAFFIC TO MAXIMIZE REVENUE
§ Shift Traffic to Winning Model using Bandit AI Algorithms
SHIFT TRAFFIC TO MINIMIZE COST
§ Real-Time Cost Per Prediction
§ Across Clouds + On-Premise
§ Bandit-Based Explore/Exploit
VIEW LIVE PREDICTION STREAMS
§ Visually Compare Real-Time Predictions
CONTINUOUS MODEL TRAINING
§ Identify and Fix Borderline Predictions (50-50% Confidence)
§ Fix Along Class Boundaries
§ Retrain on New Labeled Data
§ Enables Crowd Sourcing
§ Game-ify Labeling Process
AGENDA
§ PipelineAI Features
§ Experiment Safely in Production
§ Tune Both Model + Runtime Parameters
§ Compare Models Both Offline + Online
§ Shift Traffic (Across Clouds) to Winning Model
§ Optimize TensorFlow Training
§ GPUs + Ingestion + Training Pipeline
§ XLA JIT Compiler
§ Optimize TensorFlow Inference
§ XLA AOT Compiler + Graph Transform Tool (GTT)
§ TensorFlow Serving
SETTING UP TENSORFLOW WITH GPUS
§ Very Painful!
§ Especially inside Docker
§ Use nvidia-docker
§ Especially on Kubernetes!
§ Use Kubernetes 1.7+
§ http://pipeline.ai for GitHub + DockerHub Links
GPU HALF-PRECISION SUPPORT
§ FP32 is “Full Precision”, FP16 is “Half Precision”
§ Supported by Pascal P100 (2016) and Volta V100 (2017)
§ Flexible FP32 GPU Cores Can Fit 2 FP16’s for 2x Throughput!
§ Half-Precision is OK for Approximate Deep Learning Use Cases
VOLTA V100 RECENTLY ANNOUNCED
§ 84 Streaming Multiprocessors (SM’s)
§ 5,376 GPU Cores
§ 672 Tensor Cores (ie. Google TPU)
§ Mixed FP16/FP32 Precision
§ More Shared Memory
§ New L0 Instruction Cache
§ Faster L1 Data Cache
§ V100 vs. P100 Performance
§ 12x TFLOPS @ Peak Training
§ 6x Inference Throughput
V100 AND CUDA 9
§ Independent Thread Scheduling - Finally!!
§ Similar to CPU fine-grained thread synchronization semantics
§ Allows GPU to yield execution of any thread
§ Still Optimized for SIMT (Same Instruction Multiple Thread)
§ SIMT units automatically scheduled together
§ Explicit Thread Synchronization
P100 V100
GPU CUDA PROGRAMMING
§ Barbaric, But Fun Barbaric
§ Must Know Hardware Very Well
§ Hardware Changes are Painful
§ Many Great Debuggers Exist
CUDA STREAMS
§ Asynchronous I/O Transfer
§ Overlap Compute and I/O
§ Keeps GPUs Saturated
§ Fundamental to Queue Framework in TensorFlow
TRAINING TERMINOLOGY
§ Tensors: N-Dimensional Arrays
§ ie. Scalar, Vector, Matrix
§ Operations: MatMul, Add, SummaryLog,…
§ Graph: Graph of Operations (DAG)
§ Session: Contains Graph(s)
§ Feeds: Feed inputs into Placeholder
§ Fetches: Fetch output from Operation
§ Variables: What we learn through training
§ aka “weights”, “parameters”
§ Devices: Hardware device on which we train
-TensorFlow-
Trains
Variables
-User-
Fetches
Outputs
-User-
Feeds
Inputs
-TensorFlow-
Performs
Operations
-TensorFlow-
Flows
Tensors
with tf.device(“/gpu:0,/gpu:1”)
TENSORFLOW MODEL
§ MetaGraph
§ Combines GraphDef and Metadata
§ GraphDef
§ Architecture of your model (nodes, edges)
§ Metadata
§ Asset: Accompanying assets to your model
§ SignatureDef: Maps external : internal tensors
§ Variables
§ Stored separately during training (checkpoint)
§ Allows training to continue from any checkpoint
§ Variables are “frozen” into Constants when deployed for inference
GraphDef
x
W
mul add
b
MetaGraph
Metadata
Assets
SignatureDef
Tags
Version
Variables:
“W” : 0.328
“b” : -1.407
TENSORFLOW SESSION
Session
graph: GraphDef
Variables:
“W” : 0.328
“b” : -1.407
Variables are
Periodically
Checkpointed
GraphDef
is Static
EXTEND EXISTING DATA PIPELINES
§ Data Processing
§ HDFS/Hadoop
§ Spark
§ Containers
§ Docker
§ Google Container
§ Container Orchestrators
§ Kubernetes
§ Mesos
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-hadoop</artifactId>
</dependency>
https://github.com/tensorflow/ecosystem
DON’T USE FEED_DICT
§ Not Optimized for Production Pipelines
§ feed_dict Requires Python <-> C++ Serialization
§ Single-threaded, Synchronous, SLOW!
§ Can’t Retrieve Until Current Batch is Complete
§ CPUs/GPUs Not Fully Utilized!
§ Use Queue or Dataset API
QUEUES
§ More than just a traditional Queue
§ Perform I/O, pre-processing, cropping, shuffling
§ Pulls from HDFS, S3, Google Storage, Kafka, ...
§ Combine many small files into large TFRecord files
§ Use CPUs to free GPUs for compute
§ Uses CUDA Streams
§ Helps saturate CPUs and GPUs
QUEUE CAPACITY PLANNING
§ batch_size
§ # examples / batch (ie. 64 jpg)
§ Limited by GPU RAM
§ num_processing_threads
§ CPU threads pull and pre-process batches of data
§ Limited by CPU Cores
§ queue_capacity
§ Limited by CPU RAM (ie. 5 * batch_size)
DETECT UNDERUTILIZED CPUS, GPUS
§ Instrument training code to generate “timelines”
§ Analyze with Google Web
Tracing Framework (WTF)
§ Monitor CPU with `top`, GPU with `nvidia-smi`
http://google.github.io/tracing-framework/
from tensorflow.python.client import timeline
trace =
timeline.Timeline(step_stats=run_metadata.step_stats)
with open('timeline.json', 'w') as trace_file:
trace_file.write(
trace.generate_chrome_trace_format(show_memory=True))
SINGLE NODE, MULTI-GPU TRAINING
§ cpu:0
§ By default, all CPUs
§ Requires extra config to target a CPU
§ gpu:0..n
§ Each GPU has a unique id
§ TF usually prefers a single GPU
§ xla_cpu:0, xla_gpu:0..n
§ “JIT Compiler Device”
§ Hints TensorFlow to attempt JIT Compile
with tf.device(“/cpu:0”):
with tf.device(“/gpu:0”):
with tf.device(“/gpu:1”):
GPU 0 GPU 1
MULTI-NODE DISTRIBUTED TRAINING
§ TensorFlow Automatically Inserts Send and Receive Ops into Graph
§ Parameter Server Synchronously Aggregates Updates to Variables
§ Nodes with Multiple GPUs will Pre-Aggregate Before Sending to PS
Worker0 Worker0
Worker1
Worker0 Worker1 Worker2
gpu0 gpu1
gpu2 gpu3
gpu0 gpu1
gpu2 gpu3
gpu0 gpu1
gpu2 gpu3
gpu0
gpu1
gpu0
gpu0
SYNCHRONOUS VS. ASYNCHRONOUS
§ Synchronous
§ Nodes compute gradients
§ Nodes update Parameter Server (PS)
§ Nodes sync on PS for latest gradients
§ Asynchronous
§ Some nodes delay in computing gradients
§ Nodes don’t update PS
§ Nodes get stale gradients from PS
§ May not converge due to stale reads!
BATCH NORMALIZATION
§ Each mini-batch may have wildly different distributions
§ Normalize per batch (and layer)
§ Speeds up training!!
§ Weights are learned quicker
§ Final model is more accurate
§ Final mean and variance will be folded into Graph later
-- Pretty Much Always Use Batch Normalization! --
z = tf.matmul(a_prev, W)
a = tf.nn.relu(z)
a_mean, a_var = tf.nn.moments(a, [0])
scale = tf.Variable(tf.ones([depth/channels]))
beta = tf.Variable(tf.zeros ([depth/channels]))
bn = tf.nn.batch_normalizaton(a, a_mean, a_var,
beta, scale, 0.001)
OPTIMIZE GRAPH EXECUTION ORDER
§ https://github.com/yaroslavvb/stuff
Linearize to
minimize graph
memory usage
SEPARATE TRAINING + VALIDATION
§ Separate Training and Validation Clusters
§ Validate Upon Checkpoint
§ Avoids Resource Contention
Training
Cluster
Validation
Cluster
Parameter Server
Cluster
AGENDA
§ PipelineAI Features
§ Experiment Safely in Production
§ Tune Both Model + Runtime Parameters
§ Compare Models Both Offline + Online
§ Shift Traffic (Across Clouds) to Winning Model
§ Optimize TensorFlow Training
§ GPUs + Ingestion + Training Pipeline
§ XLA JIT Compiler
§ Optimize TensorFlow Inference
§ XLA AOT Compiler + Graph Transform Tool (GTT)
§ TensorFlow Serving
XLA FRAMEWORK
§ Accelerated Linear Algebra (XLA)
§ Goals:
§ Reduce reliance on custom operators
§ Improve execution speed
§ Improve memory usage
§ Reduce mobile footprint
§ Improve portability
§ Helps TensorFlow Stay Both Flexible and Performant
XLA HIGH LEVEL OPTIMIZER (HLO)
§ Compiler Intermediate Representation (IR)
§ Independent of Source and Target Language
§ Define Graphs using HLO Operations
§ XLA Step 1 Emits Target-Independent HLO
§ XLA Step 2 Emits Target-Dependent LLVM
§ LLVM Emits Native Code Specific to Target
§ Supports x86-64, ARM64 (CPU), and NVPTX (GPU)
JIT COMPILER
§ Just-In-Time Compiler
§ Built on XLA Framework
§ Goals:
§ Reduce memory movement – especially useful on GPUs
§ Reduce overhead of multiple function calls
§ Similar to Spark Operator Fusing in Spark 2.0
§ Unroll Loops, Fuse Operators, Fold Constants, …
§ Scope to session, device, or `with jit_scope():`
VISUALIZING JIT COMPILER IN ACTION
Before After
Google Web Tracing Framework:
http://google.github.io/tracing-framework/
from tensorflow.python.client import timeline
trace =
timeline.Timeline(step_stats=run_metadata.step_stats)
with open('timeline.json', 'w') as trace_file:
trace_file.write(
trace.generate_chrome_trace_format(show_memory=True))
VISUALIZING FUSING OPERATORS
pip install graphviz
dot -Tpng 
/tmp/hlo_graph_1.w5LcGs.dot 
-o hlo_graph_1.png
GraphViz:
http://www.graphviz.org
hlo_*.dot files generated by XLA
AGENDA
§ PipelineAI Features
§ Experiment Safely in Production
§ Tune Both Model + Runtime Parameters
§ Compare Models Both Offline + Online
§ Shift Traffic (Across Clouds) to Winning Model
§ Optimize TensorFlow Training
§ GPUs + Ingestion + Training Pipeline
§ XLA JIT Compiler
§ Optimize TensorFlow Inference
§ XLA AOT Compiler + Graph Transform Tool (GTT)
§ TensorFlow Serving
AOT COMPILER
§ Standalone, Ahead-Of-Time (AOT) Compiler
§ Built on XLA framework
§ tfcompile
§ Creates executable with minimal TensorFlow Runtime needed
§ Includes only dependencies needed by subgraph computation
§ Creates functions with feeds (inputs) and fetches (outputs)
§ Packaged as cc_libary header and object files to link into your app
§ Commonly used for mobile device inference graph
§ Currently, only CPU x86-64 and ARM are supported - no GPU
GRAPH TRANSFORM TOOL (GTT)
§ Optimize Trained Models for Inference
§ Remove training-only Ops (checkpoint, drop out, logs)
§ Remove unreachable nodes between given feed -> fetch
§ Fuse adjacent operators to improve memory bandwidth
§ Fold final batch norm mean and variance into variables
§ Round weights/variables improves compression (ie. 70%)
§ Quantize (FP32 -> INT8) to speed up math operations
BEFORE OPTIMIZATIONS
GRAPH TRANSFORM TOOL
transform_graph 
--in_graph=tensorflow_inception_graph.pb  ß Original Graph
--out_graph=optimized_inception_graph.pb  ß Transformed Graph
--inputs='Mul'  ß Feed (Input)
--outputs='softmax'  ß Fetch (Output)
--transforms=' ß List of Transforms
strip_unused_nodes
remove_nodes(op=Identity, op=CheckNumerics)
fold_constants(ignore_errors=true)
fold_batch_norms
fold_old_batch_norms
quantize_weights
quantize_nodes'
AFTER STRIPPING UNUSED NODES
§ Optimizations
§ strip_unused_nodes
§ Results
§ Graph much simpler
§ File size much smaller
AFTER REMOVING UNUSED NODES
§ Optimizations
§ strip_unused_nodes
§ remove_nodes
§ Results
§ Pesky nodes removed
§ File size a bit smaller
AFTER FOLDING CONSTANTS
§ Optimizations
§ strip_unused_nodes
§ remove_nodes
§ fold_constants
§ Results
§ Placeholders (feeds) -> Variables*
(*Why Variables and not Constants?)
AFTER FOLDING BATCH NORMS
§ Optimizations
§ strip_unused_nodes
§ remove_nodes
§ fold_constants
§ fold_batch_norms
§ Results
§ Graph remains the same
§ File size approximately the same
WEIGHT QUANTIZATION
§ FP16 and INT8 Are Computationally Simpler and Faster
§ Weights/Variables are Constants
§ Easy to Linearly Quantize
AFTER QUANTIZING WEIGHTS
§ Optimizations
§ strip_unused_nodes
§ remove_nodes
§ fold_constants
§ fold_batch_norms
§ quantize_weights
§ Results
§ Graph is same, file size is smaller, compute is faster
BUT WAIT, THERE’S MORE!
ACTIVATION QUANTIZATION
§ Activations Not Known Ahead of Time
§ Depends on input, not easy to quantize
§ Requires Additional Calibration Step
§ Use a “representative” dataset
§ Per Neural Network Layer…
§ Collect histogram of activation values
§ Generate many quantized distributions with different saturation thresholds
§ Choose threshold to minimize…
KL_divergence(ref_distribution, quant_distribution)
§ Not Much Time or Data is Required (Minutes on Commodity Hardware)
AFTER ACTIVATION QUANTIZATION
§ Optimizations
§ strip_unused_nodes
§ remove_nodes
§ fold_constants
§ fold_batch_norms
§ quantize_weights
§ quantize_nodes (activations)
§ Results
§ Larger graph, needs calibration!
Requires additional
freeze_requantization_ranges
FREEZING MODEL FOR DEPLOYMENT
§ Optimizations
§ strip_unused_nodes
§ remove_nodes
§ fold_constants
§ fold_batch_norms
§ quantize_weights
§ quantize_nodes
§ freeze_graph
§ Results
§ Variables -> Constants
Finally!
We’re Ready to Deploy!!
AGENDA
§ PipelineAI Features
§ Experiment Safely in Production
§ Tune Both Model + Runtime Parameters
§ Compare Models Both Offline + Online
§ Shift Traffic (Across Clouds) to Winning Model
§ Optimize TensorFlow Training
§ GPUs + Ingestion + Training Pipeline
§ XLA JIT Compiler
§ Optimize TensorFlow Inference
§ XLA AOT Compiler + Graph Transform Tool (GTT)
§ TensorFlow Serving
TENSORFLOW SERVING OVERVIEW
§ Inference
§ Only Forward Propagation through Network
§ Predict, Classify, Regress, …
§ Bundle
§ GraphDef, Variables, Metadata, …
§ Assets
§ ie. Map of ClassificationID -> String
§ {9283: “penguin”, 9284: “bridge”}
§ Version
§ Every Model Has a Version Number (Integer)
§ Version Policy
§ ie. Serve Only Latest (Highest), Serve Both Latest and Previous, …
MULTI-HEADED INFERENCE
§ Multiple “heads” (aka “responses”) from 1 model prediction
§ Optimizes bandwidth, CPU, latency, memory, coolness
§ Response includes both class and scores
§ Inputs sent only once
§ Feed scores into ensemble models
§ Use model for feature engineering
REQUEST BATCHING
§ max_batch_size
§ Enables throughput/latency tradeoff
§ Bounded by RAM
§ batch_timeout_micros
§ Defines batch time window, latency upper-bound
§ Bounded by RAM
§ num_batch_threads
§ Defines parallelism
§ Bounded by CPU cores
§ max_enqueued_batches
§ Defines queue upper bound, throttling
§ Bounded by RAM
Reaching either threshold
will trigger a batch
YOU JUST LEARNED…
§ PipelineAI Features
§ Experiment Safely in Production
§ Tune Both Model + Runtime Parameters
§ Compare Models Both Offline + Online
§ Shift Traffic (Across Clouds) to Winning Model
§ Optimize TensorFlow Training
§ GPUs + Ingestion + Training Pipeline
§ XLA JIT Compiler
§ Optimize TensorFlow Inference
§ XLA AOT Compiler + Graph Transform Tool (GTT)
§ TensorFlow Serving
THANKS! ANY QUESTIONS?
§ https://github.com/PipelineAI/pipeline/
§ Please 🌟 this GitHub Repo!
§ All slides, code, notebooks, and Docker images here:
https://github.com/PipelineAI/pipeline/tree/master/gpu
Contact Me
chris@pipeline.ai
@cfregly

More Related Content

PDF
High Performance TensorFlow in Production - Big Data Spain - Madrid - Nov 15 ...
PDF
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...
PDF
PipelineAI Optimizes Your Enterprise AI Pipeline from Distributed Training to...
PDF
Nvidia GPU Tech Conference - Optimizing, Profiling, and Deploying TensorFlow...
PDF
Optimizing, Profiling, and Deploying TensorFlow AI Models in Production with ...
PDF
Hyper-Parameter Tuning Across the Entire AI Pipeline GPU Tech Conference San ...
PDF
High Performance Distributed TensorFlow with GPUs - TensorFlow Chicago Meetup...
PDF
PipelineAI + TensorFlow AI + Spark ML + Kuberenetes + Istio + AWS SageMaker +...
High Performance TensorFlow in Production - Big Data Spain - Madrid - Nov 15 ...
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on G...
PipelineAI Optimizes Your Enterprise AI Pipeline from Distributed Training to...
Nvidia GPU Tech Conference - Optimizing, Profiling, and Deploying TensorFlow...
Optimizing, Profiling, and Deploying TensorFlow AI Models in Production with ...
Hyper-Parameter Tuning Across the Entire AI Pipeline GPU Tech Conference San ...
High Performance Distributed TensorFlow with GPUs - TensorFlow Chicago Meetup...
PipelineAI + TensorFlow AI + Spark ML + Kuberenetes + Istio + AWS SageMaker +...

What's hot (20)

PDF
High Performance TensorFlow in Production -- Sydney ML / AI Train Workshop @ ...
PDF
Building Google's ML Engine from Scratch on AWS with GPUs, Kubernetes, Istio,...
PDF
PipelineAI + AWS SageMaker + Distributed TensorFlow + AI Model Training and S...
PDF
Optimizing, Profiling, and Deploying TensorFlow AI Models with GPUs - San Fra...
PDF
High Performance Distributed TensorFlow in Production with GPUs - NIPS 2017 -...
PDF
High Performance Distributed TensorFlow with GPUs - Nvidia GPU Tech Conferenc...
PDF
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on GPUs
PDF
High Performance Distributed TensorFlow with GPUs - NYC Workshop - July 9 2017
PDF
Spark SQL Catalyst Optimizer, Custom Expressions, UDFs - Advanced Spark and T...
PDF
Introduction to Polyaxon
KEY
High performance network programming on the jvm oscon 2012
PDF
Optimizing Application Performance on Kubernetes
PPTX
Usenix lisa 2011
PDF
Caching with Memcached and APC
PPT
Velocity 2010 - ATS
ODP
Performance Optimization of Rails Applications
PPT
Oscon 2010 - ATS
PDF
Rails Application Optimization Techniques & Tools
PPTX
Migrating to a Bazel-based CI System: 6 Learnings - Or Shachar
ODP
Improving PHP Application Performance with APC
High Performance TensorFlow in Production -- Sydney ML / AI Train Workshop @ ...
Building Google's ML Engine from Scratch on AWS with GPUs, Kubernetes, Istio,...
PipelineAI + AWS SageMaker + Distributed TensorFlow + AI Model Training and S...
Optimizing, Profiling, and Deploying TensorFlow AI Models with GPUs - San Fra...
High Performance Distributed TensorFlow in Production with GPUs - NIPS 2017 -...
High Performance Distributed TensorFlow with GPUs - Nvidia GPU Tech Conferenc...
Optimize + Deploy Distributed Tensorflow, Spark, and Scikit-Learn Models on GPUs
High Performance Distributed TensorFlow with GPUs - NYC Workshop - July 9 2017
Spark SQL Catalyst Optimizer, Custom Expressions, UDFs - Advanced Spark and T...
Introduction to Polyaxon
High performance network programming on the jvm oscon 2012
Optimizing Application Performance on Kubernetes
Usenix lisa 2011
Caching with Memcached and APC
Velocity 2010 - ATS
Performance Optimization of Rails Applications
Oscon 2010 - ATS
Rails Application Optimization Techniques & Tools
Migrating to a Bazel-based CI System: 6 Learnings - Or Shachar
Improving PHP Application Performance with APC
Ad

Similar to Building Google Cloud ML Engine From Scratch on AWS with PipelineAI - ODSC London 2017 - Oct 13, 2017 (20)

PDF
Optimizing, profiling and deploying high performance Spark ML and TensorFlow ...
PDF
Optimizing, Profiling, and Deploying High Performance Spark ML and TensorFlow AI
PDF
High Performance Distributed TensorFlow with GPUs and Kubernetes
PPTX
Explore Deep Learning Architecture using Tensorflow 2.0 now! Part 2
PDF
Tensorflow 2.0 and Coral Edge TPU
PDF
PDF
Distributed deep learning optimizations - AI WithTheBest
PPTX
An Introduction to TensorFlow architecture
PDF
Tallinn Estonia Advanced Java Meetup Spark + TensorFlow = TensorFrames Oct 24...
PDF
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
PPTX
Deep Learning with Spark and GPUs
PPTX
Parallel & Distributed Deep Learning - Dataworks Summit
PDF
Monitoring of GPU Usage with Tensorflow Models Using Prometheus
PPTX
Leonid Kuligin "Training ML models with Cloud"
PDF
Deep Learning with Apache Spark and GPUs with Pierce Spitler
PPTX
Learn about Tensorflow for Deep Learning now! Part 1
PDF
Distributed deep learning optimizations for Finance
PDF
Atlanta Hadoop Users Meetup 09 21 2016
PPTX
Innovation with ai at scale on the edge vt sept 2019 v0
PDF
Distributed Deep Learning with Hadoop and TensorFlow
Optimizing, profiling and deploying high performance Spark ML and TensorFlow ...
Optimizing, Profiling, and Deploying High Performance Spark ML and TensorFlow AI
High Performance Distributed TensorFlow with GPUs and Kubernetes
Explore Deep Learning Architecture using Tensorflow 2.0 now! Part 2
Tensorflow 2.0 and Coral Edge TPU
Distributed deep learning optimizations - AI WithTheBest
An Introduction to TensorFlow architecture
Tallinn Estonia Advanced Java Meetup Spark + TensorFlow = TensorFrames Oct 24...
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
Deep Learning with Spark and GPUs
Parallel & Distributed Deep Learning - Dataworks Summit
Monitoring of GPU Usage with Tensorflow Models Using Prometheus
Leonid Kuligin "Training ML models with Cloud"
Deep Learning with Apache Spark and GPUs with Pierce Spitler
Learn about Tensorflow for Deep Learning now! Part 1
Distributed deep learning optimizations for Finance
Atlanta Hadoop Users Meetup 09 21 2016
Innovation with ai at scale on the edge vt sept 2019 v0
Distributed Deep Learning with Hadoop and TensorFlow
Ad

More from Chris Fregly (15)

PDF
AWS reInvent 2022 reCap AI/ML and Data
PDF
Pandas on AWS - Let me count the ways.pdf
PDF
Ray AI Runtime (AIR) on AWS - Data Science On AWS Meetup
PDF
Smokey and the Multi-Armed Bandit Featuring BERT Reynolds Updated
PDF
Amazon reInvent 2020 Recap: AI and Machine Learning
PDF
Waking the Data Scientist at 2am: Detect Model Degradation on Production Mod...
PDF
Quantum Computing with Amazon Braket
PDF
15 Tips to Scale a Large AI/ML Workshop - Both Online and In-Person
PDF
AWS Re:Invent 2019 Re:Cap
PDF
KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...
PDF
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
PDF
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
PDF
PipelineAI Continuous Machine Learning and AI - Rework Deep Learning Summit -...
PDF
PipelineAI Real-Time Machine Learning - Global Artificial Intelligence Confer...
PDF
Advanced Spark and TensorFlow Meetup - Dec 12 2017 - Dong Meng, MapR + Kubern...
AWS reInvent 2022 reCap AI/ML and Data
Pandas on AWS - Let me count the ways.pdf
Ray AI Runtime (AIR) on AWS - Data Science On AWS Meetup
Smokey and the Multi-Armed Bandit Featuring BERT Reynolds Updated
Amazon reInvent 2020 Recap: AI and Machine Learning
Waking the Data Scientist at 2am: Detect Model Degradation on Production Mod...
Quantum Computing with Amazon Braket
15 Tips to Scale a Large AI/ML Workshop - Both Online and In-Person
AWS Re:Invent 2019 Re:Cap
KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...
Swift for TensorFlow - Tanmay Bakshi - Advanced Spark and TensorFlow Meetup -...
Hands-on Learning with KubeFlow + Keras/TensorFlow 2.0 + TF Extended (TFX) + ...
PipelineAI Continuous Machine Learning and AI - Rework Deep Learning Summit -...
PipelineAI Real-Time Machine Learning - Global Artificial Intelligence Confer...
Advanced Spark and TensorFlow Meetup - Dec 12 2017 - Dong Meng, MapR + Kubern...

Recently uploaded (20)

PPTX
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
Database Infoormation System (DBIS).pptx
PPT
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
Global journeys: estimating international migration
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
Moving the Public Sector (Government) to a Digital Adoption
PPTX
Supervised vs unsupervised machine learning algorithms
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PDF
.pdf is not working space design for the following data for the following dat...
PPTX
1_Introduction to advance data techniques.pptx
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
STUDY DESIGN details- Lt Col Maksud (21).pptx
Database Infoormation System (DBIS).pptx
Chapter 2 METAL FORMINGhhhhhhhjjjjmmmmmmmmm
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Global journeys: estimating international migration
Miokarditis (Inflamasi pada Otot Jantung)
Moving the Public Sector (Government) to a Digital Adoption
Supervised vs unsupervised machine learning algorithms
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Galatica Smart Energy Infrastructure Startup Pitch Deck
Introduction-to-Cloud-ComputingFinal.pptx
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
.pdf is not working space design for the following data for the following dat...
1_Introduction to advance data techniques.pptx
oil_refinery_comprehensive_20250804084928 (1).pptx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf

Building Google Cloud ML Engine From Scratch on AWS with PipelineAI - ODSC London 2017 - Oct 13, 2017

  • 1. BUILDING GOOGLE CLOUD ML ENGINE FROM SCRATCH WITH PIPELINE.AI ODSC CONFERENCE LONDON, ENGLAND OCTOBER 13, 2017 CHRIS FREGLY, FOUNDER @ PIPELINE.AI
  • 2. INTRODUCTIONS: ME § Chris Fregly, Research Engineer @ PipelineAI § Formerly Netflix, Databricks, IBM Spark Center § Advanced Spark and TensorFlow Meetup Please Join Our 40,000+ Members Globally! Contact Me chris@pipeline.ai @cfregly *San Francisco *Chicago *Austin *Washington DC *London
  • 3. INTRODUCTIONS: YOU § Software Engineer or Data Scientist interested in optimizing and deploying TensorFlow models to production § Assume you have a working knowledge of TensorFlow
  • 4. CONTENT BREAKDOWN § PipelineAI Features § 50% Training Optimizations (GPUs, Pipeline, XLA+JIT) § 50% Prediction Optimizations (XLA+AOT, TF Serving) § Why Heavy Focus on Predicting? § Training: boring batch O(num_data_scientists) § Inference: exciting real-time O(num_users_of_app)
  • 5. 100% OPEN SOURCE CODE § https://github.com/PipelineAI/pipeline/ § Please 🌟 this GitHub Repo! § All slides, code, notebooks, and Docker images here: https://github.com/PipelineAI/pipeline/tree/master/gpu
  • 6. AGENDA § PipelineAI Features § Experiment Safely in Production § Tune Both Model + Runtime Parameters § Compare Models Both Offline + Online § Shift Traffic (Across Clouds) to Winning Model § Optimize TensorFlow Training § GPUs + Ingestion + Training Pipeline § XLA JIT Compiler § Optimize TensorFlow Inference § XLA AOT Compiler + Graph Transform Tool (GTT) § TensorFlow Serving
  • 8. EXPERIMENT SAFELY IN PRODUCTION § Setup Experiments Directly from Jupyter Notebooks § Deploy to 1% Prod Traffic § Or Deploy in Shadow Mode § Tear-Down Experiments Quickly
  • 9. AGENDA § PipelineAI Features § Experiment Safely in Production § Tune Both Model + Runtime Parameters § Compare Models Both Offline + Online § Shift Traffic (Across Clouds) to Winning Model § Optimize TensorFlow Training § GPUs + Ingestion + Training Pipeline § XLA JIT Compiler § Optimize TensorFlow Inference § XLA AOT Compiler + Graph Transform Tool (GTT) § TensorFlow Serving
  • 10. MODEL + RUNTIME PACKAGING § Package Model + Runtime into Immutable Docker Image § Same Package: Local, Dev, and Prod § No Dependency Surprises in Production
  • 11. OPTIMIZE MODEL + RUNTIME AS ONE § Tune Model Params + Runtime Configs Together § Generate Native CPU + GPU Code § Quantize Model Weights + Activations § Swap Runtimes: TF Serving, TensorRT, CPU, GPU, TPU
  • 12. NVIDIA TENSORRT RUNTIME § Performs Post-Training Optimizations § GPU-Optimized Prediction Runtime § Alternative to TensorFlow Serving
  • 13. AGENDA § PipelineAI Features § Experiment Safely in Production § Tune Both Model + Runtime Parameters § Compare Models Both Offline + Online § Shift Traffic (Across Clouds) to Winning Model § Optimize TensorFlow Training § GPUs + Ingestion + Training Pipeline § XLA JIT Compiler § Optimize TensorFlow Inference § XLA AOT Compiler + Graph Transform Tool (GTT) § TensorFlow Serving
  • 14. COMPARE MODELS OFFLINE + ONLINE § Offline Metrics § Training Accuracy § Validation Accuracy § Online / Real-Time Metrics § Prediction Precision § Latency + Throughput
  • 15. PREDICTION PROFILING + TUNING § Pinpoint Performance Bottlenecks § Fine-Grained Prediction Metrics § 3 Logic Steps in a Prediction 1. transform_request() 2. predict() 3. transform_response()
  • 16. AGENDA § PipelineAI Features § Experiment Safely in Production § Tune Both Model + Runtime Parameters § Compare Models Both Offline + Online § Shift Traffic (Across Clouds) to Winning Model § Optimize TensorFlow Training § GPUs + Ingestion + Training Pipeline § XLA JIT Compiler § Optimize TensorFlow Inference § XLA AOT Compiler + Graph Transform Tool (GTT) § TensorFlow Serving
  • 17. SHIFT TRAFFIC TO MAXIMIZE REVENUE § Shift Traffic to Winning Model using Bandit AI Algorithms
  • 18. SHIFT TRAFFIC TO MINIMIZE COST § Real-Time Cost Per Prediction § Across Clouds + On-Premise § Bandit-Based Explore/Exploit
  • 19. VIEW LIVE PREDICTION STREAMS § Visually Compare Real-Time Predictions
  • 20. CONTINUOUS MODEL TRAINING § Identify and Fix Borderline Predictions (50-50% Confidence) § Fix Along Class Boundaries § Retrain on New Labeled Data § Enables Crowd Sourcing § Game-ify Labeling Process
  • 21. AGENDA § PipelineAI Features § Experiment Safely in Production § Tune Both Model + Runtime Parameters § Compare Models Both Offline + Online § Shift Traffic (Across Clouds) to Winning Model § Optimize TensorFlow Training § GPUs + Ingestion + Training Pipeline § XLA JIT Compiler § Optimize TensorFlow Inference § XLA AOT Compiler + Graph Transform Tool (GTT) § TensorFlow Serving
  • 22. SETTING UP TENSORFLOW WITH GPUS § Very Painful! § Especially inside Docker § Use nvidia-docker § Especially on Kubernetes! § Use Kubernetes 1.7+ § http://pipeline.ai for GitHub + DockerHub Links
  • 23. GPU HALF-PRECISION SUPPORT § FP32 is “Full Precision”, FP16 is “Half Precision” § Supported by Pascal P100 (2016) and Volta V100 (2017) § Flexible FP32 GPU Cores Can Fit 2 FP16’s for 2x Throughput! § Half-Precision is OK for Approximate Deep Learning Use Cases
  • 24. VOLTA V100 RECENTLY ANNOUNCED § 84 Streaming Multiprocessors (SM’s) § 5,376 GPU Cores § 672 Tensor Cores (ie. Google TPU) § Mixed FP16/FP32 Precision § More Shared Memory § New L0 Instruction Cache § Faster L1 Data Cache § V100 vs. P100 Performance § 12x TFLOPS @ Peak Training § 6x Inference Throughput
  • 25. V100 AND CUDA 9 § Independent Thread Scheduling - Finally!! § Similar to CPU fine-grained thread synchronization semantics § Allows GPU to yield execution of any thread § Still Optimized for SIMT (Same Instruction Multiple Thread) § SIMT units automatically scheduled together § Explicit Thread Synchronization P100 V100
  • 26. GPU CUDA PROGRAMMING § Barbaric, But Fun Barbaric § Must Know Hardware Very Well § Hardware Changes are Painful § Many Great Debuggers Exist
  • 27. CUDA STREAMS § Asynchronous I/O Transfer § Overlap Compute and I/O § Keeps GPUs Saturated § Fundamental to Queue Framework in TensorFlow
  • 28. TRAINING TERMINOLOGY § Tensors: N-Dimensional Arrays § ie. Scalar, Vector, Matrix § Operations: MatMul, Add, SummaryLog,… § Graph: Graph of Operations (DAG) § Session: Contains Graph(s) § Feeds: Feed inputs into Placeholder § Fetches: Fetch output from Operation § Variables: What we learn through training § aka “weights”, “parameters” § Devices: Hardware device on which we train -TensorFlow- Trains Variables -User- Fetches Outputs -User- Feeds Inputs -TensorFlow- Performs Operations -TensorFlow- Flows Tensors with tf.device(“/gpu:0,/gpu:1”)
  • 29. TENSORFLOW MODEL § MetaGraph § Combines GraphDef and Metadata § GraphDef § Architecture of your model (nodes, edges) § Metadata § Asset: Accompanying assets to your model § SignatureDef: Maps external : internal tensors § Variables § Stored separately during training (checkpoint) § Allows training to continue from any checkpoint § Variables are “frozen” into Constants when deployed for inference GraphDef x W mul add b MetaGraph Metadata Assets SignatureDef Tags Version Variables: “W” : 0.328 “b” : -1.407
  • 30. TENSORFLOW SESSION Session graph: GraphDef Variables: “W” : 0.328 “b” : -1.407 Variables are Periodically Checkpointed GraphDef is Static
  • 31. EXTEND EXISTING DATA PIPELINES § Data Processing § HDFS/Hadoop § Spark § Containers § Docker § Google Container § Container Orchestrators § Kubernetes § Mesos <dependency> <groupId>org.tensorflow</groupId> <artifactId>tensorflow-hadoop</artifactId> </dependency> https://github.com/tensorflow/ecosystem
  • 32. DON’T USE FEED_DICT § Not Optimized for Production Pipelines § feed_dict Requires Python <-> C++ Serialization § Single-threaded, Synchronous, SLOW! § Can’t Retrieve Until Current Batch is Complete § CPUs/GPUs Not Fully Utilized! § Use Queue or Dataset API
  • 33. QUEUES § More than just a traditional Queue § Perform I/O, pre-processing, cropping, shuffling § Pulls from HDFS, S3, Google Storage, Kafka, ... § Combine many small files into large TFRecord files § Use CPUs to free GPUs for compute § Uses CUDA Streams § Helps saturate CPUs and GPUs
  • 34. QUEUE CAPACITY PLANNING § batch_size § # examples / batch (ie. 64 jpg) § Limited by GPU RAM § num_processing_threads § CPU threads pull and pre-process batches of data § Limited by CPU Cores § queue_capacity § Limited by CPU RAM (ie. 5 * batch_size)
  • 35. DETECT UNDERUTILIZED CPUS, GPUS § Instrument training code to generate “timelines” § Analyze with Google Web Tracing Framework (WTF) § Monitor CPU with `top`, GPU with `nvidia-smi` http://google.github.io/tracing-framework/ from tensorflow.python.client import timeline trace = timeline.Timeline(step_stats=run_metadata.step_stats) with open('timeline.json', 'w') as trace_file: trace_file.write( trace.generate_chrome_trace_format(show_memory=True))
  • 36. SINGLE NODE, MULTI-GPU TRAINING § cpu:0 § By default, all CPUs § Requires extra config to target a CPU § gpu:0..n § Each GPU has a unique id § TF usually prefers a single GPU § xla_cpu:0, xla_gpu:0..n § “JIT Compiler Device” § Hints TensorFlow to attempt JIT Compile with tf.device(“/cpu:0”): with tf.device(“/gpu:0”): with tf.device(“/gpu:1”): GPU 0 GPU 1
  • 37. MULTI-NODE DISTRIBUTED TRAINING § TensorFlow Automatically Inserts Send and Receive Ops into Graph § Parameter Server Synchronously Aggregates Updates to Variables § Nodes with Multiple GPUs will Pre-Aggregate Before Sending to PS Worker0 Worker0 Worker1 Worker0 Worker1 Worker2 gpu0 gpu1 gpu2 gpu3 gpu0 gpu1 gpu2 gpu3 gpu0 gpu1 gpu2 gpu3 gpu0 gpu1 gpu0 gpu0
  • 38. SYNCHRONOUS VS. ASYNCHRONOUS § Synchronous § Nodes compute gradients § Nodes update Parameter Server (PS) § Nodes sync on PS for latest gradients § Asynchronous § Some nodes delay in computing gradients § Nodes don’t update PS § Nodes get stale gradients from PS § May not converge due to stale reads!
  • 39. BATCH NORMALIZATION § Each mini-batch may have wildly different distributions § Normalize per batch (and layer) § Speeds up training!! § Weights are learned quicker § Final model is more accurate § Final mean and variance will be folded into Graph later -- Pretty Much Always Use Batch Normalization! -- z = tf.matmul(a_prev, W) a = tf.nn.relu(z) a_mean, a_var = tf.nn.moments(a, [0]) scale = tf.Variable(tf.ones([depth/channels])) beta = tf.Variable(tf.zeros ([depth/channels])) bn = tf.nn.batch_normalizaton(a, a_mean, a_var, beta, scale, 0.001)
  • 40. OPTIMIZE GRAPH EXECUTION ORDER § https://github.com/yaroslavvb/stuff Linearize to minimize graph memory usage
  • 41. SEPARATE TRAINING + VALIDATION § Separate Training and Validation Clusters § Validate Upon Checkpoint § Avoids Resource Contention Training Cluster Validation Cluster Parameter Server Cluster
  • 42. AGENDA § PipelineAI Features § Experiment Safely in Production § Tune Both Model + Runtime Parameters § Compare Models Both Offline + Online § Shift Traffic (Across Clouds) to Winning Model § Optimize TensorFlow Training § GPUs + Ingestion + Training Pipeline § XLA JIT Compiler § Optimize TensorFlow Inference § XLA AOT Compiler + Graph Transform Tool (GTT) § TensorFlow Serving
  • 43. XLA FRAMEWORK § Accelerated Linear Algebra (XLA) § Goals: § Reduce reliance on custom operators § Improve execution speed § Improve memory usage § Reduce mobile footprint § Improve portability § Helps TensorFlow Stay Both Flexible and Performant
  • 44. XLA HIGH LEVEL OPTIMIZER (HLO) § Compiler Intermediate Representation (IR) § Independent of Source and Target Language § Define Graphs using HLO Operations § XLA Step 1 Emits Target-Independent HLO § XLA Step 2 Emits Target-Dependent LLVM § LLVM Emits Native Code Specific to Target § Supports x86-64, ARM64 (CPU), and NVPTX (GPU)
  • 45. JIT COMPILER § Just-In-Time Compiler § Built on XLA Framework § Goals: § Reduce memory movement – especially useful on GPUs § Reduce overhead of multiple function calls § Similar to Spark Operator Fusing in Spark 2.0 § Unroll Loops, Fuse Operators, Fold Constants, … § Scope to session, device, or `with jit_scope():`
  • 46. VISUALIZING JIT COMPILER IN ACTION Before After Google Web Tracing Framework: http://google.github.io/tracing-framework/ from tensorflow.python.client import timeline trace = timeline.Timeline(step_stats=run_metadata.step_stats) with open('timeline.json', 'w') as trace_file: trace_file.write( trace.generate_chrome_trace_format(show_memory=True))
  • 47. VISUALIZING FUSING OPERATORS pip install graphviz dot -Tpng /tmp/hlo_graph_1.w5LcGs.dot -o hlo_graph_1.png GraphViz: http://www.graphviz.org hlo_*.dot files generated by XLA
  • 48. AGENDA § PipelineAI Features § Experiment Safely in Production § Tune Both Model + Runtime Parameters § Compare Models Both Offline + Online § Shift Traffic (Across Clouds) to Winning Model § Optimize TensorFlow Training § GPUs + Ingestion + Training Pipeline § XLA JIT Compiler § Optimize TensorFlow Inference § XLA AOT Compiler + Graph Transform Tool (GTT) § TensorFlow Serving
  • 49. AOT COMPILER § Standalone, Ahead-Of-Time (AOT) Compiler § Built on XLA framework § tfcompile § Creates executable with minimal TensorFlow Runtime needed § Includes only dependencies needed by subgraph computation § Creates functions with feeds (inputs) and fetches (outputs) § Packaged as cc_libary header and object files to link into your app § Commonly used for mobile device inference graph § Currently, only CPU x86-64 and ARM are supported - no GPU
  • 50. GRAPH TRANSFORM TOOL (GTT) § Optimize Trained Models for Inference § Remove training-only Ops (checkpoint, drop out, logs) § Remove unreachable nodes between given feed -> fetch § Fuse adjacent operators to improve memory bandwidth § Fold final batch norm mean and variance into variables § Round weights/variables improves compression (ie. 70%) § Quantize (FP32 -> INT8) to speed up math operations
  • 52. GRAPH TRANSFORM TOOL transform_graph --in_graph=tensorflow_inception_graph.pb ß Original Graph --out_graph=optimized_inception_graph.pb ß Transformed Graph --inputs='Mul' ß Feed (Input) --outputs='softmax' ß Fetch (Output) --transforms=' ß List of Transforms strip_unused_nodes remove_nodes(op=Identity, op=CheckNumerics) fold_constants(ignore_errors=true) fold_batch_norms fold_old_batch_norms quantize_weights quantize_nodes'
  • 53. AFTER STRIPPING UNUSED NODES § Optimizations § strip_unused_nodes § Results § Graph much simpler § File size much smaller
  • 54. AFTER REMOVING UNUSED NODES § Optimizations § strip_unused_nodes § remove_nodes § Results § Pesky nodes removed § File size a bit smaller
  • 55. AFTER FOLDING CONSTANTS § Optimizations § strip_unused_nodes § remove_nodes § fold_constants § Results § Placeholders (feeds) -> Variables* (*Why Variables and not Constants?)
  • 56. AFTER FOLDING BATCH NORMS § Optimizations § strip_unused_nodes § remove_nodes § fold_constants § fold_batch_norms § Results § Graph remains the same § File size approximately the same
  • 57. WEIGHT QUANTIZATION § FP16 and INT8 Are Computationally Simpler and Faster § Weights/Variables are Constants § Easy to Linearly Quantize
  • 58. AFTER QUANTIZING WEIGHTS § Optimizations § strip_unused_nodes § remove_nodes § fold_constants § fold_batch_norms § quantize_weights § Results § Graph is same, file size is smaller, compute is faster
  • 60. ACTIVATION QUANTIZATION § Activations Not Known Ahead of Time § Depends on input, not easy to quantize § Requires Additional Calibration Step § Use a “representative” dataset § Per Neural Network Layer… § Collect histogram of activation values § Generate many quantized distributions with different saturation thresholds § Choose threshold to minimize… KL_divergence(ref_distribution, quant_distribution) § Not Much Time or Data is Required (Minutes on Commodity Hardware)
  • 61. AFTER ACTIVATION QUANTIZATION § Optimizations § strip_unused_nodes § remove_nodes § fold_constants § fold_batch_norms § quantize_weights § quantize_nodes (activations) § Results § Larger graph, needs calibration! Requires additional freeze_requantization_ranges
  • 62. FREEZING MODEL FOR DEPLOYMENT § Optimizations § strip_unused_nodes § remove_nodes § fold_constants § fold_batch_norms § quantize_weights § quantize_nodes § freeze_graph § Results § Variables -> Constants Finally! We’re Ready to Deploy!!
  • 63. AGENDA § PipelineAI Features § Experiment Safely in Production § Tune Both Model + Runtime Parameters § Compare Models Both Offline + Online § Shift Traffic (Across Clouds) to Winning Model § Optimize TensorFlow Training § GPUs + Ingestion + Training Pipeline § XLA JIT Compiler § Optimize TensorFlow Inference § XLA AOT Compiler + Graph Transform Tool (GTT) § TensorFlow Serving
  • 64. TENSORFLOW SERVING OVERVIEW § Inference § Only Forward Propagation through Network § Predict, Classify, Regress, … § Bundle § GraphDef, Variables, Metadata, … § Assets § ie. Map of ClassificationID -> String § {9283: “penguin”, 9284: “bridge”} § Version § Every Model Has a Version Number (Integer) § Version Policy § ie. Serve Only Latest (Highest), Serve Both Latest and Previous, …
  • 65. MULTI-HEADED INFERENCE § Multiple “heads” (aka “responses”) from 1 model prediction § Optimizes bandwidth, CPU, latency, memory, coolness § Response includes both class and scores § Inputs sent only once § Feed scores into ensemble models § Use model for feature engineering
  • 66. REQUEST BATCHING § max_batch_size § Enables throughput/latency tradeoff § Bounded by RAM § batch_timeout_micros § Defines batch time window, latency upper-bound § Bounded by RAM § num_batch_threads § Defines parallelism § Bounded by CPU cores § max_enqueued_batches § Defines queue upper bound, throttling § Bounded by RAM Reaching either threshold will trigger a batch
  • 67. YOU JUST LEARNED… § PipelineAI Features § Experiment Safely in Production § Tune Both Model + Runtime Parameters § Compare Models Both Offline + Online § Shift Traffic (Across Clouds) to Winning Model § Optimize TensorFlow Training § GPUs + Ingestion + Training Pipeline § XLA JIT Compiler § Optimize TensorFlow Inference § XLA AOT Compiler + Graph Transform Tool (GTT) § TensorFlow Serving
  • 68. THANKS! ANY QUESTIONS? § https://github.com/PipelineAI/pipeline/ § Please 🌟 this GitHub Repo! § All slides, code, notebooks, and Docker images here: https://github.com/PipelineAI/pipeline/tree/master/gpu Contact Me chris@pipeline.ai @cfregly