r - 通过 R 中的 azure 机器学习 + azuremlsdk 部署模型并将模型公开为 Web 服务
问题描述
我正在尝试按照这篇文章在 Azure 中部署“模型”。
代码片段如下,模型,它只是一个添加 2 个数字的函数,似乎注册得很好。在 1000 次尝试后,我什至不使用该模型来隔离问题,因为此评分代码显示:
library(jsonlite)
init <- function()
{
message("hello world")
function(data)
{
vars <- as.data.frame(fromJSON(data))
prediction <- 2
toJSON(prediction)
}
}
应该没问题吧?我以任何方式运行此代码段:
r_env <- r_environment(name = "basic_env")
inference_config <- inference_config(
entry_script = "score.R",
source_directory = ".",
environment = r_env)
aci_config <- aci_webservice_deployment_config(cpu_cores = 1, memory_gb = 0.5)
aci_service <- deploy_model(ws,
'xxxxx',
list(model),
inference_config,
aci_config)
wait_for_deployment(aci_service, show_output = TRUE)
这会产生这个(经过很长时间):
Running.....................................................................
Failed
Service deployment polling reached non-successful terminal state, current service state: Failed
Operation ID: 14c35064-7ff4-46aa-9bfa-ab8a63218a2c
More information can be found using '.get_logs()'
Error:
{
"code": "AciDeploymentFailed",
"statusCode": 400,
"message": "Aci Deployment failed with exception: Error in entry script, RuntimeError: Error in file(filename, \"r\", encoding = encoding) : , please run print(service.get_logs()) to get details.",
"details": [
{
"code": "CrashLoopBackOff",
"message": "Error in entry script, RuntimeError: Error in file(filename, \"r\", encoding = encoding) : , please run print(service.get_logs()) to get details."
}
]
}
它并没有告诉我太多。不确定如何进一步调试?我该如何运行:
print(service.get_logs())
请问在哪里?猜猜这是一个 Python 神器?非常欢迎任何其他输入。
PS:
在这个时间点,我怀疑上面的 R 入口文件定义不是这些天所期望的。查看从此处获取的 Python 等效项:
import json
def init():
print("This is init")
def run(data):
test = json.loads(data)
print(f"received data {test}")
return f"test is {test}"
这样的事情会不会更合适(尝试过但没有成功)。
library(jsonlite)
init <- function()
{
message("hello world")
}
init <- function()
{
return(42)
}
解决方案
很高兴看到人们将 R SDK 付诸实践!
您正在使用的小插图显然是一个很好的入门方式。看来你几乎一路顺利。
部署总是很棘手,而且我自己也不是专家。我会向您指出有关本地部署故障排除的指南。R SDK 也存在类似的功能,即:local_webservice_deployment_config()
.
所以我想你把你的例子改成这样:
deployment_config <- local_webservice_deployment_config(port = 8890)
一旦您知道该服务在本地运行,您在使用 ACI Web 服务时遇到的问题就会变得更容易缩小范围。
推荐阅读
- python - 看不懂Python的代码行
- java - 将带有想象的java主体导出到带有图像的jar中
- database - 在数据框中查找特定项目
- ajax - 使用 ajax 和 django 进行第二次点击后,Div 显示/隐藏
- c# - 获取两个标签之间所有元素的列表
- r - 使用 dplyr 但至少保持组存在
- ruby - 主机名与服务器证书不匹配 - 使用旧的过期证书
- python-3.x - 如何在少于 30 天的日期时间中将年、月打印为 0?还是1年?
- youtube-iframe-api - Youtube url 参数 ?playlist=[video_id's] 不再工作
- batch-file - 批处理文件验证输入格式(仅限长度和数字)