本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
JSON (AWS CLI)
Amazon SageMaker 偵錯工具內建規則可透過 SageMaker CreateTrainingJobAPI 作業使用DebugHookConfig、DebugRuleConfiguration、和ProfilerRuleConfiguration物件 ProfilerConfig,為訓練任務設定。您必須在RuleEvaluatorImage
參數中指定正確的影像 URI,下列範例會逐步引導您如何設定要求的 JSON 字串CreateTrainingJob。
下列程式碼會顯示完整的 JSON 範本,使用必要設定和 Debugger 組態執行訓練任務。將範本儲存為工作目錄中的 JSON 檔案,並使用 AWS CLI 執行訓練工作。例如,將以下程式碼儲存為 debugger-training-job-cli.json
。
注意
請確定您使用正確的 Docker 容器映像。若要尋找 AWS Deep Learning Containers 映像檔,請參閱可用的深度學習容器映像
{ "TrainingJobName": "
debugger-aws-cli-test
", "RoleArn": "arn:aws:iam::111122223333:role/service-role/AmazonSageMaker-ExecutionRole-YYYYMMDDT123456
", "AlgorithmSpecification": { // Specify a training Docker container image URI (Deep Learning Container or your own training container) to TrainingImage. "TrainingImage": "763104351884.dkr.ecr.us-west-2.amazonaws.com/tensorflow-training:2.4.1-gpu-py37-cu110-ubuntu18.04
", "TrainingInputMode": "File
", "EnableSageMakerMetricsTimeSeries": false }, "HyperParameters": { "sagemaker_program": "entry_point/tf-hvd-train.py
", "sagemaker_submit_directory": "s3://sagemaker-us-west-2-111122223333/debugger-boto3-profiling-test/source.tar.gz
" }, "OutputDataConfig": { "S3OutputPath": "s3://sagemaker-us-west-2-111122223333/debugger-aws-cli-test
/output" }, "DebugHookConfig": { "S3OutputPath": "s3://sagemaker-us-west-2-111122223333/debugger-aws-cli-test
/debug-output", "CollectionConfigurations": [ { "CollectionName": "losses
", "CollectionParameters" : { "train.save_interval": "50
" } } ] }, "DebugRuleConfigurations": [ { "RuleConfigurationName": "LossNotDecreasing
", "RuleEvaluatorImage": "895741380848.dkr.ecr.us-west-2.amazonaws.com/sagemaker-debugger-rules:latest
", "RuleParameters": {"rule_to_invoke": "LossNotDecreasing
"} } ], "ProfilerConfig": { "S3OutputPath": "s3://sagemaker-us-west-2-111122223333/debugger-aws-cli-test
/profiler-output", "ProfilingIntervalInMilliseconds":500
, "ProfilingParameters": { "DataloaderProfilingConfig": "{\"StartStep\":5
, \"NumSteps\":3
, \"MetricsRegex\": \".*\", }", "DetailedProfilingConfig": "{\"StartStep\":5
, \"NumSteps\":3
, }", "PythonProfilingConfig": "{\"StartStep\":5
, \"NumSteps\":3
, \"ProfilerName\": \"cprofile
\", \"cProfileTimer\": \"total_time
\"}", "LocalPath": "/opt/ml/output/profiler/" } }, "ProfilerRuleConfigurations": [ { "RuleConfigurationName": "ProfilerReport", "RuleEvaluatorImage": "895741380848.dkr.ecr.us-west-2.amazonaws.com/sagemaker-debugger-rules:latest
", "RuleParameters": {"rule_to_invoke": "ProfilerReport"} } ], "ResourceConfig": { "InstanceType": "ml.p3.8xlarge
", "InstanceCount":1
, "VolumeSizeInGB": 30 }, "StoppingCondition": { "MaxRuntimeInSeconds":86400
} }
儲存 JSON 檔案後,請執行下列終端機中的命令。(如果您使用 Jupyter 筆記本,請在該行的開頭使用 !
。)
aws sagemaker create-training-job --cli-input-json file://debugger-training-job-cli.json
若要設定偵錯模型參數的 Debugger 規則
下列程式碼範例顯示如何使用此 SageMaker API 設定內建VanishingGradient
規則。
若要啟用 Debugger 收集輸出張量
請指定 Debugger 勾點組態,如下所示:
"DebugHookConfig": { "S3OutputPath": "
s3://<default-bucket>/<training-job-name>/debug-output
", "CollectionConfigurations": [ { "CollectionName": "gradients
", "CollectionParameters" : { "save_interval": "500
" } } ] }
這將讓訓練任務儲存張量集合(gradients
、每 500 個步驟就 save_interval
一次)。若要找到可用的 CollectionName
值,請參閱 SMDebug 用戶端程式庫文件中的 Debugger 內建集合CollectionParameters
參數鍵和值,請參閱 SageMaker Python SDK 文件中的sagemaker.debugger.CollectionConfig
若要啟用適用於偵錯輸出張量的 Debugger 規則
下列 DebugRuleConfigurations
API 範例會示範如何在已儲存的 gradients
集合上執行內建 VanishingGradient
規則。
"DebugRuleConfigurations": [ { "RuleConfigurationName": "
VanishingGradient
", "RuleEvaluatorImage": "503895931360.dkr.ecr.us-east-1.amazonaws.com/sagemaker-debugger-rules:latest
", "RuleParameters": { "rule_to_invoke": "VanishingGradient
", "threshold": "20.0
" } } ]
就此範例中的組態來說,Debugger 會使用 gradients
張量集合上的 VanishingGradient
規則,對訓練任務啟動規則評估任務。要查找用於使用調試器規則的可用 Docker 映像的完整列表,請參閱為內建或自訂規則使用偵錯器 Docker 映像。若要查找RuleParameters
,請參閱偵錯工具內建規則清單。
若要設定適用於分析系統和架構指標的 Debugger 內建規則
下列範例程式碼示範如何指定 ProfilerConfig API 作業,以便收集系統和架構指標。
若要啟用 Debugger 分析收集系統和架構指標
若要啟用 Debugger 規則分析指標
下列範例程式碼示範如何設定 ProfilerReport
規則。
"ProfilerRuleConfigurations": [ { "RuleConfigurationName": "ProfilerReport", "RuleEvaluatorImage": "
895741380848.dkr.ecr.us-west-2.amazonaws.com/sagemaker-debugger-rules:latest
", "RuleParameters": { "rule_to_invoke": "ProfilerReport", "CPUBottleneck_cpu_threshold": "90
", "IOBottleneck_threshold": "90
" } } ]
要查找用於使用調試器規則的可用 Docker 映像的完整列表,請參閱為內建或自訂規則使用偵錯器 Docker 映像。若要查找RuleParameters
,請參閱偵錯工具內建規則清單。
使用 UpdateTrainingJob
API 操作更新 Debugger 分析組態
您可以在訓練工作執行時,使用 UpdateTrainingJobAPI 作業來更新偵錯程式分析組態。配置新ProfilerRuleConfiguration物件ProfilerConfig和物件,並為TrainingJobName
參數指定訓練工作名稱。
{ "ProfilerConfig": { "DisableProfiler":
boolean
, "ProfilingIntervalInMilliseconds":number
, "ProfilingParameters": { "string
" : "string
" } }, "ProfilerRuleConfigurations": [ { "RuleConfigurationName": "string
", "RuleEvaluatorImage": "string
", "RuleParameters": { "string" : "string
" } } ], "TrainingJobName": "your-training-job-name-YYYY-MM-DD-HH-MM-SS-SSS
" }
將偵錯工具自訂規則組態新增至 CreateTrainingJob API 作業
您可以使用 CreateTrainingJobAPI 作業中的 DebugHookConfig和 DebugRuleConfiguration物件,為訓練工作設定自訂規則。下列程式碼範例顯示如何設定使用此 SageMaker API 作業以 smdebug 程式庫撰寫的自訂ImproperActivation
規則。此範例假設您已在 custom_rules.py 檔案中撰寫自訂規則,並上傳到 Amazon S3 儲存貯體。下列範例提供預先建置的 Docker 映像,可用來執行您的自訂規則。這些都列在 Amazon SageMaker 調試器註冊表自URLs定義規則評估器。您需要在 RuleEvaluatorImage
參數中指定預先建置的 Docker 影像的 URL 登錄位址。
"DebugHookConfig": { "S3OutputPath": "
s3://<default-bucket>/<training-job-name>/debug-output
", "CollectionConfigurations": [ { "CollectionName": "relu_activations
", "CollectionParameters": { "include_regex": "relu
", "save_interval": "500
", "end_step": "5000
" } } ] }, "DebugRulesConfigurations": [ { "RuleConfigurationName": "improper_activation_job
", "RuleEvaluatorImage": "552407032007.dkr.ecr.ap-south-1.amazonaws.com/sagemaker-debugger-rule-evaluator:latest
", "InstanceType": "ml.c4.xlarge
", "VolumeSizeInGB":400
, "RuleParameters": { "source_s3_uri": "s3://bucket/custom_rules.py
", "rule_to_invoke": "ImproperActivation
", "collection_names": "relu_activations
" } } ]
要查找用於使用調試器規則的可用 Docker 映像的完整列表,請參閱為內建或自訂規則使用偵錯器 Docker 映像。若要查找RuleParameters
,請參閱偵錯工具內建規則清單。