Running Your Code
Oftentimes you don't start a project from scratch. Instead of that you use someone's or your own old code as a baseline and develop your solution on top of it. This guide demonstrates how to take an existing code base, convert it into a Apolo flow, and start developing on the platform.
Prerequisites
Make sure that you have the Apolo CLI installed and logged in.
Install the
apolo-flowpackage:
pip install -U apolo-flowConfiguration
As an example we'll use the GitHub repo that contains PyTorch implementations for Aspect-Based Sentiment Analysis models (see Attentional Encoder Network for Targeted Sentiment Classification for more details).
First, let's clone the repo and navigate to the created folder:
git clone https://github.com/songyouwei/ABSA-PyTorch.git
cd ABSA-PyTorchNow, we need to create two more files in this folder:
Dockerfilecontains a very basic Docker image configuration. We need this file to build a custom Docker image which is based onpytorch/pytorchpublic images and contains this repo requirements (which are gracefully listed by the repo maintainer inrequirements.txt). Since the repo was published, the Python ecosystem has moved on, so two adjustments are needed on top of the raw requirements: the deprecatedsklearnPyPI package must be replaced withscikit-learn(installingsklearnnow fails on purpose), andprotobufmust be pinned below 4.0 (newer versions are incompatible with thetransformersversion this repo needs). Also note that we intentionally do not pass-Uto pip: with it, thetorch>=0.4.0requirement would replace the PyTorch already shipped in the base image with a several-gigabytes-larger fresh build.
FROM pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime
COPY . /cfg
RUN sed -i 's/^sklearn$/scikit-learn/' /cfg/requirements.txt && \
pip install --progress-bar=off --no-cache-dir -r /cfg/requirements.txt "protobuf<3.21".apolo/live.ymlcontains minimal configuration allowing us to run this repo's scripts right on the platform through handy short commands:
Here is a brief explanation of this config:
volumessection contains declarations of connections between your computer file system and the platform storage; here we state that we want the entire project folder to be uploaded to storage atstorage:absafolder and be mounted inside jobs/project;imagessection contains declarations of Docker images created in this project; here we declare our image which is decribed inDockerfileabove;jobssection is the one where action happens; here we declare atrainjob which runs our training script with a couple of parameters.
Running code
Now it's time to run several commands that set up the project environment and run training.
First, create volumes and upload project to platform storage:
Then, build an image:
Finally, run training:
Please run apolo-flow --help to get more information about available commands.
Last updated
Was this helpful?