awesome-repositories.com
Blog
MCP
awesome-repositories.com

Discover the best open-source repositories with AI-powered search.

ExploreCurated searchesOpen-source alternativesSelf-hosted softwareBlogSitemap
ProjectMCP serverAboutHow we rankPress
LegalPrivacyTerms
© 2026 Bringes Technology SRL·VAT RO45896025·hello@awesome-repositories.com
naklecha avatar

naklecha/llama3-from-scratch

0
View on GitHub↗
15,230 stars·1,284 forks·Jupyter Notebook·MIT·19 views

Llama3 From Scratch

This project is a manual reconstruction of the Llama 3 transformer architecture implemented as a PyTorch neural network. It serves as a reference for the internal mathematical structure and tensor flow of a transformer-based language model designed for next token prediction.

The implementation focuses on building the model from scratch using basic matrix operations and tensor manipulations. It demonstrates the manual construction of core components, including rotary positional embeddings, multi-head self-attention, and root mean square normalization.

The codebase covers the full inference pipeline, from text tokenization and token embedding generation to the use of gated linear units within a feed-forward network. It also includes the mechanisms for loading pre-trained model weights and configuration parameters to initialize the architecture.

The project is provided as a series of Jupyter Notebooks.

Features

  • Large Language Models - Implements a Llama 3 transformer architecture from scratch using fundamental tensor operations.
  • Transformer Language Models - Provides a manual reconstruction of the transformer-based language model architecture using PyTorch.
  • Attention Mechanisms - Calculates relationship scores between tokens using query and key matrix multiplication.
  • Neural Network Operations - Manages mathematical data flow through rotary embeddings, gated linear units, and normalization layers.
  • Multi-Head Attention Mechanisms - Implements multi-head attention to compute contextual relationships across parallel attention heads.
  • Neural Network Implementations - Implements a PyTorch-based neural network covering tokenization, rotary embeddings, and multi-head attention.
  • Rotary Positional Embeddings - Applies rotational shifts to query and key vectors to encode relative token positions.
  • Token Prediction - Predicts the most probable next token by calculating a probability distribution over the vocabulary.
  • Transformer Blocks - Constructs the model using sequential layers of attention and feed-forward networks via matrix operations.
  • Vector Embeddings - Maps discrete numerical tokens to high-dimensional continuous vectors to represent semantic meaning.
  • LLM - Offers a manual reconstruction of the Llama 3 architecture using basic matrix operations.
  • Gated Linear Units - Implements gated linear units to introduce non-linearity within the feed-forward network.
  • Normalization Layers - Stabilizes numerical computations using root mean square normalization layers.
  • Model Inference - Provides a system to load model weights and generate text predictions during inference.
  • Model Weight Management - Includes mechanisms to load pre-trained tensor weights and configuration parameters to initialize the network.
  • Neural Network Layers - Implements a SwiGLU feed-forward network using gated linear units for non-linear data processing.
  • RMS Normalizations - Stabilizes neural network activations by scaling tensors based on the root mean square of their elements.
  • Transformer Architectures - Serves as a reference for studying the internal mechanics of transformer architectures through manual implementation.
  • LLM - Provides a detailed reference for the internal mathematical structure and tensor flow of Llama 3.
  • LLM Development and Research - Implementation of a language model from basic matrix operations.
  • Educational Resources - Educational project demonstrating model architecture from the ground up.

Star history

Star history chart for naklecha/llama3-from-scratchStar history chart for naklecha/llama3-from-scratch

How this analysis was created: This summary and feature list were written by an AI model that read the project's README and public documentation pages. Each feature links to the documentation it came from; stars, license and language come straight from the GitHub API. The model does not read the source code, and the analysis is refreshed when the project is re-analysed. Learn more on our About page.

AI search

Explore more awesome repositories

Describe what you need in plain English — the AI ranks thousands of curated open-source projects by relevance.

Start searching with AI

Frequently asked questions

What does naklecha/llama3-from-scratch do?

