

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 配置文件
<a name="train-remote-decorator-config"></a>

Amaz SageMaker on Python 软件开发工具包支持为 AWS 基础设施原始类型设置默认值。管理员配置这些默认值后，将在支持 SageMaker Python SDK 调用时自动传递这些默认值 APIs。可将装饰器函数的参数放入配置文件中。这样一来，您便能将与基础设施相关的设置与代码库分离开来。有关 Remote 函数和方法的参数的更多信息，请参阅 [Remote 函数类和方法规范](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` 环境变量来覆盖这些文件的默认位置。

如果管理员定义的配置文件和用户定义的配置文件包含密钥，则将使用用户定义的文件中的值。