首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有一个Python模块/(函数)可以设置dsl ContainerOp (Kubeflow管道)的CPU数量?

有没有一个Python模块/(函数)可以设置dsl ContainerOp (Kubeflow管道)的CPU数量?
EN

Stack Overflow用户
提问于 2019-08-28 05:24:37
回答 1查看 516关注 0票数 0

我构建了一个Jupyter notebook,它将Jupyter notebook作为管道的一个组件部署到Kubeflow管道服务中。我想知道是否有一种方法可以为部署笔记本的ContainerOp指定CPU和内存的数量。

目标:当我打开并读取tar.gz文件的内容时,让cpu和mem作为参数显示在yaml文件中。

我试过使用多处理库,但我发布的代码示例(隐藏的路径和图像)看起来太愚蠢了,以至于不正确。另外,这也不是我老板想要的

代码语言:javascript
复制
    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数量

EN

回答 1

Stack Overflow用户

发布于 2019-10-10 10:30:23

您可以在编译时通过ContainerOp对象直接对pod应用cpu和内存限制:

代码语言:javascript
复制
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中:

代码语言:javascript
复制
- container:
      .....
      resources:
        limits:
          cpu: '4.0'
          memory: 4Gi
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57682453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档