加载中…
加载中…
This repository contains a PyTorch implementation of the Google's Gemma3 model with 270 million parameters, trained from scratch on the TinyStories dataset.
This model is based on Google DeepMind's Gemma3 architecture and was built from the ground up to explore training dynamics, architecture design, and generation quality of small LLMs. It includes advanced components such as:
Sliding Window Attention (512-token window)
Rotary Positional Embeddings (RoPE)
RMSNorm for stable training
Grouped Key-Value Attention (1 KV group)
Dataset: TinyStories by Roneneldan
Steps: 150,000 steps (not epochs)
Batch Size: 32
Loss Function: Cross-Entropy
Optimizer: AdamW
LR Scheduler: Linear Warmup + Cosine Decay
Hardware: Single NVIDIA A100 GPU
pip install git+https://huggingface.co/Shubhamw11/Gemma-270M-TinyStories
You can now load and use the model from the gemma3_tinystories library:
from gemma3_tinystories import HFGemma3Model, Gemma3Config
import tiktoken
import torch
config = Gemma3Config.from_pretrained("Shubhamw11/Gemma-270M-TinyStories")
model = HFGemma3Model.from_pretrained("Shubhamw11/Gemma-270M-TinyStories", config=config).model
tokenizer = tiktoken.get_encoding("gpt2")
#define the device
device = "cuda" if torch.cuda.is_available() else "cpu"
input_text = "Once upon a time, there was a little"
context = torch.tensor(tokenizer.encode(input_text), dtype=torch.long).unsqueeze(0).to(device)
model.to(device)
response = model.generate(context, max_new_tokens=200, temperature=1.1, top_k=5)
print(tokenizer.decode(response.squeeze().tolist()))