All posts

Porting a machine learning model from GitHub to RunwayML in 5 minutes 🍅

User Avatar
Cristobal Valenzuela
July 30, 2019
You can take an existing machine learning model, written in any deep learning framework, and add it to Runway with just a few lines of code. Learn how to do it here 👇

For this short tutorial, we will be porting Progressive Growing of GANs (PGAN), an open-source model that creates high-quality images, available in the Pytorch Hub and GitHub. The code to run and generate an image with a pre-trained PGAN checkpoint from the Pytorch hub is short and simple, let’s review the base code we will be using:

Creating a Runway model

Let’s start by creating a file called, pasting our sample code from above and adding the runway-python SDK. We will also add numpy for some minor post-processing. (Be sure to install the Runway python SDK with pip install runway-python first!)

Now, let’s wrap the loading of the model with Runway’s setup decorator. The setup decorator will only run once, at the beginning of the inference process, and should always return a model:

The setup function is used to load the checkpoints and render any UI elements in Runway that will be part of the initial model configuration. In this case, just by defining a runway.category and adding the default PGAN checkpoint as options we get this nice UI in Runway ✨:

Next, let’s wrap the inference part of the model in a Runway command function. A command is a special function that is used to define a way you can interact with a model. This will allow you to define input and output types.

A command decorator function is built with three options:

  • The name of the command: in this case generate ,
  • The input type: PGAN generates images from a noise vector of length 512, so we need to provide it with the runway.vector input type.
  • The output type: In this case, the output will be an image type.

Defining a command that takes a vector as input creates a vector grid interface to navigate the latent space of PGAN and show the resulting image as the output.

Now, we are ready to add our model to Runway! Let’s create a runway.yml file, next to our defining how our model should run:

This file provides instructions for defining an environment, installing dependencies, and running your model in a standard and reproducible manner.

That’s it! Let’s create a GitHub repo and push our code to GitHub and get our model in Runway.

Adding the model to Runway via GitHub

Runway can take any existing repository that contains a and runway.yml file and create a model that you can use and share in Runway.

Open Runway and click “From GitHub” in the lower-left corner of the models' directory, select your repository and follow the steps to add a model.

Once the model has been added, Runway will start the build process automatically. You can check the process on the versions tab. Every time you push a commit to GitHub, Runway creates a new version of your model. 🎩

Once the model has been built, you can add it to your workspace and start exploring! 🦄

If you want to learn more about how Runway works, check out the links below. We would love to get your feedback!