首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Azure AutoML管道(Python )创建的评分文件中获取模型?

如何从Azure AutoML管道(Python )创建的评分文件中获取模型?
EN

Stack Overflow用户
提问于 2021-12-13 03:42:20
回答 1查看 144关注 0票数 0

我已经开发了一个带有AutoML步骤的管道,并使用生成的工件注册了模型。工件是一个序列化模型,是一个大的单个文件: model_data。我在评分文件中使用pickle.load函数反序列化Init函数中的模型,但在部署过程中失败了。当我打开主笔记本中的模型时,它工作得很好。这让我发疯了。帮帮忙,伙计们!

AutoML-Pipeline.ipynb

代码语言:javascript
复制
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

代码语言:javascript
复制
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)
        raise

AutoML-Pipeline.ipynb

代码语言:javascript
复制
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)

错误:

代码语言:javascript
复制
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

代码语言:javascript
复制
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')
EN

回答 1

Stack Overflow用户

发布于 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()方法上

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70329715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档