Views
No views yet


| Property | Saint Iberis d12 | Remarks |
|---|---|---|
| Total parameters | 376,240,128 (376M) | n_layer: 16, n_head: 16, n_kv_head: 16, n_embd: 1024 |
| Layers | 16 (9 slc2 + 7 attn) | attn layers: 1, 4, 7, 10, 11, 14, 15 |
| Vocabulary size | 65,536 | - |
| License | Apache | - |
y = B ⋅ ∏ᵢ₌ⱼ⁽ʲ⁺ᵏ⁾ Aᵢ ⋅ xᵢ1----------------------------------------
2Algorithm: SLC2
3----------------------------------------
4Input: x: (B, S, E)
5Output: y: (B, S, E)
6 1: alpha, A, B, x₁ <- Linear(x)
7 2: x₂: (B, S, E) <- Convolution1D(E, E)(SiLU(alpha)*A*x₁)
8 3: x₃: (B, S, E) <- B*SiLU(x₂)
9 4: y: (B, S, E) <- Linear(x₃)
10 5: return y
11----------------------------------------| Metric | BASE | MID | SFT | RL |
|---|---|---|---|---|
| CORE | 0.1501 | - | - | - |
| ARC-Challenge | - | 0.2491 | 0.2807 | - |
| ARC-Easy | - | 0.2563 | 0.2673 | - |
| GSM8K | - | 0.0167 | 0.0250 | - |
| HumanEval | - | 0.0305 | 0.0122 | - |
| MMLU | - | 0.2714 | 0.2735 | - |
| ChatCORE | - | 0.1785 | 0.1875 | - |
git clone https://github.com/Rikka-Botan/Liquid_Time_nanochat_jp.git1import os
2import sys
3import torch
4import json
5import time
6from huggingface_hub import hf_hub_download
7
8if not os.path.exists("Liquid_Time_nanochat_jp"):
9 os.system("git clone https://github.com/Rikka-Botan/Liquid_Time_nanochat_jp")
10
11os.chdir("Liquid_Time_nanochat_jp")
12sys.path.append(os.getcwd())
13
14from nanochat.gpt import GPT, GPTConfig
15from nanochat.tokenizer import RustBPETokenizer
16
17repo_id = "RikkaBotan/nanochat_saint_iberis_jp"
18model_file = "model_000825.pt"
19meta_file = "meta_000825.json"
20tokenizer_file = "tokenizer.pkl"
21
22local_pt_path = hf_hub_download(repo_id=repo_id, filename=model_file)
23local_meta_path = hf_hub_download(repo_id=repo_id, filename=meta_file)
24local_tokenizer_path = hf_hub_download(repo_id=repo_id, filename=tokenizer_file, local_dir=os.getcwd())
25
26with open(local_meta_path, "r", encoding="utf-8") as f:
27 meta_data = json.load(f)
28
29model_config = GPTConfig(**meta_data["model_config"])
30
31device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
32model = GPT(model_config).to(device)
33
34state_dict = torch.load(local_pt_path, map_location=device)
35state_dict = {k.removeprefix("_orig_mod."): v for k, v in state_dict.items()}
36model.load_state_dict(state_dict, strict=True)
37model.eval()
38
39tokenizer = RustBPETokenizer.from_directory(os.getcwd())
40
41try:
42 tokenizer.bos_token_id = tokenizer.enc.encode_single_token("<|bos|>")
43except KeyError:
44 tokenizer.bos_token_id = tokenizer.enc.encode_single_token("<|endoftext|>")
45
46tokenizer.user_start_id = tokenizer.enc.encode_single_token("<|user_start|>")
47tokenizer.user_end_id = tokenizer.enc.encode_single_token("<|user_end|>")
48tokenizer.assistant_start_id = tokenizer.enc.encode_single_token("<|assistant_start|>")
49tokenizer.assistant_end_id = tokenizer.enc.encode_single_token("<|assistant_end|>")
50tokenizer.stop_tokens = {tokenizer.assistant_end_id, tokenizer.bos_token_id}
51
52def format_conversation(tokenizer, history):
53 tokens = [tokenizer.bos_token_id]
54 for message in history:
55 role = message["role"]
56 content = message["content"]
57 content_tokens = tokenizer.encode(content)
58 if role == "user":
59 tokens.extend([tokenizer.user_start_id, *content_tokens, tokenizer.user_end_id])
60 elif role == "assistant":
61 tokens.extend([tokenizer.assistant_start_id, *content_tokens, tokenizer.assistant_end_id])
62 tokens.append(tokenizer.assistant_start_id)
63 return tokens
64
65def generate_reply(prompt, conv_history, temperature=0.7, top_k=20, top_p=0.8,
66 repetition_penalty=1.15, max_new_tokens=64):
67 conv_history.append({"role": "user", "content": prompt})
68 tokens = format_conversation(tokenizer, conv_history)
69 input_ids = torch.tensor(tokens, dtype=torch.long).unsqueeze(0).to(device)
70
71 stream = model.generate(
72 input_ids,
73 max_new_tokens=max_new_tokens,
74 temperature=temperature,
75 top_k=top_k,
76 top_p=top_p,
77 repetition_penalty=repetition_penalty,
78 )
79
80 buffer_text = ""
81 for token_id in stream:
82 text_piece = tokenizer.decode([token_id])
83 if text_piece == "<|assistant_end|>":
84 break
85 buffer_text += text_piece
86 conv_history.append({"role": "assistant", "content": buffer_text})
87 return buffer_text
88
89if __name__ == "__main__":
90 print("🌸 NanoChat - Saint Iberis CLI")
91 print("Type 'exit' to quit.\n")
92 conv_history = []
93
94 while True:
95 prompt = input("You: ")
96 if prompt.lower() in {"exit", "quit"}:
97 print("Goodbye!")
98 break
99
100 reply = generate_reply(prompt, conv_history)
101 print(f"AI: {reply}\n")