

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>

Aturan bawaan Amazon SageMaker Debugger dapat dikonfigurasi untuk pekerjaan pelatihan menggunakan [DebugHookConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugHookConfig.html), [DebugRuleConfiguration[ProfilerConfig](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerConfig.html)](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DebugRuleConfiguration.html), dan [ProfilerRuleConfiguration](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ProfilerRuleConfiguration.html)objek melalui operasi SageMaker AI [CreateTrainingJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTrainingJob.html)API. Anda perlu menentukan URI gambar yang tepat dalam `RuleEvaluatorImage` parameter, dan contoh berikut memandu Anda melalui cara mengatur string JSON untuk meminta. [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 AWS Deep Learning Container, lihat Gambar [Deep Learning Containers 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 mengonfigurasi 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 mengumpulkan tensor keluaran**

Tentukan konfigurasi kait 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 menghemat koleksi tensor,`gradients`, setiap `save_interval` 500 langkah. Untuk menemukan `CollectionName` nilai yang tersedia, lihat [ Built-in Koleksi Debugger di dokumentasi pustaka](https://github.com/awslabs/sagemaker-debugger/blob/master/docs/api.md#built-in-collections) klien *SMDebug*. Untuk menemukan kunci dan nilai `CollectionParameters` parameter yang tersedia, lihat [https://sagemaker.readthedocs.io/en/stable/api/training/debugger.html#sagemaker.debugger.CollectionConfig](https://sagemaker.readthedocs.io/en/stable/api/training/debugger.html#sagemaker.debugger.CollectionConfig)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 dalam sampel ini, Debugger memulai pekerjaan evaluasi aturan untuk pekerjaan pelatihan Anda menggunakan `VanishingGradient` aturan pada kumpulan tensor. `gradients` 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 untuk`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>

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

**Untuk mengaktifkan profiling 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 untuk`RuleParameters`, lihat. [Daftar aturan bawaan Debugger](debugger-built-in-rules.md)

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

Konfigurasi profiling debugger dapat diperbarui saat tugas pelatihan Anda berjalan dengan menggunakan operasi API. [UpdateTrainingJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateTrainingJob.html) Konfigurasikan baru [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, 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 khusus 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 kustom yang ditulis dengan pustaka *smdebug* menggunakan operasi SageMaker API ini. Contoh ini mengasumsikan bahwa Anda telah menulis aturan kustom dalam file *custom\_rules.py* dan mengunggahnya ke bucket Amazon S3. Contoh ini menyediakan gambar Docker pra-bangun 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 image Docker yang sudah 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 untuk`RuleParameters`, lihat. [Daftar aturan bawaan Debugger](debugger-built-in-rules.md)