我可以使用创建静态 for 循环
with dsl.ParallelFor([1,2,3]) as item:
....
我怎样才能使用container_op.output
作为输入ParallelFor
?
假设第一个容器输出一个整数n
,然后我想跑ParallelFor
n次。
像这样的尝试是行不通的:
container_op = ContainerOp(...)
with dsl.ParallelFor(container_op.output) as item:
....
我正在尝试刺激并行Pythonrange(n)
功能。
变更为支持withItem
(静态循环)和withParams
(动态循环)是分多个部分完成的,但现在它们都可用了。参考PR https://github.com/kubeflow/pipelines/pull/2044.
确保您的 KPF 版本是0.1.31
或以上。
可以循环前一个的输出container_op
如下
echo_op = dsl.ContainerOp(
name='echo',
image='library/bash:4.4.23',
command=['sh', '-c'],
arguments=['echo "[1,2,3]"> /tmp/output.txt'],
file_outputs={'output': '/tmp/output.txt'})
with dsl.ParallelFor(echo_op.output) as item:
iterate_op = dsl.ContainerOp(
name='iterate',
image='library/bash:4.4.23',
command=['sh', '-c'],
arguments=[f"echo {item} > /tmp/output.txt"],
file_outputs={'output': '/tmp/output.txt'})
确保您的输出 YAML 如下所示:
name: for-loop-for-loop-3c29048d-1
template: for-loop-for-loop-3c29048d-1
withParam: '{{tasks.echo.outputs.parameters.echo-output}}'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)