

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# JSON (AWS CLI)
<a name="debugger-built-in-rules-api.CLI"></a>

**catatan**  
Amazon SageMaker Debugger tidak lagi terbuka untuk pelanggan baru. Pelanggan yang sudah ada dapat terus menggunakan layanan seperti biasa. AWS terus berinvestasi dalam peningkatan keamanan dan ketersediaan untuk Debugger, tetapi kami tidak berencana untuk memperkenalkan fitur baru. Untuk informasi selengkapnya, lihat [Perubahan ketersediaan debugger](debugger-availability-change.md). 

Aturan bawaan Amazon SageMaker Debugger dapat dikonfigurasi untuk pekerjaan pelatihan menggunakan [ DebugHookConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugHookConfig.html), [ DebugRuleConfiguration](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugRuleConfiguration.html), [ ProfilerConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerConfig.html), dan [ ProfilerRuleConfiguration ](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerRuleConfiguration.html) objek melalui operasi [ CreateTrainingJob ](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html) API SageMaker AI. Anda perlu menentukan URI gambar yang tepat di `RuleEvaluatorImage` parameter, dan contoh berikut memandu Anda melalui cara mengatur string JSON untuk diminta [ CreateTrainingJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html).

Kode berikut menunjukkan template JSON lengkap untuk menjalankan pekerjaan pelatihan dengan pengaturan yang diperlukan dan konfigurasi Debugger. Simpan template sebagai file JSON di direktori kerja Anda dan jalankan pekerjaan pelatihan menggunakan AWS CLI. Misalnya, simpan kode berikut sebagai`debugger-training-job-cli.json`.

