本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
本节介绍如何使用 AWS Command Line Interface (CLI) 管理机器学习模型的 Amazon SageMaker Neo 编译任务。您可以创建、描述、停止和列出编译作业。
创建编译作业
CreateCompilationJob通过 API 操作,您可以指定数据输入格式、用于存储模型的 S3 存储桶、用于写入已编译模型的 S3 存储桶以及目标硬件设备或平台。
下表演示了如何基于您的目标是设备还是平台来配置
CreateCompilationJob
API。{ "CompilationJobName": "
neo-compilation-job-demo
", "RoleArn": "arn:aws:iam::
", "InputConfig": { "S3Uri": "<your-account>
:role/service-role/AmazonSageMaker-ExecutionRole-yyyymmddThhmmsss3://
", "DataInputConfig": "<your-bucket>
/sagemaker/neo-compilation-job-demo-data/train{'data': [1,3,1024,1024]}
", "Framework": "MXNET
" }, "OutputConfig": { "S3OutputLocation": "s3://
", # A target device specification example for a ml_c5 instance family "TargetDevice": "<your-bucket>
/sagemaker/neo-compilation-job-demo-data/compileml_c5
" }, "StoppingCondition": { "MaxRuntimeInSeconds":300
} }如果您使用框架训练模型并且目标设备是目标,则可以选择指定用于该
FrameworkVersion
字段的 PyTorchml_*
框架版本。{ "CompilationJobName": "neo-compilation-job-demo", "RoleArn": "arn:aws:iam::
<your-account>
:role/service-role/AmazonSageMaker-ExecutionRole-yyyymmddThhmmss", "InputConfig": { "S3Uri": "s3://<your-bucket>
/sagemaker/neo-compilation-job-demo-data/train", "DataInputConfig": "{'data': [1,3,1024,1024]}", "Framework": "PYTORCH", "FrameworkVersion": "1.6" }, "OutputConfig": { "S3OutputLocation": "s3://<your-bucket>
/sagemaker/neo-compilation-job-demo-data/compile", # A target device specification example for a ml_c5 instance family "TargetDevice": "ml_c5", # When compiling for ml_* instances using PyTorch framework, use the "CompilerOptions" field in # OutputConfig to provide the correct data type ("dtype") of the model’s input. Default assumed is "float32" "CompilerOptions": "{'dtype': 'long'}" }, "StoppingCondition": { "MaxRuntimeInSeconds": 300 } }注意:
-
如果您使用 PyTorch 版本 2.0 或更高版本保存模型,则该
DataInputConfig
字段为可选字段。 SageMaker AI Neo 从您创建的模型定义文件中获取输入配置 PyTorch。有关如何创建定义文件的更多信息,请参阅为 SageMaker AI Neo 保存模型下的PyTorch部分。 -
仅支持此 API 字段 PyTorch。
注意
对于
OutputConfig
API 操作,TargetDevice
和TargetPlatform
API 操作是互相排斥的。您必须从两个选项中选择一个。要根据框架查找
DataInputConfig
的 JSON 字符串示例,请参阅 Neo 期望的输入数据形状。有关设置配置的更多信息,请参阅 API 参考中的InputConfigOutputConfig、和 TargetPlatform SageMaker API 操作。
配置 JSON 文件后,运行以下命令来创建编译作业:
aws sagemaker create-compilation-job \ --cli-input-json file://job.json \ --region us-west-2 # You should get CompilationJobArn
通过运行以下命令描述编译作业:
aws sagemaker describe-compilation-job \ --compilation-job-name $JOB_NM \ --region us-west-2
通过运行以下命令停止编译作业:
aws sagemaker stop-compilation-job \ --compilation-job-name $JOB_NM \ --region us-west-2 # There is no output for compilation-job operation
通过运行以下命令列出编译作业:
aws sagemaker list-compilation-jobs \ --region us-west-2