

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Avvia lavori di formazione con Debugger utilizzando Python SDK SageMaker
<a name="debugger-configuration-for-debugging"></a>

Per configurare uno stimatore SageMaker AI con SageMaker Debugger, usa Amazon [ SageMaker Python](https://sagemaker.readthedocs.io/en/stable) SDK e specifica i parametri specifici del Debugger. Per utilizzare appieno la funzionalità di debug, devi configurare tre parametri: `debugger_hook_config`, `tensorboard_output_config` e `rules`.

**Importante**  
Prima di creare ed eseguire il metodo di adattamento dello strumento di valutazione per avviare un processo di addestramento, assicurati di adattare lo script di addestramento seguendo le istruzioni riportate in [Adattamento dello script di addestramento per registrare un hook](debugger-modify-script.md).

## Creazione di SageMaker uno stimatore AI con parametri specifici del debugger
<a name="debugger-configuration-structure"></a>

Gli esempi di codice in questa sezione mostrano come costruire uno stimatore AI con i parametri specifici del Debugger. SageMaker 

**Nota**  
I seguenti esempi di codice sono modelli per la costruzione degli stimatori del framework AI e non sono direttamente eseguibili SageMaker . È necessario passare alle sezioni successive e configurare i parametri specifici di Debugger.

------
#### [ PyTorch ]

```
# An example of constructing a SageMaker AI PyTorch estimator
import boto3
import sagemaker
from sagemaker.pytorch import PyTorch
from sagemaker.debugger import CollectionConfig, DebuggerHookConfig, Rule, rule_configs

session=boto3.session.Session()
region=session.region_name

debugger_hook_config=DebuggerHookConfig(...)
rules=[
    Rule.sagemaker(rule_configs.built_in_rule())
]

estimator=PyTorch(
    entry_point="directory/to/your_training_script.py",
    role=sagemaker.get_execution_role(),
    base_job_name="debugger-demo",
    instance_count=1,
    instance_type="ml.p3.2xlarge",
    framework_version="1.12.0",
    py_version="py37",
    
    # Debugger-specific parameters
    debugger_hook_config=debugger_hook_config,
    rules=rules
)

estimator.fit(wait=False)
```

------
#### [ TensorFlow ]

```
# An example of constructing a SageMaker AI TensorFlow estimator
import boto3
import sagemaker
from sagemaker.tensorflow import TensorFlow
from sagemaker.debugger import CollectionConfig, DebuggerHookConfig, Rule, rule_configs

session=boto3.session.Session()
region=session.region_name

debugger_hook_config=DebuggerHookConfig(...)
rules=[
    Rule.sagemaker(rule_configs.built_in_rule()),
    ProfilerRule.sagemaker(rule_configs.BuiltInRule())
]

estimator=TensorFlow(
    entry_point="directory/to/your_training_script.py",
    role=sagemaker.get_execution_role(),
    base_job_name="debugger-demo",
    instance_count=1,
    instance_type="ml.p3.2xlarge",
    framework_version="2.9.0",
    py_version="py39",
    
    # Debugger-specific parameters
    debugger_hook_config=debugger_hook_config,
    rules=rules
)

estimator.fit(wait=False)
```

------
#### [ MXNet ]

```
# An example of constructing a SageMaker AI MXNet estimator
import sagemaker
from sagemaker.mxnet import MXNet
from sagemaker.debugger import CollectionConfig, DebuggerHookConfig, Rule, rule_configs

debugger_hook_config=DebuggerHookConfig(...)
rules=[
    Rule.sagemaker(rule_configs.built_in_rule())
]

estimator=MXNet(
    entry_point="directory/to/your_training_script.py",
    role=sagemaker.get_execution_role(),
    base_job_name="debugger-demo",
    instance_count=1,
    instance_type="ml.p3.2xlarge",
    framework_version="1.7.0",
    py_version="py37",
    
    # Debugger-specific parameters
    debugger_hook_config=debugger_hook_config,
    rules=rules
)

estimator.fit(wait=False)
```

------
#### [ XGBoost ]

```
# An example of constructing a SageMaker AI XGBoost estimator
import sagemaker
from sagemaker.xgboost.estimator import XGBoost
from sagemaker.debugger import CollectionConfig, DebuggerHookConfig, Rule, rule_configs

debugger_hook_config=DebuggerHookConfig(...)
rules=[
    Rule.sagemaker(rule_configs.built_in_rule())
]

estimator=XGBoost(
    entry_point="directory/to/your_training_script.py",
    role=sagemaker.get_execution_role(),
    base_job_name="debugger-demo",
    instance_count=1,
    instance_type="ml.p3.2xlarge",
    framework_version="1.5-1",

    # Debugger-specific parameters
    debugger_hook_config=debugger_hook_config,
    rules=rules
)

estimator.fit(wait=False)
```

------
#### [ Generic estimator ]

```
# An example of constructing a SageMaker AI generic estimator using the XGBoost algorithm base image
import boto3
import sagemaker
from sagemaker.estimator import Estimator
from sagemaker import image_uris
from sagemaker.debugger import CollectionConfig, DebuggerHookConfig, Rule, rule_configs

debugger_hook_config=DebuggerHookConfig(...)
rules=[
    Rule.sagemaker(rule_configs.built_in_rule())
]

region=boto3.Session().region_name
xgboost_container=sagemaker.image_uris.retrieve("xgboost", region, "1.5-1")

estimator=Estimator(
    role=sagemaker.get_execution_role()
    image_uri=xgboost_container,
    base_job_name="debugger-demo",
    instance_count=1,
    instance_type="ml.m5.2xlarge",
    
    # Debugger-specific parameters
    debugger_hook_config=debugger_hook_config,
    rules=rules
)

estimator.fit(wait=False)
```

------

Configura i seguenti parametri per attivare SageMaker Debugger:
+ `debugger_hook_config`(un oggetto di [https://sagemaker.readthedocs.io/en/stable/api/training/debugger.html#sagemaker.debugger.DebuggerHookConfig](https://sagemaker.readthedocs.io/en/stable/api/training/debugger.html#sagemaker.debugger.DebuggerHookConfig)): necessario per attivare l'hook nello script di addestramento adattato durante[Adattamento dello script di addestramento per registrare un hook](debugger-modify-script.md), configurare il SageMaker training launcher (estimatore) per raccogliere i tensori di output dal processo di addestramento e salvare i tensori nel bucket S3 protetto o nel computer locale. Per informazioni su come configurare il parametro `debugger_hook_config`, consulta [Configurazione SageMaker di Debugger per salvare i tensori](debugger-configure-hook.md).
+ `rules`(un elenco di [https://sagemaker.readthedocs.io/en/stable/api/training/debugger.html#sagemaker.debugger.Rule](https://sagemaker.readthedocs.io/en/stable/api/training/debugger.html#sagemaker.debugger.Rule)oggetti): configura questo parametro per attivare le regole integrate del SageMaker Debugger che desideri eseguire in tempo reale. Le regole integrate sono logiche che eseguono automaticamente il debug del progresso di addestramento del modello e individuano i problemi di addestramento analizzando i tensori di output salvati nel bucket S3 protetto. Per informazioni su come configurare il parametro `rules`, consulta [Come configurare le regole integrate di Debugger](use-debugger-built-in-rules.md). Per trovare un elenco completo delle regole integrate per il debug dei tensori di output, consulta [Regola Debugger](debugger-built-in-rules.md#debugger-built-in-rules-Rule). Se desideri creare una logica personalizzata per rilevare eventuali problemi di addestramento, consulta [Creazione di regole personalizzate utilizzando la libreria client di Debugger](debugger-custom-rules.md).
**Nota**  
Le regole integrate sono disponibili solo tramite SageMaker istanze di formazione. Non è possibile utilizzarle in modalità locale.
+ `tensorboard_output_config`(un oggetto di [https://sagemaker.readthedocs.io/en/stable/api/training/debugger.html#sagemaker.debugger.TensorBoardOutputConfig](https://sagemaker.readthedocs.io/en/stable/api/training/debugger.html#sagemaker.debugger.TensorBoardOutputConfig)) — Configura SageMaker Debugger per raccogliere i tensori di output nel formato TensorBoard compatibile con -e salvarli nel percorso di output S3 specificato nell'oggetto. `TensorBoardOutputConfig` Per ulteriori informazioni, consulta [Visualizza i tensori di output di Amazon SageMaker Debugger in TensorBoard](debugger-enable-tensorboard-summaries.md).
**Nota**  
`tensorboard_output_config` deve essere configurato con il parametro `debugger_hook_config`, che richiede anche di adattare lo script di addestramento aggiungendo l'hook `sagemaker-debugger`.

**Nota**  
SageMaker Debugger salva in modo sicuro i tensori di output nelle sottocartelle del bucket S3. Ad esempio, il formato dell'URI del bucket S3 predefinito nel tuo account è `s3://amzn-s3-demo-bucket-sagemaker-<region>-<12digit_account_id>/<base-job-name>/<debugger-subfolders>/`. Esistono due sottocartelle create da Debugger:, e. SageMaker `debug-output` `rule-output` Se aggiungi il parametro `tensorboard_output_config`, troverai anche la cartella `tensorboard-output`.

Consulta i seguenti argomenti per scoprire altri esempi su come configurare in dettaglio i parametri specifici di Debugger.

**Topics**
+ [Creazione di SageMaker uno stimatore AI con parametri specifici del debugger](#debugger-configuration-structure)
+ [Configurazione SageMaker di Debugger per salvare i tensori](debugger-configure-hook.md)
+ [Come configurare le regole integrate di Debugger](use-debugger-built-in-rules.md)
+ [Disattivazione di Debugger](debugger-turn-off.md)
+ [Metodi utili della classe di stima AI per Debugger SageMaker](debugger-estimator-classmethods.md)