TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model...

129
TensorFlow Extended (TFX) An End-to-End ML Platform Clemens Mewald

Transcript of TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model...

Page 1: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

TensorFlow Extended (TFX)An End-to-End ML Platform

Clemens Mewald

Page 2: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Figure 1: High-level component overview of a machine learning platform.

Data Ingestion

Data Analysis + Validation

Data Transformation Trainer Model Evaluation

and Validation Serving Logging

Shared Utilities for Garbage Collection, Data Access Controls

Pipeline Storage

Tuner

Shared Configuration Framework and Job Orchestration

Integrated Frontend for Job Management, Monitoring, Debugging, Data/Model/Evaluation Visualization

TensorFlow Extended (TFX): An End-to-End ML Platform

Page 3: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

TFX powers our most important bets and products...

(incl. )

Major ProductsAlphaBets

Page 4: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Figure 1: High-level component overview of a machine learning platform.

Data Ingestion

TensorFlow Data Validation

TensorFlow Transform

Estimator or Keras Model

TensorFlow Model Analysis

TensorFlow Serving Logging

Shared Utilities for Garbage Collection, Data Access Controls

Pipeline Storage

Tuner

Shared Configuration Framework and Job Orchestration

Integrated Frontend for Job Management, Monitoring, Debugging, Data/Model/Evaluation Visualization

So far, we’ve made some of our libraries available.

Page 5: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

… and some of our most important partners.

Page 6: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Figure 1: High-level component overview of a machine learning platform.

Data Ingestion

TensorFlow Data Validation

TensorFlow Transform

Estimator or Keras Model

TensorFlow Model Analysis

TensorFlow Serving Logging

Shared Utilities for Garbage Collection, Data Access Controls

Pipeline Storage

Tuner

Shared Configuration Framework and Job Orchestration

Integrated Frontend for Job Management, Monitoring, Debugging, Data/Model/Evaluation Visualization

So far, we’ve made some of our libraries available.

Page 7: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Figure 1: High-level component overview of a machine learning platform.

Data Ingestion

TensorFlow Data Validation

TensorFlow Transform

Estimator or Keras Model

TensorFlow Model Analysis

TensorFlow Serving Logging

Shared Utilities for Garbage Collection, Data Access Controls

Pipeline Storage

Tuner

Shared Configuration Framework and Job Orchestration

Integrated Frontend for Job Management, Monitoring, Debugging, Data/Model/Evaluation Visualization

Today, we share the horizontal layers that integrate libraries in one product.

Page 8: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Building Components out of Libraries

Data Ingestion TensorFlow Transform

Estimator or Keras Model

TensorFlow Model Analysis

Honoring Validation Outcomes

TensorFlow Data Validation

TensorFlow Serving

ExampleGen

StatisticsGen

SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator

Pusher Model Server

Page 9: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

What makes a Component

ModelValidator

Packaged binary or container

Page 10: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

What makes a Component

Last Validated Model

New (Candidate) Model

ModelValidator

Validation Outcome

Well defined inputs and outputs

Page 11: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

What makes a Component

Config

Last Validated Model

New (Candidate) Model

ModelValidator

Validation Outcome

Well definedconfiguration

Page 12: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Metadata Store

What makes a Component

Config

Last Validated Model

New (Candidate) Model

ModelValidator

Validation Outcome

Context

Page 13: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Metadata Store

What makes a Component

Trainer

Config

Last Validated Model

New (Candidate) Model

New ModelModel

Validator

Validation Outcome

Pusher

New (Candidate) Model

Validation Outcome

TensorFlow Serving

Page 14: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Metadata Store? That’s new

Page 15: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Trainer

Metadata Store? That’s new

Task-Aware Pipelines

Transform

Page 16: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Trainer

Metadata Store? That’s new

Task-Aware Pipelines

Input DataTransformed

DataTrained Models

Serving System

Task- and Data-Aware Pipelines

Pipeline + Metadata Storage

Training Data

Transform TrainerTransform

Page 17: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

What’s in the Metadata Store?

