explain-extended-2024  by quassnoi

GPT-2 implementation in SQL

created 1 year ago
278 stars

Top 94.3% on sourcepulse

GitHubView on GitHub
Project Summary

This repository provides a PostgreSQL implementation of a Generative Pre-trained Transformer (GPT) model, specifically GPT-2, written in approximately 500 lines of SQL. It targets developers and researchers interested in understanding and experimenting with large language models through a pure SQL interface, offering a unique perspective on AI model architecture and execution.

How It Works

The project leverages PostgreSQL's procedural language capabilities and the pgvector extension to execute the GPT-2 model's forward pass. It represents the model's weights and biases as tables within PostgreSQL and uses SQL queries to perform the matrix multiplications and activation functions inherent to transformer architectures. This approach allows for model inference directly within the database, potentially simplifying deployment and integration for data-centric applications.

Quick Start & Requirements

  • Install/Run: Build and run the Docker image (docker build --tag explainextended2024 . then docker run ... explainextended2024). Install Python dependencies (pip install -r requirements.txt). Populate tables (python populate.py --connection_string="...").
  • Prerequisites: PostgreSQL 15.0+, pgvector extension, Python 3.8+, Docker.
  • Resources: Requires downloading GPT-2 model parameters from OpenAI.
  • Docs: https://explainextended.com/2023/12/31/happy-new-year-15/

Highlighted Details

  • GPT-2 model implemented in ~500 lines of SQL.
  • Utilizes PostgreSQL and the pgvector extension for inference.
  • Demonstrates transformer architecture execution within a relational database.

Maintenance & Community

The project is associated with the author quassnoi. Further community engagement details are not provided in the README.

Licensing & Compatibility

The repository's license is not explicitly stated in the provided README. Compatibility for commercial use or closed-source linking is undetermined.

Limitations & Caveats

This implementation is primarily for educational and demonstrative purposes, focusing on the SQL representation of the model rather than optimized performance. It requires specific PostgreSQL and pgvector versions and relies on external model parameter downloads.

Health Check
Last commit

1 year ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
3 stars in the last 90 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems) and Andreas Jansson Andreas Jansson(Cofounder of Replicate).

natural-sql by cfahlgren1

0%
866
Text-to-SQL LLMs with strong performance
created 1 year ago
updated 1 year ago
Feedback? Help us improve.