In this tutorial, we describe the recommended way to train a simple machine learning model on Neuro 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 Neuro CLI, and logged into the platform (see Getting Started).
We base our example on the Classifying Names with a Character-Level RNN tutorial.
To simplify working with Neuro Platform and to help to establish the best practices in the ML environment, we provide a project template. This template consists of the recommended directories and files. It is designed to operate smoothly with our base environment.
Let’s initialize a new project from this template:
neuro project init
This command asks several questions about your project:
project_name [Name of the project]: Neuro Tutorialproject_slug [neuro-tutorial]:code_directory [modules]: rnn
After you execute the command mentioned above, you get the following structure:
neuro-tutorial├── data/ <- training and testing datasets (we do not keep it under source control)├── notebooks/ <- Jupyter notebooks├── rnn/ <- source code of models├── .gitignore <- default .gitignore for a Python project├── Makefile <- commands for manipulating training environment (see `make help`)├── README.md <- auto-generated informational file├── apt.txt <- list of system packages to be installed in the training environment├── requirements.txt <- list Python dependencies to be installed in the training environment└── setup.cfg <- linter settings (Python code quality checking)
When you run a job (for example, via
make jupyter), the directories are mounted to the job as follows:
Training / testing data
User's Python code
User's Jupyter notebooks
Logs and results
This mapping is defined as variables in the top of
Makefile and can be adjusted if needed.
Now we need to fill newly created project with the content:
Change working directory:
Copy the model source to your
curl https://raw.githubusercontent.com/pytorch/tutorials/master/intermediate_source/char_rnn_classification_tutorial.py -o rnn/char_rnn_classification_tutorial.py
requirements.txt in your project root folder with this file:
curl https://raw.githubusercontent.com/pytorch/tutorials/master/requirements.txt -o requirements.txt
Download data from here, extract ZIP’s content and put it in your
curl https://download.pytorch.org/tutorial/data.zip -o data/data.zip && unzip data/data.zip && rm data/data.zip
When you start working with a project on Neuro 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 will run a lightweight job (via
neuro run), upload the files containing your dependencies
neuro cp), install the dependencies (using
neuro exec), do other preparatory steps, and then create the base image from this job and push it to the platform (via
neuro save, which works similarly to
To upload data and code to your storage, run
To run training, you need to run specify the training command in Makefile, and then run
Makefile in editor,
find the following line:
TRAINING_COMMAND?='echo "Replace this placeholder with a training script execution"'
and replace it with the following line:
TRAINING_COMMAND?="bash -c 'cd $(PROJECT_PATH_ENV) && python -u $(CODE_DIR)/char_rnn_classification_tutorial.py'"
Now, you can run
and observe the output. You will see how some checks are made at the beginning of the script, and then the model is being trained and evaluated:
['data/names/German.txt', 'data/names/Polish.txt', 'data/names/Irish.txt', 'data/names/Vietnamese.txt','data/names/French.txt', 'data/names/Japanese.txt', 'data/names/Spanish.txt', 'data/names/Chinese.txt','data/names/Korean.txt', 'data/names/Czech.txt', 'data/names/Arabic.txt', 'data/names/Portuguese.txt','data/names/English.txt', 'data/names/Italian.txt', 'data/names/Russian.txt', 'data/names/Dutch.txt','data/names/Scottish.txt', 'data/names/Greek.txt']Slusarski['Abandonato', 'Abatangelo', 'Abatantuono', 'Abate', 'Abategiovanni']tensor([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0.]])torch.Size([5, 1, 57])tensor([[-2.8248, -2.9118, -2.8999, -2.9170, -2.8916, -2.9699, -2.8785, -2.9273,-2.8397, -2.8539, -2.8764, -2.9278, -2.8638, -2.9310, -2.9546, -2.9008,-2.8295, -2.8441]], grad_fn=<LogSoftmaxBackward>)('German', 0)category = Vietnamese / line = Vucategory = Chinese / line = Checategory = Scottish / line = Frasercategory = Arabic / line = Abadicategory = Russian / line = Adabashcategory = Vietnamese / line = Caocategory = Greek / line = Horiatiscategory = Portuguese / line = Pinhocategory = Vietnamese / line = Tocategory = Scottish / line = Mcintosh5000 5% (0m 19s) 2.7360 Ho / Portuguese ✗ (Vietnamese)10000 10% (0m 38s) 2.0606 Anderson / Russian ✗ (Scottish)15000 15% (0m 58s) 3.5110 Marqueringh / Russian ✗ (Dutch)20000 20% (1m 17s) 3.6223 Talambum / Arabic ✗ (Russian)25000 25% (1m 35s) 2.9651 Jollenbeck / Dutch ✗ (German)30000 30% (1m 54s) 0.9014 Finnegan / Irish ✓35000 35% (2m 13s) 0.8603 Taverna / Italian ✓40000 40% (2m 32s) 0.1065 Vysokosov / Russian ✓45000 45% (2m 52s) 3.6136 Blanxart / French ✗ (Spanish)50000 50% (3m 11s) 0.0969 Bellincioni / Italian ✓55000 55% (3m 30s) 3.1383 Roosa / Spanish ✗ (Dutch)60000 60% (3m 49s) 0.6585 O'Kane / Irish ✓65000 65% (4m 8s) 4.7300 Satorie / French ✗ (Czech)70000 70% (4m 27s) 0.9765 Mueller / German ✓75000 75% (4m 46s) 0.7882 Attia / Arabic ✓80000 80% (5m 5s) 2.1131 Till / Irish ✗ (Czech)85000 85% (5m 25s) 0.5304 Wei / Chinese ✓90000 90% (5m 44s) 1.6258 Newman / Polish ✗ (English)95000 95% (6m 2s) 3.2015 Eberhardt / Irish ✗ (German)100000 100% (6m 21s) 0.2639 Vamvakidis / Greek ✓> Dovesky(-0.77) Czech(-1.11) Russian(-2.03) English> Jackson(-0.92) English(-1.65) Czech(-1.85) Scottish> Satoshi(-1.32) Italian(-1.81) Arabic(-2.14) Japanese