kan gpt
1.2.0
使用 Kolmogorov-Arnold 网络 (KAN) 进行语言建模的生成式预训练 Transformer (GPT) 的 PyTorch 实现
pip install kan_gpt
如果您发现我们的工作有用,请引用我们!
@misc{GANESH2024KANGPT,
author = {Aditya Nalgunda Ganesh},
title = {KAN-GPT: The PyTorch implementation of Generative Pre-trained Transformers (GPTs) using Kolmogorov-Arnold Networks (KANs) for language modeling},
year = {2024},
month = {May},
note = {Release 1.0.0, 9th May 2024},
url = {https://github.com/AdityaNG/kan-gpt/}
}
请参阅 KAN_GPT.ipynb 和 kan_gpt/prompt.py 了解使用示例。以下是如何使用该模型的概述:
from kan_gpt . model import GPT
from transformers import GPT2Tokenizer
model_config = GPT . get_default_config ()
model_config . model_type = "gpt2"
model_config . vocab_size = 50257
model_config . block_size = 1024
model = GPT ( model_config )
tokenizer = GPT2Tokenizer . from_pretrained ( 'gpt2' )
prompt = "Bangalore is often described as the "
prompt_encoded = tokenizer . encode (
text = prompt , add_special_tokens = False
)
x = torch . tensor ( prompt_encoded ). unsqueeze ( 0 )
model . eval ()
y = model . generate ( x , 50 ) # sample 50 tokens
result = tokenizer . decode ( y [ 0 ])
print ( result )
# Bangalore is often described as the Silicon Valley of India.
# The city has witnessed rapid growth in the past two decades.....
# Download Repo
git clone https://github.com/AdityaNG/kan-gpt
cd kan-gpt
git pull
# Download Dataset
python3 -m kan_gpt.download_dataset --dataset tinyshakespeare
python3 -m kan_gpt.download_dataset --dataset mnist
python3 -m kan_gpt.download_dataset --dataset webtext
# Install dependencies for development
pip install -r requirements.txt
pip install -e .
使用以下虚拟脚本确保一切按预期工作
WANDB_MODE=offline CUDA_VISIBLE_DEVICE= " " python3 -m kan_gpt.train --architecture MLP --batch_size 1 --dummy_dataset --device cpu --max_iters 200
WANDB_MODE=offline CUDA_VISIBLE_DEVICE= " " python3 -m kan_gpt.train --architecture KAN --batch_size 1 --dummy_dataset --device cpu --max_iters 200
然后使用训练脚本
python -m kan_gpt.train
您可以提示模型生成文本,如下所示
python -m kan_gpt.prompt --prompt " Bangalore is often described as the " --model_path (checkpoint)
我们在 Tiny Shakespeare 数据集上训练 KAN-GPT 与等效的 MLP-GPT 模型并将其进行比较。我们观察到 KAN-GPT 的性能略好于 MLP-GPT。我们正在研究进一步的实验以进行更深入的研究。结果如下所示:
指标 | ||
---|---|---|
KAN.train_kan
的 KAN 训练逻辑mkdocs gh-deploy
阅读 CONTRIBUTING.md 文件。