Skip to content

Commit

Permalink
Merge pull request kubeflow#1035 from kbthu/master
Browse files Browse the repository at this point in the history
Update demo of mnist on kfp version 1.8.19
  • Loading branch information
js-ts authored May 23, 2023
2 parents 22dfca6 + 05e507a commit dcced9d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pipelines-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# pipelines-demo on Kubeflow/examples

This pipelines-demo contains many examples.

* mnist
* create a volume 'mnist-model' on Kubeflow UI
* compile yaml: python mnist/mnist-example.py
* load mnist-example.py.yaml on Kubeflow UI pipelines
57 changes: 57 additions & 0 deletions pipelines-demo/mnist/mnist-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2023 kbthu. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import kfp
from kfp import dsl

def mnist_train():
cop = dsl.ContainerOp(
name='mnist_train',
image='kbthu/tf-mnist-example:1.0.1',
command=['python3'],
arguments=['/mnist/mnist-train.py'],
file_outputs={'output': '/model/model.keras'},
)
cop.container.set_image_pull_policy('IfNotPresent')
cop.add_pvolumes({'/model': dsl.PipelineVolume(pvc='mnist-model')})
return cop


def mnist_test(model):
cop = dsl.ContainerOp(
name='mnist_test',
image='kbthu/tf-mnist-example:1.0.1',
command=['python3'],
arguments=['/mnist/mnist-test.py'],
)
cop.container.set_image_pull_policy('IfNotPresent')
cop.add_pvolumes({'/model': dsl.PipelineVolume(pvc='mnist-model')})
return cop


@dsl.pipeline(
name='Kubeflow pipeline example',
description='Demonstrate the Kubeflow pipeline with Mnist training'
)
def kfp_example():
_train_op = mnist_train()

mnist_test(
dsl.InputArgumentPath(_train_op.outputs['output'])
).after(_train_op)


if __name__ == '__main__':
import kfp.compiler as compiler
compiler.Compiler().compile(kfp_example, __file__ + '.yaml')

0 comments on commit dcced9d

Please sign in to comment.