Views
No views yet

| Property | Value |
|---|---|
| Parameters | ~11,900 |
| Training Tokens | 500,000 (FineWeb-Edu) |
| Context Window | 512 tokens |
| Hardware | RTX 4070 SUPER |
| Status | Base only, no SFT |
| Parameter | Value |
|---|---|
| Architecture | Transformer Decoder (LlamaForCausalLM) |
| Hidden Dimension | 16 |
| Layers | 2 |
| Attention Heads | 4 |
| KV Heads | 1 (GQA) |
| MLP Intermediate Size | 24 (SiLU activation) |
| Context Length | 512 tokens |
| Vocabulary Size | 512 |
| Normalization | RMSNorm, eps 1e-06 |
| Position Encoding | RoPE (default) |
| Embeddings | Tied input / output |
pip install torch transformers safetensors accelerate1"""
2Inference pipeline framework for Glint-Research/Glimmer-1-Base.
3Handles direct loading of structural safetensors and tokenization generation loops.
4"""
5
6import os
7import json
8import torch
9import torch.nn.functional as F
10from safetensors.torch import load_file
11from transformers import LlamaConfig, LlamaForCausalLM, AutoTokenizer
12
13class GlimmerInferencePipeline:
14 def __init__(self, model_path: str, device: str = None):
15 """
16 Initializes the model structure and updates weights directly
17 from the local repository directory.
18 """
19 if device is None:
20 self.device = "cuda" if torch.cuda.is_available() else "cpu"
21 else:
22 self.device = device
23
24 print(f"[*] Initializing Glimmer-1-Base runtime on engine: {self.device}")
25
26 config_file = os.path.join(model_path, "config.json")
27 if not os.path.exists(config_file):
28 raise FileNotFoundError(f"Could not locate config.json inside {model_path}")
29
30 with open(config_file, "r", encoding="utf-8") as f:
31 self.config_data = json.load(f)
32
33 self.config = LlamaConfig(**self.config_data)
34
35 print("[*] Loading tokenizer engine...")
36 self.tokenizer = AutoTokenizer.from_pretrained(model_path)
37
38 print("[*] Loading underlying safetensors architecture...")
39 self.model = LlamaForCausalLM(self.config)
40
41 weights_file = os.path.join(model_path, "model.safetensors")
42 if os.path.exists(weights_file):
43 state_dict = load_file(weights_file, device="cpu")
44 self.model.load_state_dict(state_dict, strict=True)
45 else:
46 raise FileNotFoundError(f"Could not find model.safetensors weight matrix in {model_path}")
47
48 self.model.to(self.device)
49 self.model.eval()
50 print("[+] Model stack fully loaded and verified.")
51
52 @torch.inference_mode()
53 def generate(
54 self,
55 prompt: str,
56 max_new_tokens: int = 50,
57 temperature: float = 0.7,
58 top_k: int = 50
59 ) -> str:
60 """
61 Executes causal autoregressive generation loop.
62 """
63 inputs = self.tokenizer(prompt, return_tensors="pt")
64 input_ids = inputs["input_ids"].to(self.device)
65
66 bos_token_id = self.config_data.get("bos_token_id", 1)
67 eos_token_id = self.config_data.get("eos_token_id", 2)
68
69 if input_ids.shape[1] == 0 or input_ids[0, 0] != bos_token_id:
70 bos_tensor = torch.tensor([[bos_token_id]], dtype=torch.long, device=self.device)
71 input_ids = torch.cat([bos_tensor, input_ids], dim=-1)
72
73 for _ in range(max_new_tokens):
74 outputs = self.model(input_ids)
75 next_token_logits = outputs.logits[:, -1, :]
76
77 if temperature > 0.0:
78 next_token_logits = next_token_logits / temperature
79
80 if top_k > 0:
81 indices_to_remove = next_token_logits < torch.topk(next_token_logits, top_k)[0][..., -1, None]
82 next_token_logits[indices_to_remove] = float('-inf')
83
84 probabilities = F.softmax(next_token_logits, dim=-1)
85 next_token = torch.multinomial(probabilities, num_samples=1)
86 else:
87 next_token = torch.argmax(next_token_logits, dim=-1, keepdim=True)
88
89 input_ids = torch.cat([input_ids, next_token], dim=-1)
90
91 if next_token.item() == eos_token_id:
92 break
93
94 # Transform resulting output block back into text
95 generated_output = self.tokenizer.decode(input_ids[0], skip_special_tokens=True)
96 return generated_output
97
98if __name__ == "__main__":
99 # Point execution context directly to repository path files
100 # Replace '.' with historical snapshot paths if running externally
101 LOCAL_REPO_DIR = "."
102
103 try:
104 pipeline = GlimmerInferencePipeline(model_path=LOCAL_REPO_DIR)
105
106 sample_prompt = "Deep learning architecture optimization requires"
107 print(f"\n[Prompt Input]: {sample_prompt}")
108
109 generated_text = pipeline.generate(
110 prompt=sample_prompt,
111 max_new_tokens=32,
112 temperature=0.85
113 )
114 print(f"[Generated Response]: {generated_text}\n")
115
116 except Exception as e:
117 print(f"[-] Execution Error failed: {str(e)}")
118 print("[!] Ensure config.json, tokenizer.json, and model.safetensors are inside the execution directory.")1@misc{glimmer1base2026,
2 author = {CompactAI},
3 title = {Glimmer-1: An 11.9K-Parameter Llama-Style Transformer},
4 year = {2026},
5 publisher = {Glint Research},
6 url = {https://huggingface.co/Glint-Research}
7}