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

Azure ML Pipeline脚本步骤中Run.register_model注册模型失败求助

解决Azure ML Pipeline中Run.register_model找不到模型文件的问题

你遇到的问题核心是模型路径指向错误——虽然已经把模型文件移到了./outputs目录,但Run.register_model的model_path参数没有正确指向这个位置。

问题根源

当你执行os.replace把文件移到./outputs后,当前工作目录下已经不存在retrained.zip了;而Run.register_model会从与当前run关联的文件集合中查找路径,这个集合里的文件路径是相对于run根目录的,你需要明确指向outputs子目录下的文件。

修正方案

修改model_path参数,指向outputs目录下的模型文件即可。调整后的代码如下:

os.replace(os.path.join('.', archive_name + '.zip'), os.path.join('.', 'outputs', archive_name + '.zip'))
print(os.listdir('./outputs'))
print('========================')
run_context = Run.get_context()

# 关键:修正model_path为outputs目录下的文件路径
finetuning_model = run_context.register_model(
    model_name='finetuning_similarity_model',
    model_path=os.path.join('outputs', archive_name + '.zip'),
    tags={},
    description="Finetuning Similarity model"
)

额外排查技巧

如果还是不确定路径是否正确,可以在注册模型前,打印出当前run中所有可用的文件列表,确认文件路径:

# 打印run关联的所有文件路径,用于验证
print("Available files in run:", run_context.list_files())

这会输出类似['outputs/retrained.zip']的结果,你只需要把model_path设置为这个输出中的路径即可。

补充说明

Azure ML的PythonScriptStep会自动把./outputs目录下的所有文件上传到run的输出存储中,所以不需要额外调用upload_file方法,只要路径正确就能被找到。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:38:47