本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
本節說明如何使用 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
} }如果您使用 PyTorch 架構訓練模型,且目標裝置是
ml_*
目標,則可以選擇性指定與FrameworkVersion
欄位搭配使用的架構版本。{ "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一節。 -
僅針對 PyTorch 支援此 API 欄位。
注意
若為
OutputConfig
API 作業,TargetDevice
和TargetPlatform
API 作業互斥。您必須選擇兩個選項之一。若要取決於架構尋找
DataInputConfig
的 JSON 字串範例,請參閱 Neo 期望的輸入資料形狀。如需設定組態的更多相關資訊,請參閱 SageMaker API 參考資料中的 InputConfig、OutputConfig 與 TargetPlatform 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