編譯模型 (AWS Command Line Interface) - Amazon SageMaker

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

編譯模型 (AWS Command Line Interface)

本節說明如何使用 AWS Command Line Interface () 管理機器學習模型的 Amazon SageMaker Neo 編譯任CLI務。您可以建立、描述、停止和列出編譯任務。

  1. 建立編譯任務

    透過此CreateCompilationJobAPI作業,您可以指定資料輸入格式、用於存放模型的 S3 儲存貯體、要寫入編譯模型的 S3 儲存貯體,以及目標硬體裝置或平台。

    下表演示瞭如何CreateCompilationJobAPI根據您的目標是設備還是平台進行配置。

    Device Example
    { "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": "MXNET" }, "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" }, "StoppingCondition": { "MaxRuntimeInSeconds": 300 } }

    如果您使用框架來訓練模型,並且目標設備是目標,則可以選擇性地指定用於該FrameworkVersion字段的 PyTorch 框架版本。ml_*

    { "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 } }
    備註:
    • 如果您使用 2.0 PyTorch 版或更新版本儲存模型,則此DataInputConfig欄位為選擇性欄位。 SageMakerNeo 會從您建立的模型定義檔案中取得輸入組態 PyTorch。有關如何建立定義檔案的更多資訊,請參閱儲存模型以供 SageMaker Neo 使用。PyTorch

    • 僅支援此API欄位 PyTorch。

    Platform Example
    { "CompilationJobName": "neo-test-compilation-job", "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": "MXNET" }, "OutputConfig": { "S3OutputLocation": "s3://<your-bucket>/sagemaker/neo-compilation-job-demo-data/compile", # A target platform configuration example for a p3.2xlarge instance "TargetPlatform": { "Os": "LINUX", "Arch": "X86_64", "Accelerator": "NVIDIA" }, "CompilerOptions": "{'cuda-ver': '10.0', 'trt-ver': '6.0.1', 'gpu-code': 'sm_70'}" }, "StoppingCondition": { "MaxRuntimeInSeconds": 300 } }
    注意

    對於OutputConfigAPI作業而言,TargetDeviceTargetPlatformAPI運算是互斥的。您必須選擇兩個選項之一。

    要查找取DataInputConfig決於框架的JSON字符串示例,請參閱 Neo 期望的輸入數據形狀

    如需有關設定模型組態的詳細資訊 InputConfigOutputConfig,請參閱 SageMaker API參照中的、和TargetPlatformAPI操作。

  2. 設定JSON檔案後,請執行下列命令以建立編譯工作:

    aws sagemaker create-compilation-job \ --cli-input-json file://job.json \ --region us-west-2 # You should get CompilationJobArn
  3. 執行下列命令,描述編譯任務:

    aws sagemaker describe-compilation-job \ --compilation-job-name $JOB_NM \ --region us-west-2
  4. 執行下列命令,停止編譯任務:

    aws sagemaker stop-compilation-job \ --compilation-job-name $JOB_NM \ --region us-west-2 # There is no output for compilation-job operation
  5. 執行下列命令,列出編譯任務:

    aws sagemaker list-compilation-jobs \ --region us-west-2