Trained Models

Type definitions of Artifacts and their PropertiesE.g., Models, Data, Evaluation Metrics

Page 18: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

What’s in the Metadata Store?

Trained Models

Type definitions of Artifacts and their PropertiesE.g., Models, Data, Evaluation Metrics

Trainer Execution Records (Runs) of ComponentsE.g., Runtime Configuration, Inputs + Outputs

Page 19: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

What’s in the Metadata Store?

Trained Models

Type definitions of Artifacts and their PropertiesE.g., Models, Data, Evaluation Metrics

Trainer Execution Records (Runs) of ComponentsE.g., Runtime Configuration, Inputs + Outputs

Lineage Tracking Across All ExecutionsE.g., to recurse back to all inputs of a specific artifact

Page 20: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

List all training runs and attributes

Page 21: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Visualize lineage of a specific model

Model artifact that was created

Page 22: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Visualize data a model was trained on

Page 23: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Visualize sliced eval metrics associated with a model

Page 24: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Launch TensorBoard for a specific model run

Page 25: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Launch TensorBoard to compare multiple model runs

Page 26: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Compare data statistics for multiple models

Page 27: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Examples of Metadata-Powered Functionality

Use-cases enabled by lineage tracking

Page 28: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Examples of Metadata-Powered Functionality

Use-cases enabled by lineage tracking Compare previous model runs

Page 29: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Examples of Metadata-Powered Functionality

Use-cases enabled by lineage tracking Compare previous model runs

Carry-over state from previous models

Page 30: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Examples of Metadata-Powered Functionality

Use-cases enabled by lineage tracking Compare previous model runs

Carry-over state from previous models Re-use previously computed outputs

Page 31: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

How do we orchestrate TFX?

Component

Legend

Page 32: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

How do we orchestrate TFX?

Component

Legend

Metadata StoreDriver and Publisher

Page 33: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

How do we orchestrate TFX?

Component

Executor

Legend

Metadata StoreDriver and Publisher

Page 34: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

How do we orchestrate TFX?TFX Config

Component

Executor

Legend

Metadata StoreDriver and Publisher

Page 35: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

def create_pipeline(): """Implements the chicago taxi pipeline with TFX.""" examples = csv_input(os.path.join(data_root, 'simple')) example_gen = CsvExampleGen(input_base=examples)

statistics_gen = StatisticsGen(input_data=...) infer_schema = SchemaGen(stats=...) validate_stats = ExampleValidator(stats=..., schema=...) transform = Transform(input_data=..., schema=..., module_file=...)

trainer = Trainer( module_file=taxi_module_file, transformed_examples=transform.outputs.transformed_examples, transform_output=transform.outputs.transform_output, schema=infer_schema.outputs.output, train_steps=10000, eval_steps=5000, warm_starting=True)

model_analyzer = Evaluator(examples=..., model_exports=...) model_validator = ModelValidator(examples=..., model=...) pusher = Pusher(model_export=..., model_blessing=..., serving_model_dir=...) return [example_gen, statistics_gen, infer_schema, validate_stats, transform, trainer, model_analyzer, model_validator, pusher]

pipeline = TfxRunner(airflow_config).run(create_pipeline())

Page 36: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

def train_and_maybe_evaluate(hparams): schema = taxi.read_schema(hparams.schema_file)

train_input = lambda: model.input_fn(...) eval_input = lambda: model.input_fn(...) serving_receiver_fn = lambda: model.example_serving_receiver_fn(...)

train_spec = tf.estimator.TrainSpec(...) eval_spec = tf.estimator.EvalSpec(...)

exporter = tf.estimator.FinalExporter('chicago-taxi', serving_receiver_fn)

run_config = tf.estimator.RunConfig( save_checkpoints_steps=999, keep_checkpoint_max=1)

estimator = model.build_estimator(...)

tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)

return estimator

Page 37: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

def build_estimator(tf_transform_dir, config, hidden_units=None):

