Installing and Configuring Trains Agent

To use Trains Agent, you must first install it. You may also need to configure Trains Agent if you are using:

  • A self-hosted Trains Server with Trains Agent.
  • The demo Trains Server with Trains Agent, and want to specify any of the Trains Agent configuration options, for example to set Git, package manager, worker, or Docker settings.

If you do not want to specify any Trains Agent configuration options, then Trains Agent is set up to work with the demo Trains Server ( by default and does not require an additional configuration.

Once installed, Trains Agent uses a cache folder to cache pip packages, apt packages and cloned repositories. The default cache folder in Linux is ~/.trains.

A configuration file may already exist.

Trains and Trains Agent use the same configuration file, but not all the same configuration options.

If you previously configured Trains, for example configured it for a self-hosted Trains Server, then you have a configuration file.

Installing Trains Agent

To install Trains Agent:

Execute the following command:

pip install trains-agent

Configuring Trains Agent

Initializing a new Trains Agent configuration file

To initialize a new Trains Agent configuration file, do the following:

  1. Open a terminal session in Linux or a command prompt session in Microsoft Windows.
  2. In your terminal session, run the setup wizard by executing the following command:
    trains-agent init
    If the setup wizard's response indicates you already have a configuration file, you must edit it. The wizard does not edit or overwrite existing configuration files.
  3. At the prompt, enter the URL for your Trains Server web server.

    You must use a secure protocol, "https". Do not use "http".

    Enter the url of the trains-server’s Web service, for example: http://localhost:8080
    Web Application Host configured to: []
  4. Enter the API server (press Enter to accept the default value which is based on your previous response):
    API Host configured to: 
  5. Enter the file server (press Enter to accept the default value which is based on your previous response):
    File Store Host configured to:
    The wizard responses with your configuration and directs you to your Trains Server's, Trains Web-App to create Trains credentials.
    TRAINS Hosts configuration:
    Web App: <your web server url>
    API: <your api server url>
    File Store: <your file server url>
    Please create new credentials using the web app: <your web server url>/profile
    In the Admin page, press "Create new credentials", then press "Copy to clipboard"
    Paste credentials here:
  6. At the command prompt Paste credentials here:, copy and paste the Trains credentials you create as follows:
    1. Click the hyperlink for your Trains Web-App, Trains Web-App.
    2. If you are not logged in, then login.

      Why would a login not be required?

      If your Trains Server is not configured for web login authentication, no login is required. You can add web login authentication, see Configuring Web Login Authentication on the "Configuring Trains Server" page.

    3. Click the PROFILE page.
    4. Click Create new credentials.
    5. Click Copy to clipboard.
    6. In your terminal session, paste your credentials and press Enter.

    The configuration is verified. The location of your configuration file appears.

    Verifying credentials ...
    Credentials verified!

  7. Enter your Git user name and password.

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

    Trains Agent configuration is completed.

    New configuration stored in /home/user/trains.conf
    TRAINS-AGENT setup completed successfully.

Your Trains Agent configuration file is saved. Its location depends upon your operating system:

  • Linux - ~/trains.conf
  • Mac - $HOME/trains.conf
  • Windows - \User\<username>\trains.conf

Adding Trains Agent settings to a Trains configuration file

To add Trains Agent settings to a Trains configuration file, do the following:

If a Trains configuration file already exists, edit it and add the Trains Agent settings, including Git credentials, and the agent section.

To edit a Trains configuration file, do the following:

  1. Open your Trains configuration file for editing. Depending upon your operating system, it is:
    • Linux - ~/trains.conf
    • Mac - $HOME/trains.conf
    • Windows - \User\<username>\trains.conf
  2. After the api section, add the following for your Git credentials, replacing .
    # Set GIT user/pass credentials
    # leave blank for GIT SSH credentials
  3. After the Git credentials (see the previous step), add the following agent section:
    agent {
        # unique name of this worker, if None, created based on hostname:process_id
        # Override with os environment: TRAINS_WORKER_NAME
        # worker_id: "trains-agent-machine1:gpu0"
        worker_id: ""
        # worker name, replaces the hostname when creating a unique name for this worker
        # Override with os environment: TRAINS_WORKER_ID
        # worker_name: "trains-agent-machine1"
        worker_name: ""
        # Set GIT user/pass credentials for cloning code, leave blank for GIT SSH credentials.
        # git_user: ""
        # git_pass: ""
        # select python package manager:
        # currently supported pip and conda
        # poetry is used if pip selected and repository contains poetry.lock file
        package_manager: {
            # supported options: pip, conda
            type: pip,
            # virtual environment inheres packages from system
            system_site_packages: false,
            # install with --upgrade
            force_upgrade: false,
            # additional artifact repositories to use when installing python packages
            # extra_index_url: [""]
            extra_index_url: []
            # additional conda channels to use when installing with conda package manager
            conda_channels: ["defaults", "conda-forge", "pytorch", ]
        # target folder for virtual environments builds, created when executing experiment
        venvs_dir = ~/.trains/venvs-builds
        # cached git clone folder
        vcs_cache: {
            enabled: true,
            path: ~/.trains/vcs-cache
        # use venv-update in order to accelerate python virtual environment building
        # Still in beta, turned off by default
        venv_update: {
            enabled: false,
        # cached folder for specific python package download (used for pytorch package caching)
        pip_download_cache {
            enabled: true,
            path: ~/.trains/pip-download-cache
        translate_ssh: true,
        # reload configuration file every daemon execution
        reload_config: false,
        # pip cache folder used mapped into docker, for python package caching
        docker_pip_cache = ~/.trains/pip-cache
        # apt cache folder used mapped into docker, for ubuntu package caching
        docker_apt_cache = ~/.trains/apt-cache
        default_docker: {
            # default docker image to use when running in docker mode
            image: "nvidia/cuda"
            # optional arguments to pass to docker image
            # arguments: ["--ipc=host", ]
        # cuda versions used for solving pytorch wheel packages
        # should be detected automatically. Override with os environment CUDA_VERSION / CUDNN_VERSION
        # cuda_version: 10.1
        # cudnn_version: 7.6

Your Trains Agent configuration file is saved.

Next Steps