Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.3%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Basic Info
  • Host: GitHub
  • Owner: Sangwan70
  • License: other
  • Language: Jupyter Notebook
  • Default Branch: main
  • Homepage: https://www.theskillpedia.com
  • Size: 12 MB
Statistics
  • Stars: 9
  • Watchers: 1
  • Forks: 31
  • Open Issues: 0
  • Releases: 0
Created over 1 year ago · Last pushed 11 months ago
Metadata Files
Readme License Citation

README.md

Building a Large Language Model From Scratch

This repository contains the code for developing, pretraining, and finetuning a GPT-like LLM.

You'll learn and understand how large language models (LLMs) work from the inside out by coding them from the ground up, step by step. I'll guide you through creating your own LLM, explaining each stage with clear text, diagrams, and examples.

!Environment Setup for Building Large Language Models

The method described for training and developing your own small-but-functional model for educational purposes mirrors the approach used in creating large-scale foundational models such as those behind ChatGPT. In addition, this repository includes code for loading the weights of larger pretrained models for finetuning.

bash git clone --depth 1 https://github.com/Sangwan70/Building-an-LLM-From-Scratch.git

Table of Contents

[!TIP] If you're seeking guidance on installing Python and Python packages and setting up your code environment, I suggest reading the README.md file located in the setup directory.

| part Title | Main Code (for Quick Access) | All Code + Supplementary | |------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|-------------------------------| | Setup recommendations | - | - | | Part 1: Working with Text Data | - Part 1: Working with Text
- dataloader.ipynb (summary)
- additional_examples.ipynb | ./part_1 | | Part 2: Coding Attention Mechanisms | - Part 2: Coding Attention Mechanisms
- multihead-attention.ipynb (summary)
- additional_examples.ipynb| ./part_2 | | Part 3: Implementing a GPT Model from Scratch | - Part 3: Implementing a GPT model from Scratch
- gpt.py (summary)
- additional_examples.ipynb | ./part_3 | | Part 4: Pretraining on Unlabeled Data | - Part 4: Pretraining on Unlabeled Data
- gpt_train.py (summary)
- gpt_generate.py (summary)
- additional_examples.ipynb | ./part_4 | | Part 5: Finetuning for Text Classification | - Part 5: Finetuning for Text Classification
- gptclassfinetune.py
- additional_examples.ipynb | ./part_5 | | Part 6: Finetuning to Follow Instructions | - Part 6: Finetuning To Follow Instructions
- gptinstructionfinetuning.py (summary)
- ollama_evaluate.py (summary)
- example-solutions.ipynb | ./part_6 | | Appendix A: Introduction to PyTorch | - code-part1.ipynb
- code-part2.ipynb
- DDP-script.py
- additional_examples.ipynb | ./appendix-A | | Appendix B: Adding Bells and Whistles to the Training Loop | - appendix-B.ipynb | ./appendix-B | | Appendix C: Parameter-efficient Finetuning with LoRA | - appendix-C.ipynb | ./appendix-C |

Hardware Requirements

The code in the main parts of this course is designed to run on conventional laptops within a reasonable timeframe and does not require specialized hardware. Additionally, the code automatically utilizes GPUs if they are available. (Please see the setup doc for additional recommendations.)

Additional Material

Several folders contain additional materials for interested readers:

Questions, Feedback, and Contributing to This Repository

I welcome all sorts of feedback via GitHub Discussions. Likewise, if you have any questions or just want to bounce ideas off others, please don't hesitate to post these in the forum as well.

 

Citation

BibTeX entry:

author = {Ram N Sangwan}, title = {Building An LLM From Scratch} github = {https://github.com/Sangwan70/Building-an-LLM-From-Scratch} }

Owner

  • Name: Ram Niwas Sangwan
  • Login: Sangwan70
  • Kind: user
  • Company: Alliance Softech Pvt Ltd

GitHub Events

Total
  • Watch event: 11
  • Push event: 81
  • Fork event: 33
  • Create event: 2
Last Year
  • Watch event: 11
  • Push event: 81
  • Fork event: 33
  • Create event: 2

Dependencies

setup/03_optional-docker-environment/.devcontainer/Dockerfile docker
  • pytorch/pytorch 2.5.0-cuda12.4-cudnn9-runtime build
ch02/02_bonus_bytepair-encoder/requirements-extra.txt pypi
  • requests *
  • tqdm *
  • transformers >=4.33.2
ch04/02_performance-analysis/requirements-extra.txt pypi
  • thop *
ch05/06_user_interface/requirements-extra.txt pypi
  • chainlit >=1.2.0
ch05/07_gpt_to_llama/requirements-extra.txt pypi
  • blobfile >=3.0.0
  • huggingface_hub >=0.24.7
  • ipywidgets >=8.1.2
  • safetensors >=0.4.4
  • sentencepiece >=0.1.99
ch05/07_gpt_to_llama/tests/test-requirements-extra.txt pypi
  • pytest >=8.1.1 test
  • transformers >=4.44.2 test
ch06/03_bonus_imdb-classification/requirements-extra.txt pypi
  • scikit-learn >=1.3.0
  • transformers >=4.33.2
ch06/04_user_interface/requirements-extra.txt pypi
  • chainlit >=1.2.0
ch07/02_dataset-utilities/requirements-extra.txt pypi
  • openai >=1.30.3
  • scikit-learn >=1.3.1
  • tqdm >=4.65.0
ch07/03_model-evaluation/requirements-extra.txt pypi
  • openai >=1.30.3
  • tqdm >=4.65.0
ch07/05_dataset-generation/requirements-extra.txt pypi
  • openai >=1.30.3
  • tqdm >=4.65.0
ch07/06_user_interface/requirements-extra.txt pypi
  • chainlit >=1.2.0
requirements.txt pypi
  • jupyterlab >=4.0
  • matplotlib >=3.7.1
  • numpy >=1.25,<2.0
  • pandas >=2.2.1
  • psutil >=5.9.5
  • tensorflow >=2.15.0
  • tiktoken >=0.5.1
  • torch >=2.0.1
  • tqdm >=4.66.1