GPT-2 implementation in SQL
Top 94.3% on sourcepulse
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
docker build --tag explainextended2024 .
then docker run ... explainextended2024
). Install Python dependencies (pip install -r requirements.txt
). Populate tables (python populate.py --connection_string="..."
).pgvector
extension, Python 3.8+, Docker.Highlighted Details
pgvector
extension for inference.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.
1 year ago
1 day