我正在尝试为azureml模型创建端点。目前我看到的所有示例都使用了库sklearn中的模型,因此从.pkl文件加载模型没有问题。
在我的例子中,我的模型是一个自定义类,我写了我自己的"bert_based_model“。
现在的问题是在编译我的score.py文件时,我得到了一个错误:
ModuleNotFoundError:没有名为“bert_based_model”的模块
如何在azureml端点中导入自定义模型?
谢谢。
发布于 2022-10-15 20:11:42
假设您有一个包含自定义模型类MyBertModel
的脚本my_module.py,则应该将脚本放在端点的source_directory
下,并在条目脚本中导入该类。
因此,如果这是您的推理配置:
inference_config = InferenceConfig(
environment=env,
source_directory='./endpoint_source',
entry_script="./score.py",
)
./endpoint_source/应该是这样的:
.
└── endpoint_source
├── score.py
├── my_module.py
└── ...
您的入口脚本score.py
应该是这样的:
from my_module import MyBertModel
# other imports
...
def init():
global model
# load the model here, from pickle file or using the custom class
model = ...
def run(data):
# use the model here to predict on data
...
https://stackoverflow.com/questions/73703577
复制相似问题