Upgrade model adapter without retraining(升级模型适配器而无需重新训练)¶
:::callout{theme="neutral"} This feature only applies to models trained in Code Repositories. :::
Recall that a model is the combination of model artifacts and a model adapter:
- Model artifacts: The model files, parameters, weights, containers, or credentials where a trained model is saved.
- Model adapter: The logic and the environment dependencies needed for Foundry to interact with the model artifacts to load, initialize, and perform inference with the model.
Sometimes, it can be useful to update the model adapter without changing or reproducing the model artifacts. For example:
- Fixing a bug in a model adapter without retraining the saved model.
- Updating a model's
load,api,predict, orrun_inferencemethod. - Updating a model's Python environment in the event that a Python dependency was found to have a vulnerability or bug.
However, updating the model adapter can also introduce breaking changes to the model's inference environment. The following must be kept in mind when making changes to a model adapter:
- Changes to any Python dependency in the environment must be compatible with existing model artifacts.
- The new implementation of
load,api,predict, orrun_inferencemust be compatible with existing artifacts. - The updated model adapter must be located in the same Python module with the same class name as the original model adapter.
It is highly recommended to exercise caution while updating a model adapter and to test changes first on a new branch.
Upgrade Model Adapter from Models App¶
Foundry enables upgrading a model version's model adapter to its most recent commit or tag while retaining its published model weights.
To upgrade a model adapter, first implement and publish changes to the model adapter class in the repository where it is defined. In the Model Training template in Code Repositories, changes will be published after every commit. In a Model Adapter template, changes will be published after a new tag is created.
Next, on the model application, scroll to the Inference Configuration card. Click Upgrade model adapter.

Clicking Create model version will create a new model version using the updated model adapter with the previously published model artifacts.
If the previous model version has been submitted to a modeling objective, the updated model version will not automatically be submitted and must be submitted again.
中文翻译¶
升级模型适配器而无需重新训练¶
:::callout{theme="neutral"} 此功能仅适用于在代码仓库中训练的模型。 :::
需要明确的是,模型由模型制品(model artifacts)和模型适配器(model adapter)两部分组成:
- 模型制品(Model artifacts): 保存训练模型时产生的模型文件、参数、权重、容器或凭证。
- 模型适配器(Model adapter): 用于让 Foundry 与模型制品交互,以加载、初始化并执行模型推理所需的逻辑和环境依赖。
在某些情况下,更新模型适配器而不修改或重新生成模型制品会非常有用。例如:
- 修复模型适配器中的错误,而无需重新训练已保存的模型。
- 更新模型的
load、api、predict或run_inference方法。 - 当发现某个 Python 依赖存在漏洞或错误时,更新模型的 Python 环境。
然而,更新模型适配器也可能对模型的推理环境带来破坏性变更。在对模型适配器进行修改时,必须注意以下几点:
- 环境中任何 Python 依赖的变更必须与现有模型制品兼容。
load、api、predict或run_inference的新实现必须与现有制品兼容。- 更新后的模型适配器必须位于与原始模型适配器相同的 Python 模块中,并使用相同的类名。
强烈建议在更新模型适配器时谨慎操作,并先在新分支上测试变更。
从模型应用(Models App)升级模型适配器¶
Foundry 支持将模型版本的模型适配器升级到最新的提交(commit)或标签(tag),同时保留已发布的模型权重。
要升级模型适配器,首先在定义该适配器的仓库中实现并发布对模型适配器类的更改。在代码仓库的模型训练模板中,每次提交后更改都会自动发布。在模型适配器模板中,创建新标签后更改才会发布。
接下来,在模型应用中,滚动到推理配置(Inference Configuration)卡片。点击升级模型适配器(Upgrade model adapter)。

点击创建模型版本(Create model version)将使用更新后的模型适配器以及之前发布的模型制品创建一个新的模型版本。
如果之前的模型版本已提交到建模目标(modeling objective),更新后的模型版本不会自动提交,需要重新提交。