我已经开发了一个带有AutoML步骤的管道,并使用生成的工件注册了模型。工件是一个序列化模型,是一个大的单个文件: model_data。我在评分文件中使用pickle.load函数反序列化Init函数中的模型,但在部署过程中失败了。当我打开主笔记本中的模型时,它工作得很好。这让我发疯了。帮帮忙,伙计们!
AutoML-Pipeline.ipynb
automl_settings = {
"experiment_timeout_minutes": 30,
"primary_metric": 'AUC_weighted',
"max_concurrent_iterations": 3,
"max_cores_per_iteration": -1,
"enable_dnn": True,
"enable_early_stopping": True,
"validation_size": 0.3,
"verbosity": logging.INFO,
"enable_voting_ensemble": False,
"enable_stack_ensemble": False,
}
automl_config = AutoMLConfig(task = 'classification',
debug_log = 'automl_errors.log',
path = ".",
compute_target=compute_target,
training_data = train_ds,
label_column_name = target_column_name,
**automl_settings
)
metrics_output_name = 'metrics_output'
best_model_output_name = 'best_model_output'
metrics_data = PipelineData(name='metrics_data',
datastore=dstor,
pipeline_output_name=metrics_output_name,
training_output=TrainingOutput(type='Metrics'))
model_data = PipelineData(name='model_data',
datastore=dstor,
pipeline_output_name=best_model_output_name,
training_output=TrainingOutput(type='Model'))
automl_step = AutoMLStep(
name='automl_module',
automl_config=automl_config,
outputs=[metrics_data, model_data],
allow_reuse=False)scoring_file_v_1__0.py
def init():
global model
model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'model_data')
try:
with open(model_path, "rb" ) as f:
model = pickle.load(f)
except Exception as e:
logging_utilities.log_traceback(e, logger)
raiseAutoML-Pipeline.ipynb
model = Model(ws, 'AutoML-Product')
automl_env = Environment.from_conda_specification(name = 'automl_env', file_path = 'conda_env_v_1_0_0.yml')
inference_config=InferenceConfig(entry_script="scoring_file_v_1_0_0.py",environment=automl_env)
aciconfig=AciWebservice.deploy_configuration(cpu_cores=1,
memory_gb=1,
tags={'type': "automl_product"},
description='Product Classification')
aci_service=Model.deploy(ws, "automl-product-classification", [model], inference_config, aciconfig)
aci_service.wait_for_deployment(True)错误:
WebserviceException: WebserviceException: Message: Service deployment polling reached non-successful terminal state, current service state.
Error:
{
"code": "AciDeploymentFailed",
"statusCode": 400,
"message": "Aci Deployment failed with exception: Your scoring file's init() function restarts frequently. You can address the error by increasing the value of memory_gb in deployment_config.",
"details": [
{
"code": "ScoreInitRestart",
"message": "Your scoring file's init() function restarts frequently. You can address the error by increasing the value of memory_gb in deployment_config."
}
]
}在笔记本中成功运行:AutoML-管道. in
import pickle
path=Model.get_model_path('AutoML-Product',None,ws)
with open(path, "rb" ) as f:
best_model = pickle.load(f)
best_model
>>>>>
PipelineWithYTransformations(Pipeline={'memory': None,
'steps': [('datatransformer',
DataTransformer(enable_dnn=True, enable_feature_sweeping=True, feature_sweeping_config={}, feature_sweeping_timeout=86400, featurization_config=None, force_text_dnn=False, is_cross_validation=False, is_onnx_compatible=False, observer=None, task='classification', working_dir='/mn...
with_std=True
)),
('LogisticRegression',
LogisticRegression(C=0.02811768697974228,
class_weight='balanced',
dual=False,
fit_intercept=True,
intercept_scaling=1,
l1_ratio=None,
max_iter=100,
multi_class='ovr',
n_jobs=-1,
penalty='l2',
random_state=None,
solver='saga',
tol=0.0001,
verbose=0,
warm_start=False))],
'verbose': False},
y_transformer={},
y_transformer_name='LabelEncoder')发布于 2022-01-07 10:38:16
从读取错误消息中可以看出,您需要增加分配给部署的内存。
aciconfig=AciWebservice.deploy_configuration(...,memory_gb=1,...)
to和x数量,允许您的模型运行:
aciconfig=AciWebservice.deploy_configuration(...,memory_gb=x,...)
您的记分文件的init()函数经常重新启动。您可以通过增加memory_gb在deployment_config中的值来解决错误。
有迹象表明问题出在pickle.load()方法上
https://stackoverflow.com/questions/70329715
复制相似问题