Configuring Trains for Trains Server

After deploying Trains Server, you must configure Trains for it by either:

  • Initializing a new Trains configuration file using our interactive setup.
  • Adding Trains settings to an existing Trains configuration file.

    Why would a Trains configuration file already exist?

    If you previously configured Trains for our demo Trains Server, or installed and configure Trains Agent, you may have an existing configuration file. This is because Trains and Trains Agent use the same configuration file, but not all the same configuration options.

Initializing a new Trains configuration file

Use our trains-init setup wizard to initialize a new Trains configuration file.

If you already have a configuration file, the setup wizard will notify you and you can add Trains settings to an existing Trains configuration file.

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

  1. Open a terminal session.
  2. In your terminal session, run the setup wizard by executing the following command:
    trains-init
    If the setup wizard's response indicates you already have a configuration file, then perform the steps in the Adding Trains settings to an existing Trains configuration file section. The wizard does not edit or overwrite existing configuration files.

    Additional Trains configuration files

    You can create additional Trains configuration files using the --file option of trains-init.

    For example, create a configuration file to use inside Docker containers when executing a Task:
    trains-init --file MyOtherTrains.conf
    and then specify it using the TRAINS_CONFIG_FILE environment variable inside the container:
    TRAINS_CONFIG_FILE = MyOtherTrains.conf
    For more information about running experiments inside Docker containers, see Docker mode in the "Trains Agent Reference" section.

  3. TRAINS SDK setup process
    
    Please create new trains credentials through the profile page in your trains web app (e.g. http://localhost:8080/profile)
    In the profile page, press "Create new credentials", then press "Copy to clipboard".
    
    Paste copied configuration here:
  4. At the command prompt Paste copied configuration here:, copy and paste the Trains credentials you create as follows:
    1. Open the Trains Web-App in your browser (if you are using are demo Trains Server, go ).
    2. Click the PROFILE page.
    3. Click Create new credentials.
    4. Click Copy to clipboard.
    5. In your terminal session, paste your credentials and press Enter.
  5. Enter the API server (press Enter to accept the default value which is based on your Trains credentials):
    Detected credentials key="********************" secret="*******"
    API Host configured to: [https://demoapi.trains.allegro.ai]
  6. Enter your Trains Server web server (press Enter to accept the default value which is based on your previous response):
    demoapi.trains.allegro.ai is the api server, we need the web server. Replacing 'demoapi.' with 'demoapp.'
    Web Application Host configured to: [https://demoapp.trains.allegro.ai]
  7. Enter your Trains file server (press Enter to accept the default value which is based on your previous response):
    File Store Host configured to: [https://demofiles.trains.allegro.ai]
  8. Your Trains configuration file is verified and created.
    TRAINS Hosts configuration:
    Web App: https://demoapp.trains.allegro.ai
    API: https://demoapi.trains.allegro.ai
    File Store: https://demofiles.trains.allegro.ai
    
    Verifying credentials ...
    Credentials verified!
    
    New configuration stored in /home/<username>/trains.conf
    TRAINS setup completed successfully.
    The configuration file's location depends upon your operating system:
    • Linux - ~/trains.conf
    • Mac - $HOME/trains.conf
    • Windows - \User\<username>\trains.conf

    Your Trains configuration file is saved.

Adding Trains settings to an existing Trains configuration file

If a Trains configuration file already exists, add Trains settings to it. Add an api section containing your Trains Server web server, API server, and file server URLs, and your Trains credentials from the Trains Web-App.

The URLs for your Trains Server are required:

  • Trains Server web server
  • Trains Server API server
  • Trains Server file server

These may be localhost, your domain, or a sub-domain of your domain.

To add Trains settings to an existing 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. Add an api section to your configuration file containing the following (for a complete configuration file example, see the trains.conf sample in the trains repository):
    api {
        # server URLs
        api_server: "<api_server_url>"
        web_server: "<web_server_url>"
        files_server: "<file_server_url>"
    
        # Credentials are generated using the webapp
        credentials {"access_key": "******************", "secret_key": "*******************"}
        }

    For example:

    • To use localhost:
      api {
            # API server on port 8008
            api_server: "http://localhost:8008"
            # web_server on port 8080
            web_server: "http://localhost:8080"
            # file server on port 8081
            files_server: "http://localhost:8081"
        }
    • To use a domain named mydomain.com:
      api {
          api_server: "https://api.mydomain.com:8008"
          web_server: "https://app.mydomain.com:8080"
          files_server: "https://files.mydomain.com:8081"
      }
    • To use a sub-domain named trains.mydomain.com (if you use a sub-domain, no port is required):
      api {
          api_server: "https://api.trains.mydomain.com"
          web_server: "https://app.trains.mydomain.com"
          files_server: "https://files.trains.mydomain.com"
      }

      Configuring Trains Server for sub-domains

      To configure sub-domains on Trains Server, see Configuring Sub-domains and load balancers on the "Configuring Trains Server" page.

  3. In the sdk.storage.cache section, add the size section highlighted below:
    
    sdk {
        # TRAINS - default SDK configuration
    
        storage {
            cache {
                # Defaults to system temp folder / cache
                default_base_dir: "~/.trains/cache"
    
    size { # max_used_bytes = -1 min_free_bytes = 10GB # cleanup_margin_percent = 5% }
    } direct_access: [ # Objects matching are considered to be available for direct access, i.e. they will not be downloaded # or cached, and any download request will return a direct reference. # Objects are specified in glob format, available for url and content_type. { url: "file://*" } # file-urls are always directly referenced ] }
  4. Save your Trains configuration file. Trains is now configured for your Trains Server.

Next Steps

  • You can now use the Trains Python Client Package in your Python experiment scripts and your Trains Server. When you run an experiment script, the experiment is stored in your Trains Server.
  • If you install and configure Trains Agent for your Trains Server, you can use workers and queues to manage your experimentation.