For the complete documentation index, see llms.txt. This page is also available as Markdown.

Training Your First Model

Introduction

In this tutorial, we describe the recommended way to train a simple machine learning model on the Apolo platform. As our ML engineers prefer PyTorch over other ML frameworks, we show the training and evaluation of one of the basic PyTorch examples.

We assume that you have already signed up to the platform, installed the Apolo CLI, and logged in to the platform (see Getting Started).

We base our example on the Classifying Names with a Character-Level RNN tutorial.

Initializing a new flow

To simplify working with Apolo Platform and to help establish the best practices in the ML environment, we provide a flow template. This template consists of the recommended directories and files. It's designed to operate smoothly with our base environment.

To use it, install the cookiecutter package and initialize cookiecutter-neuro-project:

pipx install cookiecutter
cookiecutter gh:neuro-inc/cookiecutter-neuro-project --checkout release

You will then need to provide some information about the new flow:

[1/6] flow_name (My flow): Apolo Tutorial
[2/6] flow_description ():
[3/6] flow_dir (apolo tutorial): apolo-tutorial
[4/6] flow_id (apolo_tutorial):
[5/6] code_directory (modules): rnn
[6/6] preserve Apolo Flow template hints (yes):

Flow configuration structure

After you execute the command mentioned above, you get the following structure:

When you run a job (for example, via apolo-flow run jupyter), the directories are mounted to the job as follows:

Mount Point
Description
Storage URI

/project/data/

Training / testing data

storage:apolo_tutorial/data/

/project/rnn/

User's Python code

storage:apolo_tutorial/rnn/

/project/notebooks/

User's Jupyter notebooks

storage:apolo_tutorial/notebooks/

/project/results/

Logs and results

storage:apolo_tutorial/results/

Filling the flow

Now we need to fill newly created flow with the content:

  • Change working directory:

  • Download data from here, extract the ZIP’s content and put it in your data folder:

Training and evaluating the model

When you start working with a flow on the Apolo platform, the basic flow looks as follows: you set up the remote environment, upload data and code to your storage, run training, and evaluate the results.

To set up the remote environment, run

This command uploads the build context (your Dockerfile, apt.txt, requirements.txt, and the rest of the flow directory) to the platform storage, runs a kaniko build job on the cluster which installs the system packages from apt.txt and the pip dependencies from requirements.txt on top of the base image, and pushes the resulting image to the platform registry as image:apolo_tutorial:v1.

To upload data and code to your storage, run

To run training job, you need to specify the training script in .apolo/live.yml, and then run apolo-flow run train:

  • open .apolo/live.yml in an editor,

  • find the following lines (make sure you're looking at the train job, not multitrain which has a very similar section):

  • and replace it with the following lines (in the base image, PyTorch lives in the dedicated torch conda environment, so the script must be started via conda run):

  • also set a resource preset for the train job (uncomment the preset attribute in the same section and pick a preset from apolo config show). Without it, the job runs on the cluster's default preset, which may be too small for PyTorch:

Now, you can run

and observe the output. The script prints the device it runs on and some dataset and model information first, and then the model is being trained (the exact numbers will differ between runs):

On a cpu-large preset, the training takes around 10 minutes.

Last updated

Was this helpful?