我可以使用
创建静态 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:
....
我正在尝试模拟并行 python range(n)
函数。
最佳答案
支持 withItem
(静态循环)和 withParams
(动态循环)的更改是分多个部分完成的,但它们现在都可用。请参阅PR .
确保您的 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}}'
关于python - kubeflow ParallelFor使用之前的containerop输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59249245/