gpt4 book ai didi

python - 尝试部署我的模型时 Sagemaker "Could not find model data"

转载 作者:行者123 更新时间:2023-11-28 19:04:44 24 4
gpt4 key购买 nike

我在 Sagemaker 中有一个训练脚本,例如,

def train(current_host, hosts, num_cpus, num_gpus, channel_input_dirs, model_dir, hyperparameters, **kwargs):
... Train a network ...
return net

def save(net, model_dir):
# save the model
logging.info('Saving model')
y = net(mx.sym.var('data'))
y.save('%s/model.json' % model_dir)
net.collect_params().save('%s/model.params' % model_dir)

def model_fn(model_dir):
symbol = mx.sym.load('%s/model.json' % model_dir)
outputs = mx.symbol.softmax(data=symbol, name='softmax_label')
inputs = mx.sym.var('data')
param_dict = gluon.ParameterDict('model_')
net = gluon.SymbolBlock(outputs, inputs, param_dict)
net.load_params('%s/model.params' % model_dir, ctx=mx.cpu())
return net

其中大部分是我从 MNIST Example 偷来的。

当我训练时,一切都很顺利,但是当我尝试部署时,

m = MXNet("lstm_trainer.py", 
role=role,
train_instance_count=1,
train_instance_type="ml.c4.xlarge",
hyperparameters={'batch_size': 100,
'epochs': 20,
'learning_rate': 0.1,
'momentum': 0.9,
'log_interval': 100})
m.fit(inputs) # No errors
predictor = m.deploy(initial_instance_count=1, instance_type='ml.m4.xlarge')

我明白了,( full output )

INFO:sagemaker:Creating model with name: sagemaker-mxnet-py2-cpu-2018-01-17-20-52-52-599
---------------------------------------------------------------------------
... Stack dump ...
ClientError: An error occurred (ValidationException) when calling the CreateModel operation: Could not find model data at s3://sagemaker-us-west-2-01234567890/sagemaker-mxnet-py2-cpu-2018-01-17-20-52-52-599/output/model.tar.gz.

查看我的 S3 存储桶 s3://sagemaker-us-west-2-01234567890/sagemaker-mxnet-py2-cpu-2018-01-17-20-52-52-599/output/model .tar.gz,其实我没看到模型。

我错过了什么?

最佳答案

当您调用训练作业时,您应该指定输出目录:

#Bucket location where results of model training are saved.
model_artifacts_location = 's3://<bucket-name>/artifacts'

m = MXNet(entry_point='lstm_trainer.py',
role=role,
output_path=model_artifacts_location,
...)

如果您不指定输出目录,该函数将使用默认位置,它可能没有创建或写入权限。

关于python - 尝试部署我的模型时 Sagemaker "Could not find model data",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48310237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com