**catatan**  
Pastikan Anda menggunakan gambar kontainer Docker yang benar. Untuk menemukan gambar Kontainer AWS Pembelajaran Mendalam, lihat Gambar Wad [ ah Pembelajaran Mendalam yang Tersedia](https://github.com/aws/deep-learning-containers/blob/master/available_images.md). Untuk menemukan daftar lengkap gambar Docker yang tersedia untuk menggunakan aturan Debugger, lihat. [Gambar Docker untuk aturan Debugger](debugger-reference.md#debugger-docker-images-rules)

```
{
   "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}}
   }
}
```

Setelah menyimpan file JSON, jalankan perintah berikut di terminal Anda. (Gunakan `!` di awal baris jika Anda menggunakan notebook Jupyter.)

```
aws sagemaker create-training-job --cli-input-json file://debugger-training-job-cli.json
```

## Untuk mengkonfigurasi aturan Debugger untuk parameter model debugging
<a name="debugger-built-in-rules-api-debug.CLI"></a>

Contoh kode berikut menunjukkan cara mengonfigurasi `VanishingGradient` aturan bawaan menggunakan SageMaker API ini. 

**Untuk mengaktifkan Debugger untuk mengumpulkan tensor keluaran **

Tentukan konfigurasi hook Debugger sebagai berikut:

```
"DebugHookConfig": {
    "S3OutputPath": "{{s3://<default-bucket>/<training-job-name>/debug-output}}",
    "CollectionConfigurations": [
        {
            "CollectionName": "{{gradients}}",
            "CollectionParameters" : {
                "save_interval": "{{500}}"
            }
        }
    ]
}
```

Ini akan membuat pekerjaan pelatihan menyimpan koleksi tensor,`gradients`, setiap `save_interval` 500 langkah. Untuk menemukan `CollectionName` nilai yang tersedia, lihat Koleksi [ Debugger ](https://github.com/awslabs/sagemaker-debugger/blob/master/docs/api.md#built-in-collections) di Built-in dokumentasi pustaka klien * SMDebug. * Untuk menemukan kunci dan nilai `CollectionParameters` parameter yang tersedia, lihat [`sagemaker.debugger.CollectionConfig`](https://sagemaker.readthedocs.io/en/stable/api/sagemaker_core.html) kelas dalam dokumentasi * SageMaker Python SDK*.

**Untuk mengaktifkan aturan Debugger untuk men-debug tensor keluaran **

Contoh `DebugRuleConfigurations` API berikut menunjukkan cara menjalankan `VanishingGradient` aturan bawaan pada `gradients` koleksi yang disimpan.

```
"DebugRuleConfigurations": [
    {
        "RuleConfigurationName": "{{VanishingGradient}}",
        "RuleEvaluatorImage": "{{503895931360.dkr.ecr.us-east-1.amazonaws.com/sagemaker-debugger-rules:latest}}",
        "RuleParameters": {
            "rule_to_invoke": "{{VanishingGradient}}",
            "threshold": "{{20.0}}"
        }
    }
]
```

Dengan konfigurasi seperti yang ada di sampel ini, Debugger memulai pekerjaan evaluasi aturan untuk pekerjaan pelatihan Anda menggunakan `VanishingGradient` aturan pada pengumpulan `gradients` tensor. Untuk menemukan daftar lengkap gambar Docker yang tersedia untuk menggunakan aturan Debugger, lihat. [Gambar Docker untuk aturan Debugger](debugger-reference.md#debugger-docker-images-rules) Untuk menemukan pasangan kunci-nilai`RuleParameters`, lihat. [Daftar aturan bawaan Debugger](debugger-built-in-rules.md)

## Untuk mengonfigurasi aturan bawaan Debugger untuk sistem profil dan metrik kerangka kerja
<a name="debugger-built-in-rules-api-profile.CLI"></a>

Kode contoh berikut menunjukkan cara menentukan operasi ProfilerConfig API untuk mengaktifkan sistem pengumpulan metrik dan kerangka kerja.

**Untuk mengaktifkan profil Debugger untuk mengumpulkan metrik sistem dan kerangka kerja **

------
#### [ Target Step ]

```
"ProfilerConfig": { 
    // Optional. Path to an S3 bucket to save profiling outputs
    "S3OutputPath": "{{s3://<default-bucket>/<training-job-name>/profiler-output}}", 
    // Available values for ProfilingIntervalInMilliseconds: 100, 200, 500, 1000 (1 second), 5000 (5 seconds), and 60000 (1 minute) milliseconds.
    "ProfilingIntervalInMilliseconds": {{500}}, 
    "ProfilingParameters": {
        "DataloaderProfilingConfig": "{ \"StartStep\": {{5}}, \"NumSteps\": {{3}}, \"MetricsRegex\": \".*\" }",
        "DetailedProfilingConfig": "{ \"StartStep\": {{5}}, \"NumSteps\": {{3}} }",
        // For PythonProfilingConfig,
        // available ProfilerName options: cProfile, Pyinstrument
        // available cProfileTimer options only when using cProfile: cpu, off_cpu, total_time
        "PythonProfilingConfig": "{ \"StartStep\": {{5}}, \"NumSteps\": {{3}}, \"ProfilerName\": \"{{cProfile}}\", \"cProfileTimer\": \"{{total_time}}\" }",
        // Optional. Local path for profiling outputs
        "LocalPath": "/opt/ml/output/profiler/" 
    }
}
```

------
#### [ Target Time Duration ]

```
"ProfilerConfig": { 
    // Optional. Path to an S3 bucket to save profiling outputs
    "S3OutputPath": "{{s3://<default-bucket>/<training-job-name>/profiler-output}}", 
    // Available values for ProfilingIntervalInMilliseconds: 100, 200, 500, 1000 (1 second), 5000 (5 seconds), and 60000 (1 minute) milliseconds.
    "ProfilingIntervalInMilliseconds": {{500}},
    "ProfilingParameters": {
        "DataloaderProfilingConfig": "{ \"StartTimeInSecSinceEpoch\": {{12345567789}}, \"DurationInSeconds\": {{10}}, \"MetricsRegex\": \".*\" }",
        "DetailedProfilingConfig": "{ \"StartTimeInSecSinceEpoch\": {{12345567789}}, \"DurationInSeconds\": {{10}} }",
        // For PythonProfilingConfig,
        // available ProfilerName options: cProfile, Pyinstrument
        // available cProfileTimer options only when using cProfile: cpu, off_cpu, total_time
        "PythonProfilingConfig": "{ \"StartTimeInSecSinceEpoch\": {{12345567789}}, \"DurationInSeconds\": {{10}}, \"ProfilerName\": \"{{cProfile}}\", \"cProfileTimer\": \"{{total_time}}\" }",
        // Optional. Local path for profiling outputs
        "LocalPath": "/opt/ml/output/profiler/"  
    }
}
```

------

**Untuk mengaktifkan aturan Debugger untuk membuat profil metrik **

Kode contoh berikut menunjukkan cara mengkonfigurasi `ProfilerReport` aturan.

```
"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}}"
        }
    }
]
```

Untuk menemukan daftar lengkap gambar Docker yang tersedia untuk menggunakan aturan Debugger, lihat. [Gambar Docker untuk aturan Debugger](debugger-reference.md#debugger-docker-images-rules) Untuk menemukan pasangan kunci-nilai`RuleParameters`, lihat. [Daftar aturan bawaan Debugger](debugger-built-in-rules.md)

## Perbarui konfigurasi profil Debugger menggunakan API `UpdateTrainingJob`
<a name="debugger-updatetrainingjob-api.CLI"></a>

Konfigurasi profil debugger dapat diperbarui saat pekerjaan pelatihan Anda berjalan dengan menggunakan operasi [ UpdateTrainingJob ](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateTrainingJob.html) API. Konfigurasikan [ ProfilerRuleConfiguration ](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerRuleConfiguration.html) objek [ ProfilerConfig ](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerConfig.html) dan baru, dan tentukan nama pekerjaan pelatihan ke `TrainingJobName` parameter.

```
{
    "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}}"
}
```

## Tambahkan konfigurasi aturan kustom Debugger ke API `CreateTrainingJob`
<a name="debugger-custom-rules-api.CLI"></a>

Aturan khusus dapat dikonfigurasi untuk pekerjaan pelatihan menggunakan [ DebugRuleConfiguration ](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugRuleConfiguration.html) objek [ DebugHookConfig ](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugHookConfig.html) dan dalam operasi [ CreateTrainingJob ](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html) API. Contoh kode berikut menunjukkan cara mengonfigurasi `ImproperActivation` aturan khusus yang ditulis dengan pustaka * smdebug menggunakan * operasi SageMaker API ini. Contoh ini mengasumsikan bahwa Anda telah menulis aturan khusus di * file * custom\_rules.py dan mengunggahnya ke bucket Amazon S3. Contoh ini menyediakan gambar Docker pra-build yang dapat Anda gunakan untuk menjalankan aturan kustom Anda. Ini terdaftar di[URI gambar Amazon SageMaker Debugger untuk evaluator aturan khusus](debugger-reference.md#debuger-custom-rule-registry-ids). Anda menentukan alamat registri URL untuk gambar Docker yang dibuat sebelumnya dalam parameter. `RuleEvaluatorImage`

```
"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}}"
        }
    }
]
```

Untuk menemukan daftar lengkap gambar Docker yang tersedia untuk menggunakan aturan Debugger, lihat. [Gambar Docker untuk aturan Debugger](debugger-reference.md#debugger-docker-images-rules) Untuk menemukan pasangan kunci-nilai`RuleParameters`, lihat. [Daftar aturan bawaan Debugger](debugger-built-in-rules.md)