3

I have a training script in Sagemaker like,

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

Most of which I stole from the MNIST Example.

When I train, everything goes fine, but when trying to deploy like,

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')

I get, (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.

Looking in my S3 bucket s3://sagemaker-us-west-2-01234567890/sagemaker-mxnet-py2-cpu-2018-01-17-20-52-52-599/output/model.tar.gz, I in fact don't see the model.

What am I missing?

4

2 回答 2

0

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

#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,
          ...)

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

于 2018-01-22T06:28:10.380 回答
0

我在 Sagemaker 上以非常相似的方式使用不同的 Estimator 时遇到了同样的问题。

我的问题是在重新部署的第一次部署之后,我不得不删除旧的“端点配置”——这令人困惑地将端点指向旧模型位置。我想这可以使用 AWS API 从 python 完成,尽管如果这是同一个问题,在门户上很容易测试。

在此处输入图像描述

于 2019-05-06T14:16:32.313 回答