# receive Schema and Transform metadata metadata_dir = os.path.join(tf_transform_dir, transform_fn_io.TRANSFORMED_METADATA_DIR) transformed_metadata = metadata_io.read_metadata(metadata_dir) transformed_feature_spec = transformed_metadata.schema.as_feature_spec()

transformed_feature_spec.pop(taxi.transformed_name(taxi.LABEL_KEY))

real_valued_columns = [...] categorical_columns = [...] return tf.estimator.DNNLinearCombinedClassifier( config=config, linear_feature_columns=categorical_columns, dnn_feature_columns=real_valued_columns, dnn_hidden_units=hidden_units or [100, 70, 50, 25])

Page 38: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

How do we orchestrate TFX?TFX Config

Component

Executor

Legend

Metadata StoreDriver and Publisher

Page 39: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Your own runtime ...Kubeflow Runtime

Bring your very own favorite orchestrator

Metadata Store

Component

Driver and Publisher

Executor

Legend

Airflow Runtime

TFX Config

Page 40: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Examples of orchestrated TFX pipelines

Airflow Kubeflow Pipelines

Page 41: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

TFX: Putting it all together.

Airflow Runtime

Page 42: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Get started with TensorFlow Extended (TFX)An End-to-End ML Platform

github.com/tensorflow/tfx

tensorflow.org/tfx

Page 43: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

TFX End-to-End ExampleChicago Taxi Cab Dataset

Page 44: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

TFX End-to-End Example

Categorical Features

trip_start_hour

trip_start_day

trip_start_month

pickup/dropoff_census_tract

pickup/dropoff_community_area

Dense Float Features

trip_miles

fare

trip_seconds

Bucket Features

pickup_latitude

pickup_longitude

dropoff_latitude

dropoff_longitude

Vocab Features

payment_type

company

Chicago Taxi Cab Dataset

Features

Label = tips > (fare * 20%)

Page 45: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

TFX End-to-End ExampleChicago Taxi Cab Dataset

string_to_int bucketize scale_to_z_score

Features

Transforms

Label = tips > (fare * 20%)

Categorical Features

trip_start_hour

trip_start_day

trip_start_month

pickup/dropoff_census_tract

pickup/dropoff_community_area

Dense Float Features

trip_miles

fare

trip_seconds

Bucket Features

pickup_latitude

pickup_longitude

dropoff_latitude

dropoff_longitude

Vocab Features

payment_type

company

Page 46: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

TFX End-to-End ExampleChicago Taxi Cab Dataset

string_to_int bucketize scale_to_z_score

Features

Transforms

Model (Wide+Deep)

Label = tips > (fare * 20%)

Categorical Features

trip_start_hour

trip_start_day

trip_start_month

pickup/dropoff_census_tract

pickup/dropoff_community_area

Dense Float Features

trip_miles

fare

trip_seconds

Bucket Features

pickup_latitude

pickup_longitude

dropoff_latitude

dropoff_longitude

Vocab Features

payment_type

company

Page 47: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

TFX End-to-End ExampleChicago Taxi Cab Dataset

string_to_int bucketize scale_to_z_score

Features

Transforms

Model(Wide+Deep)

Label = tips > (fare * 20%)

Categorical Features

trip_start_hour

trip_start_day

trip_start_month

pickup/dropoff_census_tract

pickup/dropoff_community_area

Dense Float Features

trip_miles

fare

trip_seconds

Bucket Features

pickup_latitude

pickup_longitude

dropoff_latitude

dropoff_longitude

Vocab Features

payment_type

company

Page 48: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Data Validation and Transformation

Clemens Mewald

Page 49: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Overview

Airflow Runtime

Data Ingestion Data Transformation

Data Analysis & Validation

Page 50: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

ExampleGen

Airflow Runtime

Page 51: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: ExampleGen

ExampleGen

Raw Data

Inputs and Outputs

CSV TF Record

Split TF Record

Data

Training

Eval

Page 52: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: ExampleGen

examples = csv_input(os.path.join(data_root, 'simple'))

example_gen = CsvExampleGen(input_base=examples)

Configuration

ExampleGen

Raw Data

