vixhal-baraiya/microgpt-c

The most atomic way to train and inference a GPT in pure, dependency-free C

What it solves

解決する課題

It provides a minimal, dependency-free implementation of a GPT-style transformer model written in pure C. This allows for training and inference without the need for heavy machine learning frameworks or external libraries beyond the standard C library (libc).

純粋なC言語で書かれた、最小限で依存関係のないGPTスタイルのTransformerモデルの実装を提供します。これにより、重い機械学習フレームワークや標準Cライブラリ (libc) 以外の外部ライブラリを必要とせずに、学習と推論を行うことができます。

How it works

仕組み

The project implements a character-level transformer that includes a forward pass, a backpropagation, the Adam optimizer, and sampling. It uses two distinct forward pass paths: one for training (gpt_forward) which stores activations for backpropagation, and a specialized, optimized path for single-token inference (gpt_forward_infer). To maximize performance, it leverages hardware-specific optimizations like NEON for ARM64 and AVX2 for x86-64.

このプロジェクトは、フォワードパス、バックプロパゲーション、Adamオプティマイザ、およびサンプリングを含む、文字レベルのTransformerを実装しています。2つの異なるフォワードパスを使用します:バックプロパゲーションのために活性化を保存する学習用 (gpt_forward) と、単一トークンの推論に特化した最適化されたパス (gpt_forward_infer) です。パフォーマンスを最大化するために、ARM64用のNEONやx86-64用のAVX2といったハードウェア固有の最適化を活用しています。

Who it’s for

対象者

Developers and researchers who want to understand the inner workings of GPT models at the most atomic level or who need a lightweight, highly efficient C implementation for simple text generation tasks.

GPTモデルの内部動作を最も原子的なレベルで理解したい開発者や研究者、または、単純なテキスト生成タスクのために軽量で非常に効率的なC言語の実装が必要な方を対象としています。

Highlights

ハイライト

  • Dependency-free: Written in pure C using only libc.
  • 依存関係なし: libcのみを使用した純粋なC言語による記述。
  • High performance: Optimized for ARM64 (NEON) and AVX2 (x86-64).
  • 高パフォーマンス: ARM64 (NEON) および AVX2 (x86-64) に最適化。
  • Efficient: A small model (4192 parameters) that generalizes well on character-level tasks like name generation.
  • 効率的: 名前生成のような文字レベルのタスクにおいて、高い汎化性能を持つ小さなモデル (4192 parameters)。
  • Single-file implementation: The core logic is contained within one C file.
  • 単一ファイル実装: コアロジックは1つのCファイル内に収められています。

関連

  • プロジェクト
  • プロジェクト
  • プロジェクト
  • Dispatch
  • プロジェクト