Views
No views yet
1import torch
2import torch.nn.functional as F
3import tiktoken
4from huggingface_hub import hf_hub_download
5
6device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
7
8# 1. Download model weights from HuggingFace
9weights_path = hf_hub_download(repo_id="DanilKZ/TUPOI-1", filename="tupoi-300m.pt")
10
11# 2. Clone repository code for architecture definitions:
12# git clone https://github.com/starface77/TUPOI.git
13from tupoi import TUPOI300M, generate_text
14
15enc = tiktoken.get_encoding("gpt2")
16model = TUPOI300M(vocab_size=enc.n_vocab, d_model=1024, num_layers=24, d_ff=4096, max_seq_len=512).to(device)
17
18checkpoint = torch.load(weights_path, map_location=device)
19sd = checkpoint["model_state_dict"] if "model_state_dict" in checkpoint else checkpoint
20if "opinion_anchor.anchor_state" in sd:
21 del sd["opinion_anchor.anchor_state"]
22
23model.load_state_dict(sd, strict=False)
24model.eval()
25
26# 3. Generate text
27prompt = "Once upon a time, there was a little girl named Lily who"
28output = generate_text(model, enc, prompt=prompt, max_new_tokens=50, temperature=0.7)
29print(output)