跳到主要内容

设置

安装

注意

如果 ClearML 之前已配置,请按照此处的说明添加 ClearML Agent 特定配置

要安装 ClearML Agent,请执行

pip install clearml-agent
信息

将 ClearML Agent 作为系统 Python 包安装,而不是在 Python 虚拟环境中安装。在虚拟环境模式或 Conda 环境模式下运行的 Agent 需要创建虚拟环境,而当它从虚拟环境运行时则无法做到这一点。

配置

  1. 在终端会话中,执行

    clearml-agent init

    设置向导会提示输入 ClearML 凭据(有关获取凭据的信息,请参阅此处)。

    Please create new clearml credentials through the settings page in your `clearml-server` web app, 
    or create a free account at https://app.clear.ml/settings/webapp-configuration

    In the settings > workspace page, press "Create new credentials", then press "Copy to clipboard".

    Paste copied configuration here:

    如果设置向导的响应表明配置文件已存在,请按照此处的说明操作。向导不会编辑或覆盖现有配置文件。

  2. 在命令提示符 Paste copied configuration here: 处,粘贴 ClearML 凭据并按 Enter 键。设置向导会确认凭据。

    Detected credentials key="********************" secret="*******"
  3. Enter 键接受默认服务器 URL(从凭据中检测到),或输入 ClearML Web 服务器 URL。

    必须使用安全协议 https。请勿使用 http。

    WEB Host configured to: [https://app.clear.ml] 
    注意

    如果您使用的是自托管的 ClearML Server,默认 URL 将使用您的域名。

  4. 对 API、URL 和文件服务器执行与上述相同的操作。

  5. 向导会响应显示您的配置

    CLEARML Hosts configuration:
    Web App: https://app.clear.ml
    API: https://api.clear.ml
    File Store: https://files.clear.ml

    Verifying credentials ...
    Credentials verified!
  6. 输入默认输出 URI。模型检查点(快照)和任务产物将存储在此输出位置。

    Default Output URI (used to automatically store models and artifacts): (N)one/ClearML (S)erver/(C)ustom [None]
  7. 输入您的 Git 用户名和密码。如果使用 SSH 密钥认证或仅使用公共仓库,请留空。

    这是 Agent 克隆仓库所必需的。

    Enter git username for repository cloning (leave blank for SSH key authentication): []
    Enter password for user '<username>':

    设置向导会确认您的 git 凭据。

    Git repository cloning will be using user=<username> password=<password>        
  8. 输入一个额外的产物仓库,如果不需要,则按 Enter 键。

    这是安装 pypi 中找不到的 Python 包所必需的。

    Enter additional artifact repository (extra-index-url) to use when installing python packages (leave blank if not required):

    设置向导完成。

    New configuration stored in /home/<username>/clearml.conf
    CLEARML-AGENT setup completed successfully.

    配置文件的位置取决于操作系统

    • Linux - ~/clearml.conf
    • Mac - $HOME/clearml.conf
    • Windows - \User\<username>\clearml.conf
  9. (可选)为 ClearML Agent 配置 ClearML 选项(默认 docker、包管理器等)。请参阅ClearML 配置参考ClearML Agent 环境变量参考

注意

ClearML 企业版服务器提供一个配置库,其内容会分类应用于 Agent 本地配置之上

将 ClearML Agent 添加到配置文件

如果 clearml.conf 文件已存在,请向其中添加一些 ClearML Agent 特定配置。

将 ClearML Agent 添加到 ClearML 配置文件

  1. 打开 ClearML 配置文件进行编辑。根据操作系统,文件位于

    • Linux - ~/clearml.conf
    • Mac - $HOME/clearml.conf
    • Windows - \User\<username>\clearml.conf
  2. api 部分之后,添加您的 agent 部分。例如

    agent {
    # Set GIT user/pass credentials (if user/pass are set, GIT protocol will be set to https)
    git_user=""
    git_pass=""
    # all other domains will use public access (no user/pass). Default: always send user/pass for any VCS domain
    git_host=""

    # Force GIT protocol to use SSH regardless of the git url (Assumes GIT user/pass are blank)
    force_git_ssh_protocol: false

    # unique name of this worker, if None, created based on hostname:process_id
    # Overridden with os environment: CLEARML_WORKER_NAME
    worker_id: ""
    }

    在此处查看包含 agent 部分的完整 ClearML Agent 配置文件示例。

  3. 保存配置。

动态环境变量

动态 ClearML Agent 环境变量可用于覆盖 clearml.conf 文件中agent 部分出现的任何配置设置。

环境变量的名称应为 CLEARML_AGENT__AGENT__<configuration-path>,其中 <configuration-path> 代表正在设置的配置字段的完整路径。配置路径的元素应通过 __(双下划线)分隔。例如,设置 CLEARML_AGENT__AGENT__DEFAULT_DOCKER__IMAGE 环境变量可部署 Agent,使其使用的 docker 镜像不同于 clearml.conf 中 agent.default_docker.image 指定的值。

注意事项
  • 由于配置字段可能包含可由 JSON 解析的值,请确保始终引用字符串(否则 Agent 可能无法解析它们)
  • 为了符合环境变量标准,建议仅在环境变量键中使用大写字符。因此,ClearML Agent 总是会将动态环境变量键中指定的配置路径转换为小写,然后使用环境变量值覆盖配置值。