修改神经网络epoch数后Kubeflow Pipeline出现ImportError求助
解决KFP VertexAI中
ImportError: cannot import name 'appengine'问题 问题根源
该错误由requests与urllib3版本不兼容引发:urllib3 2.0+版本移除了requests.packages.urllib3.contrib.appengine模块,而你使用的KFP 2.0.0-beta.15(预发布版)依赖的旧版请求逻辑在新版本依赖环境下失效。修改epoch并重新保存yaml后,触发了组件依赖的重新拉取或镜像更新,从而暴露了这一冲突。
可行解决方案
1. 锁定组件依赖版本
在KFP组件的依赖声明中明确指定兼容版本,避免自动拉取高版本依赖:
@kfp.v2.dsl.component( packages_to_install=[ "kfp>=2.0.0-beta.15", "requests<2.29", "urllib3<2.0" ] ) def your_component(...): # 组件业务代码
2. 使用自定义基础镜像
若依赖冲突仍存在,构建包含固定版本依赖的自定义镜像替代默认镜像:
FROM python:3.8-slim RUN pip install --no-cache-dir kfp==2.0.0-beta.15 requests==2.28.2 urllib3==1.26.15
将镜像推送到GCR后,在组件中指定:
@kfp.v2.dsl.component(base_image="gcr.io/your-project-id/your-custom-image:v1") def your_component(...): # 组件业务代码
3. 重新编译Pipeline而非手动修改YAML
禁止直接编辑存储桶中的YAML文件,修改代码中的epoch参数后重新编译生成YAML:
from kfp.v2.compiler import Compiler Compiler().compile( pipeline_func=your_pipeline_definition, package_path="updated_pipeline.yaml" ) # 将新编译的YAML上传至"budgetff"存储桶
4. 禁用Pipeline缓存
提交运行时禁用缓存,避免使用存在依赖问题的旧缓存组件:
from kfp.v2.google.client import AIPlatformClient client = AIPlatformClient(project_id="your-project-id", region="your-region") client.create_run_from_job_spec( "updated_pipeline.yaml", parameter_values={"epoch": your_new_epoch}, enable_caching=False )
内容的提问来源于stack exchange,提问作者filipe
相关产品推荐
相关产品推荐

