Views
No views yet
src folder) to run it.1# 1. Install dependencies
2# pip install transformers torch huggingface_hub
3
4import sys
5import os
6import torch
7from transformers import AutoTokenizer
8from huggingface_hub import snapshot_download
9
10# 2. Download the repository (Code + Weights)
11repo_path = snapshot_download(repo_id="Adx19/gemma-3-270m-tinystories")
12
13# 3. Add the downloaded folder to Python path so we can import 'src'
14sys.path.append(repo_path)
15
16# 4. Import Custom Model
17from src.model import Gemma3Model
18from src.config import GEMMA3_CONFIG_270M
19
20# 5. Load Model & Weights
21device = "cuda" if torch.cuda.is_available() else "cpu"
22model = Gemma3Model(GEMMA3_CONFIG_270M).to(device)
23
24weights_path = os.path.join(repo_path, "pytorch_model.bin")
25model.load_state_dict(torch.load(weights_path, map_location=device))
26model.eval()
27
28# 6. Load Tokenizer
29tokenizer = AutoTokenizer.from_pretrained("Adx19/gemma-3-270m-tinystories")
30
31# 7. Generate
32input_text = "Once upon a time"
33input_ids = tokenizer(input_text, return_tensors="pt")["input_ids"].to(device)
34
35with torch.no_grad():
36 output = model.generate(input_ids, max_new_tokens=50)
37
38print(tokenizer.decode(output[0], skip_special_tokens=True))