Git Product home page Git Product logo

kan-gpt-2's Introduction

Training small GPT-2 style models using KANs instead of MLPs in JAX

This repository compares transformers using multilayer perceptron (MLP) and Kolmogorov-Arnold networks (KAN) layers.

Key points:

  • Uses Kolmogorov-Arnold Networks but with Chebyshev polynomials as the basis (inspired by this repo).
  • The tanh function is used to keep the activation values within [-1, 1] rather than using grids that update during training.
  • Both models are trained on 134M tokens of TinyStories.
  • They both use standard GPT-2 architecture (other than the KAN part).
  • The MLP version has 3.3M non-embedding weights and the KAN model has 2.5M non-embedding weights (~25% fewer).

Results:

They both achieve a final loss of ~2.46 (despite the KAN model having 25% fewer parameters!). image

Hyperparameters:

  • d_model: 128
  • d_mlp: 768 (when applicable)
  • n_heads: 8
  • n_layers: 16
  • learning_rate: 1e-5
  • batch_size: 16
  • weight_decay: 0.001
  • optimizer: adamw
  • seq_len: 64

Hardware: Single 1080ti GPU

Wandb: link.

kan-gpt-2's People

Contributors

cg80499 avatar

Stargazers

Sean avatar  avatar Jiaqing Zhang avatar Ulan Sametov avatar Shreyas S avatar Henry Ndubuaku avatar  avatar SAMeh Zaghloul avatar Jelle Hak avatar J.-C. Jiang avatar Tiange Zhu avatar S.Goussous avatar _ravecat_ avatar Nikita Bragin avatar MaximusIdeal avatar Esmail avatar Jackson Hall avatar Artem Gribul avatar Ben Zhang avatar Chris Huang avatar David Borts avatar Muhammad N ElNokrashy avatar Ayomide Ayodele-Soyebo avatar Jihoon Oh avatar  avatar  avatar Ronit Raj avatar Vũ Đức Duy avatar  avatar Caio Petrucci Rosa avatar Rusty avatar gyunggyung avatar boolayon avatar Hironobu Suzuki avatar  avatar  avatar Ayodhya Ratnayake avatar Iulius™ avatar Marcel Guinhos avatar Daniel Flores Araiza avatar Artic avatar Garry Proshian avatar Sathish Kumar R avatar  avatar Sergey Kostyaev avatar Cris@None avatar Boris Ter-Avanesov avatar  avatar Peyton avatar  avatar yibit avatar Gurumurthi V Ramanan avatar QinLuo avatar Smuglix avatar  avatar Danny Wang avatar play123 avatar  avatar lizhan avatar Tokarev Igor avatar  avatar  avatar AICTPM avatar 爱可可-爱生活 avatar Leonardo Iania avatar Leo Lee avatar Gilad Turok avatar dearwind153 avatar Huan Xu avatar Amund Tveit avatar Felipe Menegazzi avatar Muhammad Anas Raza avatar Shoaib Ahmed Siddiqui avatar Huy Hoàng avatar Grzegorz Aniol avatar snoop2head avatar Ertan Burak FELEK avatar  avatar  avatar Jinhui.Lin avatar Juraj Pohanka avatar Julien Raoult avatar Naafey Aamer avatar  avatar Andrews Cordolino Sobral avatar hyunsookim avatar Douglas Lewis avatar Neil Tan avatar  avatar kathir avatar Crux avatar Junbum Lee avatar Ciaran Regan avatar PengqianHan avatar  avatar Daniel  avatar Nimrod avatar  avatar

Watchers

 avatar Artic avatar  avatar

kan-gpt-2's Issues

Any suggestions for KAN-ViT?

Dear @CG80499 ,
Thank you for your contribution.

Using your implementation of ChebyKAN layer, I am currently training Vision Transformer tiny model on ImageNet1K. But it seems like it is underperforming the original implementation.

Any suggestions? Why did you set polynomial degree as 8 for GPT?

Screenshot 2024-05-10 at 2 37 15 PM

Here are some minor details for my implementation on ViT.

  • I used DeiT replication written in JAX/FLAX.
  • Learning rate, batch size, weight decay, random seed etcs are set to be the same.
  • I replaced feedforward MLP that are subsequent to the attention block only, while remaining attention layers to use nn.Dense which is similar to your KAN-GPT-2 implementation.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.