Inputs and Outputs

CSV TF Record

Split TF Record

Data

Training

Eval

Page 53: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Data Analysis & Validation

Airflow Runtime

Data Analysis & Validation

Page 54: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why Data Validation is important

ML

Page 55: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why Data Validation is important

garbage in garbage out

ML

Page 56: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why Data Validation is important

Data understanding is important for model understanding

“Why are my tip predictions bad in the morning hours?”

Page 57: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why Data Validation is important

Data understanding is important for model understanding

“What are expected values for payment types?”

Treat data as you treat code

Page 58: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why Data Validation is important

Data understanding is important for model understanding

“Is this new taxi company name a typo or a new company?”

Treat data as you treat code

Catching errors early is critical

Page 59: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

StatisticsGen

Airflow Runtime

Page 60: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: StatisticsGen

StatisticsGen

Data

ExampleGen

Inputs and Outputs

Statistics

● Training● Eval● Serving logs (for skew detection)

Page 61: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: StatisticsGen

StatisticsGen

Data

ExampleGen

Inputs and Outputs

Statistics

● Captures shape of data● Visualization highlights unusual stats● Overlay helps with comparison

Page 62: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: StatisticsGen

statistics_gen = StatisticsGen(input_data=example_gen.outputs.examples)

Configuration

Visualization

StatisticsGen

Data

ExampleGen

Inputs and Outputs

Statistics

Page 63: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why are my tip predictions bad in the morning hours?

Page 64: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

SchemaGen

Airflow Runtime

Page 65: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: SchemaGen

SchemaGen

Statistics

StatisticsGen

Inputs and Outputs

Schema

● High-level description of the data○ Expected features○ Expected value domains○ Expected constraints○ and much more!

● Codifies expectations of “good” data● Initially inferred, then user-curated

Page 66: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: SchemaGen

SchemaGen

Statistics

StatisticsGen

Inputs and Outputs

Schema

infer_schema = SchemaGen(stats=statistics_gen.outputs.output)

Configuration

Visualization

Page 67: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

What are expected values for payment types?

Page 68: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

ExampleValidator

Airflow Runtime

Page 69: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: ExampleValidator

ExampleValidator

Statistics Schema

StatisticsGen SchemaGen

Inputs and Outputs

Anomalies Report

● Missing features● Wrong feature valency● Training/serving skew● Data distribution drift● ...

Page 70: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: ExampleValidator

ExampleValidator

Statistics Schema

StatisticsGen SchemaGen

Inputs and Outputs

Anomalies Report

validate_stats = ExampleValidator( stats=statistics_gen.outputs.output, schema=infer_schema.outputs.output)

Configuration

Visualization

Page 71: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Is this new taxi company name a typo or a new company?

Page 72: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Transform

Airflow Runtime

Page 73: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Recap: End-to-End ExampleChicago Taxi Cab Dataset

string_to_int bucketize scale_to_z_score

Features

Transforms

Model(Wide+Deep)

Label = tips > (fare * 20%)

Categorical Features

trip_start_hour

trip_start_day

trip_start_month

pickup/dropoff_census_tract

pickup/dropoff_community_area

Dense Float Features

trip_miles

fare

trip_seconds

Bucket Features

pickup_latitude

pickup_longitude

dropoff_latitude

dropoff_longitude

Vocab Features

payment_type

company

Page 74: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Using tf.Transform for feature transformations.

Page 75: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Using tf.Transform for feature transformations.

Page 76: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Using tf.Transform for feature transformations.

Training Serving

Page 77: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: Transform

Transform

Data Schema

Transform Graph

Transformed Data

ExampleGen SchemaGen

Trainer

Inputs and Outputs

● User-provided transform code (TF Transform)● Schema for parsing

Code

Page 78: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: Transform

Transform

Data Schema

Transform Graph

Transformed Data

ExampleGen SchemaGen

Trainer

Inputs and Outputs

Transform Graph● Applied at training time● Embedded in serving graph

(Optional) Transformed Data● For performance optimization

Code

