Ошибка при развертывании модели: во время развертывания Azure ML отсутствует azureml-inference-server-http.Python

Программы на Python
Ответить
Anonymous
 Ошибка при развертывании модели: во время развертывания Azure ML отсутствует azureml-inference-server-http.

Сообщение Anonymous »

В настоящее время я работаю над развертыванием модели рекомендаций фильмов с помощью Azure ML, но в процессе развертывания возникла ошибка. Я продолжаю получать следующее сообщение об ошибке

Код: Выделить всё

A required package azureml-inference-server-http is missing.  Please install azureml-inference-server-http before trying again.
/bin/bash: /azureml-envs/azureml_fab3afe801876d063dd71721ecb28f65/lib/libtinfo.so.6: no version information available (required by /bin/bash)
Что я пытаюсь сделать:
Я работаю с пакетом-сюрпризом, чтобы обучить модель совместной фильтрации рекомендаций по фильмам, а затем развернуть ее в службе Azure Kubernetes (AKS) с помощью Azure ML.
Шаги, которые я предпринял на данный момент:
Я уже установил необходимый пакет azureml-inference-server-http в файле conda.yaml.
Я проверил среду и проверил наличие пакета, но ошибка не устранена.

Код: Выделить всё

import recommenders
from recommenders.datasets import movielens

import surprise

from recommenders.utils.timer import Timer
from recommenders.datasets import movielens
from recommenders.datasets.python_splitters import python_random_split
from recommenders.evaluation.python_evaluation import (
rmse,
mae,
rsquared,
exp_var,
map_at_k,
ndcg_at_k,
precision_at_k,
recall_at_k,
get_top_k_items,
)
from recommenders.models.surprise.surprise_utils import (
predict,
compute_ranking_predictions,
)
from recommenders.utils.notebook_utils import store_metadata

from azure.identity import DefaultAzureCredential
from azure.ai.ml import MLClient

try:
credential = DefaultAzureCredential()
except Exception as ex:
print(ex)

# Get a handle to workspace
ml_client = MLClient.from_config(credential=credential)
# Top k items to recommend
TOP_K = 10

# Select MovieLens data size: 100k, 1m, 10m, or 20m
MOVIELENS_DATA_SIZE = "100k"

data = movielens.load_pandas_df(
size=MOVIELENS_DATA_SIZE, header=["userID", "itemID", "rating"]
)

data.head()

train, test = python_random_split(data, 0.75)
train_set = surprise.Dataset.load_from_df(
train, reader=surprise.Reader("ml-100k")
).build_full_trainset()
train_set

svd = surprise.SVD(random_state=0, n_factors=200, n_epochs=30, verbose=True)

with Timer() as train_time:
svd.fit(train_set)

print(f"Took {train_time.interval} seconds for training.")
predictions = predict(svd, test, usercol="userID", itemcol="itemID")
predictions.head()

with Timer() as test_time:
all_predictions = compute_ranking_predictions(
svd, train, usercol="userID", itemcol="itemID", remove_seen=True
)

print(f"Took {test_time.interval} seconds for prediction.")

all_predictions.head()

eval_rmse = rmse(test, predictions)
eval_mae = mae(test, predictions)
eval_rsquared = rsquared(test, predictions)
eval_exp_var = exp_var(test, predictions)

eval_map = map_at_k(test, all_predictions, col_prediction="prediction", k=TOP_K)
eval_ndcg = ndcg_at_k(test, all_predictions, col_prediction="prediction", k=TOP_K)
eval_precision = precision_at_k(
test, all_predictions, col_prediction="prediction", k=TOP_K
)
eval_recall = recall_at_k(test, all_predictions, col_prediction="prediction", k=TOP_K)

print(
"RMSE:\t\t%f" % eval_rmse,
"MAE:\t\t%f" % eval_mae,
"rsquared:\t%f" % eval_rsquared,
"exp var:\t%f" % eval_exp_var,
sep="\n",
)

print("----")

print(
"MAP:\t\t%f" % eval_map,
"NDCG:\t\t%f" % eval_ndcg,
"Precision@K:\t%f" % eval_precision,
"Recall@K:\t%f"  % eval_recall,
sep="\n",
)

import joblib

# Save the model to a file
joblib.dump(svd, 'svd_model.pkl')

# Step 8: Recommend Movies for a User
def recommend_movies(user_id, model, train_data, top_k=10):
"""Generate movie recommendations for a specific user."""
all_movie_ids = set(train_data["itemID"])
seen_movies = set(train_data[train_data["userID"] == user_id]["itemID"])
unseen_movies = all_movie_ids - seen_movies

predictions = [
(movie_id, model.predict(user_id, movie_id).est)
for movie_id in unseen_movies
]
recommendations = sorted(predictions, key=lambda x: x[1], reverse=True)[:top_k]
return recommendations

# Example: Generate Recommendations for a User
example_user_id = 1
print(f"Generating recommendations for user {example_user_id}...")
recommendations = recommend_movies(example_user_id, svd, train, top_k=TOP_K)
print(f"Top {TOP_K} recommendations for user {example_user_id}:")
for movie_id, predicted_rating in recommendations:
print(f"Movie ID: {movie_id}, Predicted Rating: {predicted_rating:.2f}")

