Quick tip: Using picoGPT in the SingleStore portal
Tags: singlestoredb, gpt2, picogpt
Published: 2024-06-23 19:56:06

## Abstract
[picoGPT](https://github.com/jaymody/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](https://github.com/VeryFatBoy/picogpt).

## Introduction
In an article titled "[GPT in 60 Lines of NumPy](https://jaykmody.com/blog/gpt-from-scratch/)" 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](https://github.com/jaymody/picoGPT), 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](https://dev.to/singlestore/quick-tip-using-dbt-with-singlestoredb-161g) 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](https://github.com/VeryFatBoy/picogpt).

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:

```python
result = main("Alan Turing theorized that computers would one day become")
print(result)
```

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.
```

Second, some example text from the [Ollama website](https://ollama.com/blog/embedding-models):

```python
result = main("Llamas are members of the camelid family meaning")
print(result)
```

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
```

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.