This project is a manual reconstruction of the Llama 3 transformer architecture implemented as a PyTorch neural network. It serves as a reference for the internal mathematical structure and tensor flow of a transformer-based language model designed for next token prediction.

What are the main features of naklecha/llama3-from-scratch?

The main features of naklecha/llama3-from-scratch are: Large Language Models, Transformer Language Models, Attention Mechanisms, Neural Network Operations, Multi-Head Attention Mechanisms, Neural Network Implementations, Rotary Positional Embeddings, Token Prediction.

What are some open-source alternatives to naklecha/llama3-from-scratch?

Open-source alternatives to naklecha/llama3-from-scratch include: d2l-ai/d2l-en — This project is an educational platform and research toolkit designed to teach deep learning through a combination of… skyzh/tiny-llm — tiny-llm is a large language model inference engine and transformer model implementation. It serves as a quantized… datawhalechina/so-large-lm — This project is a comprehensive educational curriculum and structured learning path covering the full lifecycle of… datawhalechina/tiny-universe — Tiny Universe is an educational monorepo that delivers multiple independent implementations of core AI subsystems as… datawhalechina/llms-from-scratch-cn — This project is an educational course and set of instructional materials for building large language models from… graykode/nlp-tutorial — This repository serves as an educational resource for learning the foundational architectures of natural language…

Open-source alternatives to Llama3 From Scratch

Similar open-source projects, ranked by how many features they share with Llama3 From Scratch.
  • d2l-ai/d2l-end2l-ai avatar

    d2l-ai/d2l-en

    29,001View on GitHub↗

    This project is an educational platform and research toolkit designed to teach deep learning through a combination of mathematical theory, visual diagrams, and executable code. It provides a comprehensive environment for building, training, and evaluating neural networks, grounding complex concepts in interactive computational notebooks that allow for hands-on experimentation. The framework distinguishes itself by interleaving theoretical foundations—including linear algebra, calculus, and probability—with practical implementations across multiple industry-standard libraries. It supports flex

    Pythonbookcomputer-visiondata-science
    View on GitHub↗29,001
  • skyzh/tiny-llmskyzh avatar

    skyzh/tiny-llm

    4,304View on GitHub↗

    tiny-llm is a large language model inference engine and transformer model implementation. It serves as a quantized model runtime and paged key-value cache manager, providing a specialized inference stack optimized for Apple Silicon. The system distinguishes itself through high-throughput execution techniques, including continuous batching and paged attention. It utilizes a paged memory system to eliminate fragmentation during token generation and employs on-the-fly dequantization of compressed weights to reduce the memory footprint during matrix multiplication. The project covers a broad ran

    Pythoncourselarge-language-modelllm
    View on GitHub↗4,304
  • datawhalechina/so-large-lmdatawhalechina avatar

    datawhalechina/so-large-lm

    7,400View on GitHub↗

    This project is a comprehensive educational curriculum and structured learning path covering the full lifecycle of large language models. It provides a guided progression through the theory, architecture, training, and deployment of these models. The curriculum includes specialized guides on transformer architecture, model training tutorials, and frameworks for designing autonomous agents. It also provides dedicated resources for studying model safety and ethics. The material covers a wide range of technical capabilities, including distributed training strategies, parameter-efficient fine-tu

    View on GitHub↗7,400
  • datawhalechina/tiny-universedatawhalechina avatar

    datawhalechina/tiny-universe

    4,505View on GitHub↗

    Tiny Universe is an educational monorepo that delivers multiple independent implementations of core AI subsystems as self-contained Jupyter notebooks. It provides from-scratch constructions of foundational architectures including a complete Transformer model built from the original paper specification, a denoising diffusion probabilistic model for image generation, and a ReAct-style autonomous agent framework that equips an LLM with tools for planning and multi-step task execution. The project distinguishes itself by covering the full lifecycle of modern AI systems through hands-on implementa

    Jupyter Notebookagentdiffusionevaluation-metrics
    View on GitHub↗4,505
  • See all 30 alternatives to Llama3 From Scratch→