
This repository is an educational implementation of Google's Gemma 3 270M model, with readability and pedagogy prioritized over production inference optimizations. The code aims to present the core algorithms clearly so readers can follow how the model and attention mechanics are implemented.
Libraries such as Hugging Face Transformers are excellent but often introduce additional abstraction layers and hardware compatibility code that can obscure the raw behavior of large language models for newcomers.
This repository keeps the code simple by intentionally avoiding:
This project assumes you use uv for environment and task management: https://github.com/astral-sh/uv
uv sync
This implementation uses google/gemma-3-270m from the Hugging Face Hub.
uv run hf auth
Run the sample script (note: this requires a modest amount of VRAM):
uv run python main.py
This repository includes a Logit Lens implementation to visualize how the model refines its predictions layer by layer.
Run the analysis script to trace hidden states and attention weights. This creates a JSON file in the out/ directory.
uv run python logit_lens.py
Start the Streamlit app to explore the generated data interactively.
uv run streamlit run logit_lens_app.py
You can observe:
Issues and pull requests are welcome.
This code references and derives from Hugging Face Transformers and Google implementations. It is provided under the Apache-2.0 License, consistent with the original work. See LICENSE and NOTICE for details.
26 commits
Python
100.0%

This repository is an educational implementation of Google's Gemma 3 270M model, with readability and pedagogy prioritized over production inference optimizations. The code aims to present the core algorithms clearly so readers can follow how the model and attention mechanics are implemented.
Libraries such as Hugging Face Transformers are excellent but often introduce additional abstraction layers and hardware compatibility code that can obscure the raw behavior of large language models for newcomers.
This repository keeps the code simple by intentionally avoiding:
This project assumes you use uv for environment and task management: https://github.com/astral-sh/uv
uv sync
This implementation uses google/gemma-3-270m from the Hugging Face Hub.
uv run hf auth
Run the sample script (note: this requires a modest amount of VRAM):
uv run python main.py
This repository includes a Logit Lens implementation to visualize how the model refines its predictions layer by layer.
Run the analysis script to trace hidden states and attention weights. This creates a JSON file in the out/ directory.
uv run python logit_lens.py
Start the Streamlit app to explore the generated data interactively.
uv run streamlit run logit_lens_app.py
You can observe:
Issues and pull requests are welcome.
This code references and derives from Hugging Face Transformers and Google implementations. It is provided under the Apache-2.0 License, consistent with the original work. See LICENSE and NOTICE for details.
26 commits
Python
100.0%