from azureml.core import Workspace,Model

# Connect to the Azure ML workspace
workspace = Workspace.from_config()

# Register the model
model = Model.register(
workspace=workspace,
model_path="svd_model.pkl",  # Path to your model file
model_name="movie_recommendation_model1",  # Name to register the model
description="Collaborative filtering model for movie recommendations",
)
print(f"Model registered: {model.name}, Version: {model.version}")
# create azureml environment
from azureml.core import Workspace, Environment

workspace = Workspace.from_config()

env = Environment.from_conda_specification(name="svd-env", file_path="conda.yaml")
env.register(workspace=workspace)

from azureml.core import Workspace, ComputeTarget
from azureml.core.compute import AksCompute
from azureml.exceptions import ComputeTargetException

# Set your Azure ML workspace and AKS cluster name
workspace = Workspace.from_config()
aks_name = "my-aks-cluster"  # Replace with your preferred cluster name

# Verify if the AKS cluster already exists
try:
aks_target = ComputeTarget(workspace=workspace, name=aks_name)
print("Found existing cluster. Using it.")
except ComputeTargetException:
print("AKS cluster not found.  Creating a new cluster...")

# Define provisioning configuration
prov_config = AksCompute.provisioning_configuration(
agent_count=3,                 # Number of nodes (adjust based on needs)
vm_size="Standard_DS3_v2",    # VM size for the nodes
location="eastus"             # Azure region (optional, defaults to workspace location)
)

# Create the AKS cluster
aks_target = ComputeTarget.create(
workspace=workspace,
name=aks_name,
provisioning_configuration=prov_config
)
aks_target.wait_for_completion(show_output=True)

# Check provisioning state and any errors
if aks_target.provisioning_state == "Succeeded":
print("AKS cluster creation succeeded.")
else:
print(f"Provisioning state: {aks_target.provisioning_state}")
print("Provisioning errors:", aks_target.provisioning_errors)

from azureml.core import Workspace, Model, Environment, Webservice
from azureml.core.model import InferenceConfig
from azureml.core.webservice import AksWebservice
from azureml.exceptions import WebserviceException

# Set your Azure ML workspace and AKS cluster name
workspace = Workspace.from_config()
service_name = "my-aks-service"  # Replace with your desired service name

# Reference your AKS cluster
aks_name = "my-aks-cluster"  # Replace with your AKS cluster name
aks_target = ComputeTarget(workspace=workspace, name=aks_name)

# Reference your registered model
model_name = "movie_recommendation_model"  # Replace with your model name
mymodel = Model(workspace, name=model_name)

# Create an inferencing configuration
inference_config = InferenceConfig(
environment=env,  # Previously registered environment
entry_script="score.py"  # Replace with your scoring script
)

# Set up AKS deployment configuration
aks_config = AksWebservice.deploy_configuration(enable_app_insights=True)

# Deploy the model to AKS
try:
aks_service = Model.deploy(
workspace=workspace,
models=[mymodel],
name=service_name,
inference_config=inference_config,
deployment_config=aks_config,
deployment_target=aks_target
)
aks_service.wait_for_deployment(show_output=True)
print(f"Service deployed successfully.  State: {aks_service.state}")
except WebserviceException:
# Retrieve existing service if deployment fails or service already exists
aks_service = Webservice(workspace, name=service_name)
print("Retrieved existing service.")
print(f"Service state: {aks_service.state}")

# Check the scoring URI
print(f"Service scoring URI: {aks_service.scoring_uri}")

# Check logs (optional)
print("Service logs:")
print(aks_service.get_logs())

Это мои данные в файле Score.py

Код: Выделить всё

import json
import pickle
import numpy as np

# Load the model during initialization
def init():
global model
with open("svd_model.pkl", "rb") as f:
model = pickle.load(f)

# Handle requests
def run(raw_data):
try:
data = json.loads(raw_data)
user_id = data["user_id"]
unseen_movies = data["unseen_movies"]

# Generate predictions
predictions = [
{"movie_id": movie_id, "score": model.predict(user_id, movie_id).est}
for movie_id in unseen_movies
]
# Sort by score
recommendations = sorted(predictions, key=lambda x: x["score"], reverse=True)
return json.dumps(recommendations[:10])  # Return top 10 recommendations
except Exception as e:
return json.dumps({"error": str(e)})
Это мой файл conda.yaml ниже

Код: Выделить всё

name: svd-env
channels:
- defaults
dependencies:
- python=3.9
- scikit-learn=1.0.2
- numpy=1.21.5
- pandas=1.1.5
- ncurses  # Ensures libtinfo.so.6 is available
- pip
- pip:
- azureml-defaults==1.50.0
- azureml-inference-server-http==0.8.0  # Downgrade to a compatible version
- azureml-sdk==1.50.0
- joblib==1.1.0
Как устранить эту ошибку во время развертывания модели в Azure ML? Чего-то не хватает в моей конфигурации или нужно предпринять какие-то конкретные действия, чтобы устранить проблему с отсутствующим пакетом?

Подробнее здесь: https://stackoverflow.com/questions/793 ... during-azu
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»