Transformer系モデルをスクラッチ実装し、理解を深める。
- Vanilla Transformer1: models/vanilla_transformer.py
- GPT-22: models/gpt2.py
- Vision Transformer3: models/vision_transformer.py
- CLIP4: models/clip.py
- 学習コード(言語モデル学習のみ): train.py
uv sync
学習済みのTokenizerは置いてあるのでやらなくてもいい。
uv run python train_tokenizer.py
config/にモデルの設定をtoml形式で記述し、ファイル名を指定する。
uv run torchrun --nproc_per_node=1 train.py -c gpt2
学習したモデルを使って実際に文章生成を試す。
本プログラムで学習したモデルはHugging Faceにアップロード済み。
Footnotes
-
Vaswani, Ashish, et al. "Attention Is All You Need." Advances in Neural Information Processing Systems, 2017, pp. 5998–6008. arXiv:1706.03762. ↩
-
Radford, Alec, et al. "Language Models are Unsupervised Multitask Learners." OpenAI Blog, 2019. ↩
-
Dosovitskiy, Alexey, et al. "An Image is Worth 16×16 Words: Transformers for Image Recognition at Scale." arXiv preprint arXiv:2010.11929 (2021). ↩
-
Radford, Alec, et al. "Learning Transferable Visual Models from Natural Language Supervision." arXiv preprint arXiv:2103.00020, 2021. ↩