Page 79: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: Transform

transform = Transform( input_data=example_gen.outputs.examples, schema=infer_schema.outputs.output, module_file=taxi_module_file)

Configuration

for key in _DENSE_FLOAT_FEATURE_KEYS: outputs[_transformed_name(key)] = transform.scale_to_z_score( _fill_in_missing(inputs[key]))# ...

outputs[_transformed_name(_LABEL_KEY)] = tf.where( tf.is_nan(taxi_fare), tf.cast(tf.zeros_like(taxi_fare), tf.int64), # Test if the tip was > 20% of the fare. tf.cast( tf.greater(tips, tf.multiply(taxi_fare, tf.constant(0.2))), tf.int64))

# ...

CodeTransform

Data Schema

Transform Graph

Transformed Data

ExampleGen SchemaGen

Trainer

Inputs and Outputs

Code

Page 80: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

def preprocessing_fn(inputs): ... for key in taxi.DENSE_FLOAT_FEATURE_KEYS: outputs[key] = transform.scale_to_z_score(inputs[key])

for key in taxi.VOCAB_FEATURE_KEYS: outputs[key] = transform.string_to_int(inputs[key], top_k=taxi.VOCAB_SIZE, num_oov_buckets=taxi.OOV_SIZE)

for key in taxi.BUCKET_FEATURE_KEYS: outputs[key] = transform.bucketize(inputs[key], taxi.FEATURE_BUCKET_COUNT) ...

Page 81: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Overview

Airflow Runtime

Data Ingestion Data Transformation

Data Analysis & Validation

Page 82: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Training

Clemens Mewald

Page 83: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Trainer

Airflow Runtime

Page 84: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: Trainer

Trainer

Data Schema

Transform SchemaGen

Evaluator

Inputs and Outputs

Code

Transform Graph

Model Validator Pusher

Model(s)

● User-provided training code (TensorFlow)● Optionally, transformed data

Page 85: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: Trainer

Trainer

Data Schema

Transform SchemaGen

Evaluator

Inputs and Outputs

Code

Transform Graph

Model Validator Pusher

Highlight: SavedModel Format

TensorFlow Serving

TensorFlow Model Analysis

Train, Eval, and Inference Graphs

SignatureDefEval Metadata

SignatureDefModel(s)

Page 86: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: Trainer

trainer = Trainer( module_file=taxi_module_file, transformed_examples=transform.outputs.transformed_examples, schema=infer_schema.outputs.output, transform_output=transform.outputs.transform_output, train_steps=10000, eval_steps=5000, warm_starting=True)

Configuration

Code: Just TensorFlow :)

Trainer

Data Schema

Transform SchemaGen

Evaluator

Inputs and Outputs

Code

Transform Graph

Model Validator Pusher

Model(s)

Page 87: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

def train_and_maybe_evaluate(hparams): schema = taxi.read_schema(hparams.schema_file)

train_input = lambda: model.input_fn(...) eval_input = lambda: model.input_fn(...) serving_receiver_fn = lambda: model.example_serving_receiver_fn(...)

train_spec = tf.estimator.TrainSpec(...) eval_spec = tf.estimator.EvalSpec(...)

exporter = tf.estimator.FinalExporter('chicago-taxi', serving_receiver_fn)

run_config = tf.estimator.RunConfig( save_checkpoints_steps=999, keep_checkpoint_max=1)

estimator = model.build_estimator(...)

tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)

return estimator

Page 88: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

def build_estimator(tf_transform_dir, config, hidden_units=None):

# receive Schema and Transform metadata metadata_dir = os.path.join(tf_transform_dir, transform_fn_io.TRANSFORMED_METADATA_DIR) transformed_metadata = metadata_io.read_metadata(metadata_dir) transformed_feature_spec = transformed_metadata.schema.as_feature_spec()

transformed_feature_spec.pop(taxi.transformed_name(taxi.LABEL_KEY))

