You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kedro动态构建管道问题:无法获取CLI传入的参数值

Kedro 0.19.12 动态构建序列管道解决方案

1. 通过CLI传递参数

运行Kedro命令时,用--params指定ID参数:

# 执行A+B+C组合管道
kedro run --params ID:X

# 执行A+C组合管道
kedro run --params ID:Y

2. 在管道注册逻辑中动态拼接

修改项目根目录下src/<你的项目名>/pipelines/__init__.py中的register_pipelines函数,实现根据参数动态组合子管道:

from .pipelineA import create_pipeline as create_pipelineA
from .pipelineB import create_pipeline as create_pipelineB
from .pipelineC import create_pipeline as create_pipelineC
from kedro.framework.project import get_current_context
from kedro.pipeline import Pipeline
from typing import Dict

def register_pipelines(**kwargs) -> Dict[str, Pipeline]:
    # 获取Kedro上下文,读取CLI传入的参数
    context = get_current_context()
    target_id = context.params.get("ID", "")

    # 初始化各子管道实例
    pipeline_a = create_pipelineA()
    pipeline_b = create_pipelineB()
    pipeline_c = create_pipelineC()

    # 根据ID值拼接目标管道
    if target_id == "X":
        pipeline_to_run = pipeline_a + pipeline_b + pipeline_c
    elif target_id == "Y":
        pipeline_to_run = pipeline_a + pipeline_c
    else:
        # 自定义默认逻辑,示例为仅运行pipelineA
        pipeline_to_run = pipeline_a

    return {
        "__default__": pipeline_to_run
    }

3. 可选:配置默认参数

为避免参数未传入时出错,可在conf/base/parameters.yml中添加ID的默认值:

ID: ""

验证方式

执行命令前,可通过kedro run --dry-run预览将要执行的节点,确认管道拼接是否符合预期。

内容的提问来源于stack exchange,提问作者William

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 11:48:14