Skip to content

Commit

Permalink
sample pipeline notebook (kubeflow#476)
Browse files Browse the repository at this point in the history
* sample pipeline notebook

* addressing review comments
  • Loading branch information
animeshsingh authored and k8s-ci-robot committed Oct 25, 2019
1 parent 5ca79a9 commit 485814b
Showing 1 changed file with 183 additions and 0 deletions.
183 changes: 183 additions & 0 deletions docs/samples/pipelines/kfs-pipeline.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# KFServing Pipeline samples"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Install the necessary kfp library"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip3 install kfp --upgrade"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import kfp.dsl as dsl\n",
"import kfp\n",
"from kfp import components\n",
"import json\n",
"\n",
"# Create kfp client\n",
"# Note: Add the KubeFlow Pipeline endpoint below if the client is not running on the same cluster.\n",
"client = kfp.Client('kfserving_endpoint')\n",
"EXPERIMENT_NAME = 'KFServing Experiments'\n",
"experiment = client.create_experiment(name=EXPERIMENT_NAME)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### TensorFlow example\n",
"\n",
"Note: Change the action from `update` to `create` if you are deploying the model for the first time."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"kfserving_op = components.load_component_from_url('https://raw.githubusercontent.com/kubeflow/pipelines/master/components/kubeflow/kfserving/component.yaml')\n",
"\n",
"@dsl.pipeline(\n",
" name='kfserving pipeline',\n",
" description='A pipeline for kfserving.'\n",
")\n",
"def kfservingPipeline(\n",
" action = 'update',\n",
" model_name='tf-sample',\n",
" default_model_uri='gs://kfserving-samples/models/tensorflow/flowers',\n",
" canary_model_uri='gs://kfserving-samples/models/tensorflow/flowers-2',\n",
" canary_model_traffic_percentage='10',\n",
" namespace='your_namespace',\n",
" framework='tensorflow',\n",
" default_custom_model_spec='{}',\n",
" canary_custom_model_spec='{}',\n",
" autoscaling_target='0',\n",
" kfserving_endpoint=''\n",
"):\n",
"\n",
" # define workflow\n",
" kfserving = kfserving_op(action = action,\n",
" model_name=model_name,\n",
" default_model_uri=default_model_uri,\n",
" canary_model_uri=canary_model_uri,\n",
" canary_model_traffic_percentage=canary_model_traffic_percentage,\n",
" namespace=namespace,\n",
" framework=framework,\n",
" default_custom_model_spec=default_custom_model_spec,\n",
" canary_custom_model_spec=canary_custom_model_spec,\n",
" autoscaling_target=autoscaling_target,\n",
" kfserving_endpoint=kfserving_endpoint).set_image_pull_policy('Always')\n",
"\n",
"# Compile pipeline\n",
"import kfp.compiler as compiler\n",
"compiler.Compiler().compile(kfservingPipeline, 'tf-flower.tar.gz')\n",
"\n",
"# Execute pipeline\n",
"run = client.run_pipeline(experiment.id, 'tf-flower', 'tf-flower.tar.gz')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Custom model example"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"kfserving_op = components.load_component_from_url('https://raw.githubusercontent.com/kubeflow/pipelines/master/components/kubeflow/kfserving/component.yaml')\n",
"\n",
"@dsl.pipeline(\n",
" name='kfserving pipeline',\n",
" description='A pipeline for kfserving.'\n",
")\n",
"def kfservingPipeline(\n",
" action = 'update',\n",
" model_name='custom-sample',\n",
" default_model_uri='',\n",
" canary_model_uri='',\n",
" canary_model_traffic_percentage='0',\n",
" namespace='kubeflow',\n",
" framework='custom',\n",
" default_custom_model_spec='{\"name\": \"image-segmenter\", \"image\": \"codait/max-image-segmenter:latest\", \"port\": \"5000\"}',\n",
" canary_custom_model_spec='{}',\n",
" autoscaling_target='0',\n",
" kfserving_endpoint=''\n",
"):\n",
"\n",
" # define workflow\n",
" kfserving = kfserving_op(action = action,\n",
" model_name=model_name,\n",
" default_model_uri=default_model_uri,\n",
" canary_model_uri=canary_model_uri,\n",
" canary_model_traffic_percentage=canary_model_traffic_percentage,\n",
" namespace=namespace,\n",
" framework=framework,\n",
" default_custom_model_spec=default_custom_model_spec,\n",
" canary_custom_model_spec=canary_custom_model_spec,\n",
" autoscaling_target=autoscaling_target,\n",
" kfserving_endpoint=kfserving_endpoint).set_image_pull_policy('Always')\n",
"\n",
"# Compile pipeline\n",
"import kfp.compiler as compiler\n",
"compiler.Compiler().compile(kfservingPipeline, 'custom.tar.gz')\n",
"\n",
"# Execute pipeline\n",
"run = client.run_pipeline(experiment.id, 'custom-model', 'custom.tar.gz')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 485814b

Please sign in to comment.