如何通过Azure ML Python SDK V2禁止Pipeline上传指定文件?
解决Azure ML SDK V2创建Pipeline时排除指定文件的问题
方法1:使用.amlignore文件(推荐)
和Git的.gitignore逻辑一致,在项目根目录创建.amlignore文件,写入需要排除的文件/目录规则即可。Azure ML会自动识别该文件,跳过匹配的内容不上传。
示例.amlignore内容:
# 排除.env凭据文件 .env # 可选:排除缓存和日志文件 __pycache__/ *.log
方法2:在命令组件中显式配置排除规则
如果不想依赖配置文件,可以直接在@mldesigner.command_component装饰器中通过source_directory和exclude参数指定上传范围和排除项:
修改后的组件代码:
@mldesigner.command_component( name="testcomponent", display_name="Test Component", description="Test Component description.", environment=dict( conda_file="./conda.yaml", image="mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04", ), source_directory=".", # 指定要上传的根目录 exclude=[".env", "__pycache__"] # 列出需要排除的文件/目录 ) def test_component(): mlflow.log_metric("metric", 0)
补充说明
.amlignore的语法和.gitignore完全兼容,支持通配符、目录匹配等复杂规则。- 若同时使用
.amlignore和exclude参数,两者的排除规则会叠加生效,最终排除的是两者规则的并集。 - 本地读取
.env的代码是在创建Pipeline的本地阶段执行的,组件运行在Azure ML集群时不会依赖该文件,因此排除后不会影响组件功能。
内容的提问来源于stack exchange,提问作者Ken Jiiii
相关产品推荐
相关产品推荐