real_valued_columns = [...] categorical_columns = [...] return tf.estimator.DNNLinearCombinedClassifier( config=config, linear_feature_columns=categorical_columns, dnn_feature_columns=real_valued_columns, dnn_hidden_units=hidden_units or [100, 70, 50, 25])

Page 89: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(), tf.keras.layers.Dense(512, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation='softmax')])model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)model.evaluate(x_test, y_test)

Keras: TF 2.0

Page 90: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

model = tf.keras.models.Sequential([

tf.keras.layers.Dense(64, input_shape=[10]),

tf.keras.layers.Dense(64, activation='relu'),

tf.keras.layers.Dense(10, activation='softmax')])

model.compile(optimizer='adam',

loss='categorical_crossentropy',

metrics=['accuracy'])

Going big: tf.distribute.Strategy

Page 91: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

strategy = tf.distribute.MirroredStrategy()

with strategy.scope():

model = tf.keras.models.Sequential([

tf.keras.layers.Dense(64, input_shape=[10]),

tf.keras.layers.Dense(64, activation='relu'),

tf.keras.layers.Dense(10, activation='softmax')])

model.compile(optimizer='adam',

loss='categorical_crossentropy',

metrics=['accuracy'])

Going big: Multi-GPU

Page 92: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy()

with strategy.scope():

model = tf.keras.models.Sequential([

tf.keras.layers.Dense(64, input_shape=[10]),

tf.keras.layers.Dense(64, activation='relu'),

tf.keras.layers.Dense(10, activation='softmax')])

model.compile(optimizer='adam',

loss='categorical_crossentropy',

metrics=['accuracy'])

Coming soon: Multi-node synchronous

Page 93: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

saved_model_path = tf.keras.experimental.export_saved_model(

model, '/path/to/model')

new_model = tf.keras.experimental.load_from_saved_model(

saved_model_path)

new_model.summary()

To SavedModel and beyond

Page 94: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Model Evaluation and Analysis

Clemens Mewald

Page 95: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Model Analysis & Validation

Airflow Runtime

Page 96: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Evaluator

Airflow Runtime

Page 97: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why Model Evaluation is important

Assess overall model quality overall

“How well can I predict trips that result in tips > 20%?”

Page 98: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why Model Evaluation is important

Assess overall model quality overall

“Why are my tip predictions sometimes wrong?”

Assess model quality on specific segments / slices

Page 99: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why Model Evaluation is important

Assess overall model quality overall

“Am I getting better at predicting trips with tips > 20%?”

Assess model quality on specific segments / slices

Track performance over time

Page 100: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: Evaluator

Evaluator

Data Model

ExampleGen Trainer

Inputs and Outputs

Evaluation Metrics

● Evaluation split of data● Eval spec for slicing of metrics

Page 101: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: Evaluator

Evaluator

Data Model

ExampleGen Trainer

Inputs and Outputs

Evaluation Metrics

model_analyzer = Evaluator( examples=examples_gen.outputs.output, eval_spec=taxi_eval_spec, model_exports=trainer.outputs.output)

Configuration

Visualization

Page 102: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

How well can I predict trips that result in tips > 20%?

Page 103: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why are my tip predictions sometimes wrong?

Page 104: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Am I getting better at predicting trips with tips > 20%?

Page 105: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

ModelValidator

Airflow Runtime

Page 106: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why Model Validation is important

Avoid pushing models with degraded quality

“Why am I suddenly getting tipped less?”

Page 107: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Why Model Validation is important

Avoid pushing models with degraded quality.

“Why am I no longer getting recommendations for trips?”

Avoid breaking downstream components (e.g. serving)

Page 108: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: ModelValidator

Model Validator

Data

ExampleGen Trainer

Inputs and Outputs

Validation Outcome

Model (x2)

● Evaluation split of data● Last validated model● New candidate model

Page 109: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: ModelValidator

Model Validator

Data

ExampleGen Trainer

Inputs and Outputs

Validation Outcome

Model (x2)

model_validator = ModelValidator( examples=examples_gen.outputs.output, model=trainer.outputs.output, eval_spec=taxi_mv_spec)

Configuration

