

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 組態檔案
<a name="train-remote-decorator-config"></a>

Amazon SageMaker Python SDK 支援設定 AWS 基礎設施基本類型的預設值。在管理員設定這些預設值之後，當 SageMaker Python SDK 呼叫支援的 API 時，系統會自動傳遞這些預設值。可將裝飾項目函式的引數置於組態檔案內部。這樣您就可以將與基礎設施相關的設定與代碼基底分隔開來。如需更多相關資訊了解遠端函式與方法的參數及引數，請參閱[遠端函式類別與方法規格](https://sagemaker.readthedocs.io/en/stable/remote_function/sagemaker.remote_function.html)。

您可以針對網路組態、IAM 角色、用於輸入與輸出資料的 Amazon S3 資料夾，以及組態檔案內部的標籤編輯基礎設施設定。當您使用 @remote 裝飾項目或 `RemoteExecutor` API 調用函式時，可運用組態檔案。

以下範例組態檔案定義相依性、資源以及其他引數。此範例組態檔案是用來調用使用 @remote 裝飾項目或 RemoteExecutor API 初始化的函式。

```
SchemaVersion: '1.0'
SageMaker:
  PythonSDK:
    Modules:
      RemoteFunction:
        Dependencies: 'path/to/requirements.txt'
        EnableInterContainerTrafficEncryption: true
        EnvironmentVariables: {'EnvVarKey': 'EnvVarValue'}
        ImageUri: '366666666666.dkr.ecr.us-west-2.amazonaws.com/my-image:latest'
        IncludeLocalWorkDir: true
        CustomFileFilter: 
          IgnoreNamePatterns:
          - "*.ipynb"
          - "data"
        InstanceType: 'ml.m5.large'
        JobCondaEnvironment: 'your_conda_env'
        PreExecutionCommands:
            - 'command_1'
            - 'command_2'
        PreExecutionScript: 'path/to/script.sh'
        RoleArn: 'arn:aws:iam::366666666666:role/MyRole'
        S3KmsKeyId: 'yourkmskeyid'
        S3RootUri: 's3://amzn-s3-demo-bucket/my-project'
        VpcConfig:
            SecurityGroupIds: 
            - 'sg123'
            Subnets: 
            - 'subnet-1234'
        Tags: [{'Key': 'yourTagKey', 'Value':'yourTagValue'}]
        VolumeKmsKeyId: 'yourkmskeyid'
```

@remote 裝飾項目與 `RemoteExecutor` 將在以下組態檔案查找 `Dependencies`：
+ 管理員定義的組態檔案。
+ 使用者定義的組態檔案。

這些組態檔案的預設位置取決於且相對於您的環境。下列代碼範例會傳回管理員與使用者組態檔案的預設位置。這些命令必須在您使用 SageMaker Python SDK 的相同環境執行。

```
import os
from platformdirs import site_config_dir, user_config_dir

#Prints the location of the admin config file
print(os.path.join(site_config_dir("sagemaker"), "config.yaml"))

#Prints the location of the user config file
print(os.path.join(user_config_dir("sagemaker"), "config.yaml"))
```

您可以透過分別針對管理員定義及使用者定義的組態檔案路徑設定 `SAGEMAKER_ADMIN_CONFIG_OVERRIDE` 與 `SAGEMAKER_USER_CONFIG_OVERRIDE` 環境變數，來覆寫這些檔案的預設位置。

如果系統管理員定義及使用者定義的組態檔案均存在金鑰，則會採用使用者定義檔案的值。