我构建了一个Jupyter notebook,它将Jupyter notebook作为管道的一个组件部署到Kubeflow管道服务中。我想知道是否有一种方法可以为部署笔记本的ContainerOp指定CPU和内存的数量。
目标:当我打开并读取tar.gz文件的内容时,让cpu和mem作为参数显示在yaml文件中。
我试过使用多处理库,但我发布的代码示例(隐藏的路径和图像)看起来太愚蠢了,以至于不正确。另外,这也不是我老板想要的
import kfp
import random
import string
if not os.path.exists(tmp_dir):
os.makedirs(tmp_dir)
def demo_op(input_notebook, output_notebook, name):
return dsl.ContainerOp(
name='papermill',
image=image,
command=['sh', '-c'],
pvolumes={"/home/jovyan": dsl.PipelineVolume(pvc="efs-storage",name='efs-storage')},
arguments=['papermill $0 $1 -p name $2', input_notebook, output_notebook, name]
)
@dsl.pipeline(
name='papermill demo',
description='executing notebooks demo'
)
def pipeline_func(output_notebook,
name,
input_notebook='abcd'): #example of path
demo_task = demo_op(input_notebook, output_notebook, name)
filename = tmp_dir + '/demo{dt:%Y%m%d_%H%M%S}.pipeline.tar.gz'.format(dt=datetime.datetime.now())
compiler.Compiler().compile(pipeline_func, filename)
client = kfp.Client()
experiment = client.create_experiment('papermill_volume_test')
arguments = {'output_notebook': 'abcd', #example
'name': 'demo_test'} # Output_notebook prints: demo_test
run_name = 'papermill demo run'
run_result = client.run_pipeline(experiment.id, run_name, filename, arguments)
p = multiprocessing.Process(target=run_func, args=(tmp_dr,
image, inp_nb, out_np, mem))
processes.append(p)
p.start()
for d in processes:
d.join()这不会给出在yaml文件中使用的cpu数量
发布于 2019-10-10 10:30:23
您可以在编译时通过ContainerOp对象直接对pod应用cpu和内存限制:
demo_op.set_memory_limit('4G')
demo_op.set_cpu_limit('4.0')在使用demo_op(input_notebook, output_notebook, name)调用ContainerOp之前
下面是基于limit:link调用k8s资源的KFP SDK的链接
这也出现在编译后的Argo yaml中:
- container:
.....
resources:
limits:
cpu: '4.0'
memory: 4Gihttps://stackoverflow.com/questions/57682453
复制相似问题