DEV Community

Cover image for Quick tip: Using picoGPT in the SingleStore portal
Akmal Chaudhri for SingleStore

Posted on • Updated on

Quick tip: Using picoGPT in the SingleStore portal

Abstract

picoGPT is a simplified and minimal implementation of the GPT model. It demonstrates the core principles of the GPT architecture without the requirement for a full-scale implementation. Written in Python and consisting of a small quantity of code, picoGPT doesn't implement many of the optimisations and enhancements found in comprehensive implementations. In this short article, we'll convert the original Python code to a Jupyter notebook and test it in the SingleStore portal.

The notebook file used in this article is available on GitHub.

Introduction

In an article titled "GPT in 60 Lines of NumPy" published in 2023, the author describes a very compact GPT solution. The article contains a wealth of implementation details and step-by-step instructions. Using the Python code provided on GitHub, we'll convert the standalone implementation to run in a Jupyter notebook. We'll then test the notebook in the SingleStore portal.

The code can be broken down into three main parts:

  1. encoder: A GPT-2 encoder from OpenAI
  2. utils: Several helper functions for GPT-2 model setup
  3. gpt2: A transformer for text generation similar to a GPT-2 model

We'll make the minimal changes required to get the code working for us in the SingleStore portal.

Create a SingleStoreDB Cloud account

A previous article showed the steps to create a free SingleStoreDB Cloud account. We'll use the following settings:

  • Workspace Group Name: picoGPT Demo Group
  • Cloud Provider: AWS
  • Region: US East 1 (N. Virginia)
  • Workspace Name: picogpt-demo
  • Size: S-00

Import the notebook

We'll download the notebook from GitHub.

From the left navigation pane in the SingleStore cloud portal, we'll select DEVELOP > Data Studio.

In the top right of the web page, we'll select New Notebook > Import From File. We'll use the wizard to locate and import the notebook we downloaded from GitHub.

Run the notebook

After checking that we are connected to the SingleStore workspace, we'll select Run > Run All Cells.

We have two examples programmed into the notebook.

First, the example text from the original implementation:

result = main("Alan Turing theorized that computers would one day become")
print(result)
Enter fullscreen mode Exit fullscreen mode

Example output:

 the most powerful machines on the planet.

The computer is a machine that can perform complex calculations, and it can perform these calculations in a way that is very similar to the human brain.
Enter fullscreen mode Exit fullscreen mode

Second, some example text from the Ollama website:

result = main("Llamas are members of the camelid family meaning")
print(result)
Enter fullscreen mode Exit fullscreen mode

Example output:

 they are the only members of the family that live in the desert.

The camelid family is a group of animals that live in the desert. The camelid family is a group of animals
Enter fullscreen mode Exit fullscreen mode

So, some mixed results.

Summary

In this short article, we've implemented and run picoGPT in the SingleStore portal. Performance may not be great and results seem somewhat mixed, but implementing the GPT in such few lines of code is very impressive.

Top comments (0)