Description of image

Create and Run Example Gradient Notebooks with Fast.ia and CLIP-PixelDraw

Notebooks are a web-based Jupyter IDE with shared persistent storage for long-term development and inter-notebook collaboration, backed by accelerated compute.


Notebooks are an increasingly popular abstraction in machine learning. Notebooks eliminate development steps to create a machine learning environment and reproducible and collaborative. Gradient Notebooks are a web-based Jupyter IDE with high-powered GPUs which use a pre-build runtime from Paperspace. You can create and run your own Gradient notebook by importing your files and container with advanced options.

Create first Notebook

If you run Jupyter Notebooks or JupyterLab on other managed cloud services or on your local machine, Gradient Notebooks combine the functionality of Jupyter with an additional set of features:

  • Persistent storage
  • Free-tier or Paid-tier CPU and GPU instances
  • Unlimited duration runtimes for paid instances
  • Pre-configured templates or your own custom Docker image

Creating and Running a Fast.ai Notebook

With a Fast.ai notebook, your Gradient notebook runs on the latest version of Practical Deep Learning for Coders course from Fast.ai. First create or choose a Gradient Project.

Then create a notebook by selecting the Notebooks tab and click Create.

Create new Notebook

For configurations, select your machine and either use the prebuilt runtime or select a runtime. Afterwards click Paperspace + Fast.ai to start a Fast.ai notebook which instructs Gradient to copy the contents of a specific Fast.ai repository that contains the Fast.ai exercise files over to your notebook. Then, it runs those files on a compute instance pre-installed with compatible dependencies.

fast.ai runtime

There are several machine options to run your notebook, including Free-CPU and Free-GPU instances.

Free-GPU instance

After creating your notebook, go to the Gradient Notebooks IDE. You can look at the status bar which shows how long your notebook is loading into the IDE.

Status bar

Once the notebook is in the Running state, the Gradient Notebooks IDE looks like this:

Notebook ready

When running commands, check the bottom bar of the IDE as this area shows you what the machine is doing as it displays the information and metrics.

Idle Notebook

You can run cells from the 01_intro.ipynb file which shows the cells executing like this:

Run single cell

Next, you add !pip install statements in your cell by cutting the !pip install command from the existing cell, and using the + button to then click Insert Code. Then, you paste the pip command into the newly created cell.

Create a new code or markdown cell

You can select Insert Markdown which adds an explanatory or reference block of text to your ipynb file.

Gradient notebooks support editing standard code files as well as full autosave capabilities. You can modify the contents of the requirements.txt file which ships with the Fast.ai learning materials:

edit non-ipynb files

You can run your notebook only within six-hour sessions on a free instance as the notebook shuts down after six hours of use. However, Gradient must have the capacity to run your session. If you need infinite runtimes or faster GPU instances, you need to update your Gradient subscription and recreate the notebook.

When you want to shutdown your notebook, you can let the auto-shutdown timer expire or shut down the instance manually via instance panel in the sidebar or via the Stop Instance button in the top status bar.

Instance selector

If the instance is not shut down manually, the auto-shutdown timer turns off the Free-GPU instance at the six hour mark. Paid instances auto-shutdown if an auto-shutdown interval is specified. The default is 12 hours for paid instances.

Creating and Running a Custom CLIP-PixelDraw Notebook

You use CLIP and PixelDraw to generate imaginative clip-art piece from a string of text. If you are on the Gradient free tier, stop the notebook instance so that you do not exceed the limit of QTY 1 concurrent running notebooks on the free plan. If you have the upgraded Gradient account, you do not need to shut down running notebook instances.

You can read more on Gradient tier limits through this pricing overview under Compare Plans.

On the Gradient console, you can update your project name to illustrate that a new notebook is added to it:

Rename project

Then, click Create to show the Create a notebook screen:

Second notebook

There are a several runtimes available when switching from Recommended to All in the runtime selector. Gradient frequently adds support for new runtimes. In Gradient, a runtime is a specific workspace combination, which is pulled from a git repository via like GitHub, and a container, which is pulled from a container registry via like DockerHub.

Prebuilt runtimes

If you toggle the tile called Transformers + NLP from Hugging Face, and scroll down to the Advanced Options slider at the bottom of screen and toggle it on, you can see the specific workspace combination in the advanced options:

Transformers + NLP tile Workspace and Container parameters

This particular Hugging Face tile is specifying Workspace URL, Container Name, and Command.

  • Workspace URL: Git repository URL that Gradient uses to clone into the notebook.
  • Container Name: Location of the image on Docker Hub that Gradient loads into the notebook.
  • Command (Advanced): Bash command that is run on the Jupyter kernel on instantiation.

A runtime then is a combination of Workspace URL and Container Name that results in some files from a respository running against a container image.

For the notebook, the implementation of CLIP from OpenAI and PixelDraw from the PixRay project helps create synthetic artwork from a inputted text prompt. Dune is used for the text prompt for the image generator.

Select the highest GPU instance then toggle to Advanced options and enter the following parameters:

  • Workspace URL: https://github.com/gradient-ai/ClipIt-PixelDraw.git
  • Container Name: paperspace/clip-pixeldraw:jupyter

The workspace contains a number of files related to generative art, and the container contains a number of libraries pre-installed.

Advanced options clip

Ensure the locations of the workspace and container are copy and pasted the Advanced options section of the Create a notebook workflow. Once you initialized your notebook, it looks like this:

Running clip

Run the following !git clone commands at the top of the notebook:

Start git clone

Open the pixeldraw.py file using the file navigator on the left to see the prompt currently used on line 15. By default that prompt is set to the following:

Paperspace.com helps you do machine learning #pixelart

Change the prompt that describes a sand-covered planet from Dune:

On the desert planet of Arrakis, the spice must flow!
Change default prompt

Go to the .ipynb file and run the following cell:

!python pixeldraw.py
from IPython.display import Image
Image(filename='output.png')

This runs the modified code in pixeldraw.py.

Depending on the GPU instance in use, processing could take 8-20 minutes.

Clip art results

After processing, this is the following output:

Clip art

It is recommended that the repository or a container is explicitly specified. For example, if you decided to use the new CLIP implementation which uses a different artistic technique to generate artwork, then you could create a new notebook with Workspace URL in Advanced options set to:

https://github.com/pschaldenbrand/styleclipdraw

This would pull the target files into an instance running the default Gradient container.

Afterwards, you would fork the repository to a new public or private repository and modify it. You could also create your own Docker container pre-loaded with new dependencies and submit that to a public or private registry.

For inspiration, it is recommended to read the Paperspace blog which has novel implementations that often include code and demo notebooks. For browsing a collection of starter notebooks created for Gradient, look into the ML Showcase. It is recommended to learn more about runtimes, machines, including free tier instances, and Persistent Storage which is automatically mounted at /storage.