● Configuration options○ Validate using current eval data○ “Next-day eval”, validate using unseen data

Page 110: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Kubeflow Runtime

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Pusher

Airflow Runtime

Page 111: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: Pusher

Pusher

Validation Outcome

ModelValidator

Inputs and Outputs

PusherPusherDeployment

Options

Page 112: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Component: Pusher

Pusher

Validation Outcome

ModelValidator

Inputs and Outputs

PusherPusherDeployment

Options

pusher = Pusher( model_export=trainer.outputs.output, model_blessing=model_validator.outputs.blessing, serving_model_dir=serving_model_dir)

Configuration

● Block push on validation outcome

● Push destinations supported today○ Filesystem○ TF Serving model server

Page 113: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Model Deployment

Clemens Mewald

Page 114: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

This is where you are ...

$ curl -d '{"instances": [60, 27.05, ...]}' -X POST

http://localhost:8501/v1/models/chicago_taxi:predict

{ "results": [1.0] }

This is where you want to be ...

assets/

variables/

variables.data-*****-of-*****

variables.index

saved_model.pb

A Trained SavedModel

Page 115: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Deploy anywhere

JavaScriptEdge devicesServers

Serving Lite .JS

Page 116: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

TensorFlow ServingFlexible

Multi-tenancy

Optimize with GPU and TensorRT

gRPC or REST API

Page 117: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

TensorFlow ServingHigh-Performance

Low-latency

Request Batching

Traffic Isolation

Page 118: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

TensorFlow ServingProduction-Ready

Used for years at Google, millions of QPS

Scale in minutes

Dynamic version refresh

Page 119: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

$ apt-get install tensorflow-model-server

$ tensorflow_model_server

--port=8501

--model_name=chicago_taxi

--model_base_path='/path/to/savedmodel'

Deploy a REST API for your model in minutes ..

$ docker run -p 8501:8501 \

-v '/path/to/savedmodel':/models/chicago_taxi

-e MODEL_NAME=chicago_taxi -t tensorflow/serving

... or locally on

your host ...

... using Docker ...

Page 120: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Easily enable* hardware acceleration

$ docker run -p 8501:8501 \

-v '/path/to/savedmodel':/models/chicago_taxi

-e MODEL_NAME=chicago_taxi -t tensorflow/serving

$ docker run --runtime=nvidia -p 8501:8501 \

-v /path/to/savedmodel:/models/chicago_taxi

-e MODEL_NAME=chicago_taxi -t tensorflow/serving:latest-gpu

* Only possible if running on a host equipped with a GPU and nvidia-docker installed

Page 121: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Optimize your model for serving using TensorRT

$ saved_model_cli convert --dir '/path/to/savedmodel'

--output_dir '/path/to/trt-savedmodel' --tag_set serve tensorrt

$ docker run --runtime=nvidia -p 8501:8501 \

-v /path/to/trt-savedmodel:/models/chicago_taxi

-e MODEL_NAME=chicago_taxi -t tensorflow/serving:latest-gpu

Page 122: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform

Putting it all together again

Training + Eval Data

Page 123: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Putting it all together again

Training + Eval Data

Page 124: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator

Putting it all together again

Training + Eval Data

Page 125: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Putting it all together again

Training + Eval Data

Page 126: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Putting it all together again

Page 127: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Putting it all together again

Page 128: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

ExampleGen

StatisticsGen SchemaGen

ExampleValidator

Transform Trainer

Evaluator

ModelValidator Pusher

TFX Config

Metadata Store

Training + Eval Data

TensorFlow Serving

TensorFlow Hub

TensorFlow Lite

TensorFlow JS

Putting it all together again

Kubeflow RuntimeAirflow Runtime

Page 129: TensorFlow Extended (TFX) · TensorFlow Transform Estimator or Keras Model TensorFlow Model Analysis TensorFlow Serving Logging Shared Utilities for Garbage Collection, Data Access

Get started with TensorFlow Extended (TFX)An End-to-End ML Platform

github.com/tensorflow/tfx

tensorflow.org/tfx