【问题标题】:Unhealthy deployment不健康的部署
【发布时间】:2020-08-17 12:26:51
【问题描述】:

我将一个 keras 模型(在 python 中)部署到 ML Azure。部署以不健康状态结束。这意味着什么? 我用这段代码部署我的模型:

image_config = ContainerImage.image_configuration(execution_script='script.py', 
                                                  runtime='python', 
                                                  conda_file='config_conda.yml')

   aciconfig = AciWebservice.deploy_configuration(cpu_cores=1, 
                                               memory_gb=1, 
                                               description='')
   service = Webservice.deploy_from_model(workspace=ws,
                                       name=model_name,
                                       deployment_config=aciconfig,
                                       models=[model],
                                       image_config=image_config)
 
   service.wait_for_deployment(show_output=True) 

在 config_conda.yml 文件中,“pip”部分和“dependencies”部分有什么区别? 我在我的 script.py 中使用以下包:

import pandas as pd
   import numpy as np
   import string

   #scikit-learn
   from sklearn.metrics import roc_curve
   from sklearn.metrics import roc_auc_score
   from sklearn.model_selection import train_test_split
   from sklearn.feature_extraction.text import CountVectorizer
   from sklearn.linear_model import LogisticRegression
   from sklearn.model_selection import GridSearchCV
   from sklearn.preprocessing import LabelEncoder

   import nltk
   from nltk.corpus import stopwords
   from nltk.corpus import wordnet
   from nltk.stem import WordNetLemmatizer
   from nltk.stem.porter import PorterStemmer

   # Word2vec
   import gensim

   # Keras  
   from tensorflow import keras
   from keras import metrics
   from keras.models import Sequential
   from keras.layers import Dense
   from keras.layers import Dropout
   from keras.layers import Embedding
   from keras.layers import LSTM
   from keras.layers import GlobalMaxPool1D
   from keras import utils
   from keras.preprocessing.text import Tokenizer
   from keras.preprocessing.sequence import pad_sequences

   import multiprocessing 

【问题讨论】:

    标签: python tensorflow keras scikit-learn azure-machine-learning-service


    【解决方案1】:

    请参阅https://docs.microsoft.com/en-us/azure/machine-learning/how-to-deploy-and-where?tabs=azcli#understanding-service-state 了解服务状态。

    另见troubleshooting steps

    "dependencies" 将与conda install x 一起安装,而"pip" 下列出的内容将与pip install x 一起安装。尽可能尝试使用 conda 版本,因为它使用不太可能导致问题的预编译二进制文件。

    【讨论】:

    • 感谢 Gopal 的回答 :-)
    • 如何增加超时时间?
    【解决方案2】:

    根据我的经验,当评分脚本或 .yml 文件(在您的情况下为 script.py 和 config_conda.yml)出现问题时,端点最终会处于不健康状态。您可以使用此命令查看日志,这通常会告诉您问题:

    print(service.get_logs())
    

    另一种调试方法是先尝试将服务部署为LocalService:

    myenv = Environment.from_conda_specification(name = "myenv", file_path = "config_conda.yml")
    
    inference_config = InferenceConfig(entry_script = "script.py", environment = myenv)
    deployment_config = LocalWebservice.deploy_configuration(port=6789)
    
    local_service = Model.deploy(ws, "local-test", [model], inference_config, deployment_config)
    local_service.wait_for_deployment(show_output = True)
    

    这样,Docker容器构建过程的所有步骤(包括安装包)都打印出来了。完成后,您可以删除本地服务 (local_service.delete())。

    顺便说一句,您还可以使用 Model.deploy 而不是 Webservice.deploy_from_model 部署 ACI Web 服务(请参阅https://docs.microsoft.com/en-us/python/api/azureml-core/azureml.core.webservice(class)?view=azure-ml-py)。据我所知,这通常更快

    【讨论】:

    • 感谢埃琳娜的帮助。我会试试的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 2020-10-30
    • 2023-03-19
    • 1970-01-01
    • 2020-01-26
    相关资源
    最近更新 更多