GGUFGuy NoviAIBot commited on
Commit
d39a477
·
0 Parent(s):

Duplicate from Novi-AI/Novi-Micro-Base

Browse files

Co-authored-by: Novi The Assistant <NoviAIBot@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ banner.jpg filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+
3
+ language:
4
+ - en
5
+ library_name: transformers
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - novi
9
+ - novi-micro
10
+ - causal-lm
11
+ - from-scratch
12
+ - bananaall
13
+
14
+ ---
15
+
16
+ # Novi-Micro-Base
17
+
18
+ ![Novi-Micro Banner](banner.jpg)
19
+
20
+ **Novi-Micro-Base** is a tiny causal language model trained from scratch by **Novi-AI**.
21
+
22
+ With approximately **5.04 million parameters**, Novi-Micro explores language modeling at a small scale while using a substantially larger context window and training corpus than earlier Novi models.
23
+
24
+ ⚡ **5.04M parameters · 1B training tokens · 2,048-token context**
25
+
26
+ ## Model Details
27
+
28
+ ### Architecture
29
+
30
+ Novi-Micro-Base uses a custom **BananaMind 2-style decoder architecture** with RMSNorm, Rotary Position Embeddings (RoPE), grouped-query attention, QK normalization, SwiGLU feed-forward layers, and tied input/output embeddings.
31
+
32
+ | Property | Value |
33
+ | ------------------ | --------------------------------: |
34
+ | Model type | Causal Language Model |
35
+ | Architecture | **BananaMind 2-style** |
36
+ | Parameters | **5.04M** |
37
+ | Vocabulary size | **16,384** |
38
+ | Context length | **2,048 tokens** |
39
+ | Attention | **Grouped-Query Attention (GQA)** |
40
+ | Position encoding | **RoPE** |
41
+ | Normalization | **RMSNorm** |
42
+ | Feed-forward | **SwiGLU** |
43
+ | QK normalization | **Enabled** |
44
+ | Embeddings | **Tied** |
45
+ | Training precision | **FP32** |
46
+
47
+ ## Training
48
+
49
+ Novi-Micro-Base was trained from scratch for approximately **1 billion tokens**.
50
+
51
+ The training configuration used a **5M parameter target**, a sequence length of **2,048 tokens**, and a single dataset source.
52
+
53
+ ### Training Configuration
54
+
55
+ | Setting | Value |
56
+ | --------------------- | ----------------: |
57
+ | Training mode | **Pretraining** |
58
+ | Target size | **5M parameters** |
59
+ | Actual parameters | **5.04M** |
60
+ | Training tokens | **1,000,000,000** |
61
+ | Sequence length | **2,048** |
62
+ | Batch size | **2** |
63
+ | Gradient accumulation | **8** |
64
+ | Effective batch size | **16 sequences** |
65
+ | Learning rate | **2 × 10⁻⁴** |
66
+ | Scheduler | **Cosine** |
67
+ | Warmup ratio | **3%** |
68
+ | Weight decay | **0.01** |
69
+ | Maximum gradient norm | **1.0** |
70
+ | Optimizer steps | **30,518** |
71
+ | Precision | **FP32** |
72
+ | Torch compile | **Enabled** |
73
+ | Random seed | **1337** |
74
+ | Checkpoint interval | **100 steps** |
75
+ | Logging interval | **10 steps** |
76
+
77
+ The model was trained until the selected **1,000,000,000-token target** was consumed.
78
+
79
+ ## Dataset
80
+
81
+ Novi-Micro-Base was trained using:
82
+
83
+ * **FineWeb-HQ**
84
+
85
+ The training configuration allocated a token target of exactly:
86
+
87
+ **1,000,000,000 tokens**
88
+
89
+ Documents were streamed from the dataset and packed into contiguous **2,048-token sequences** before being passed to the model.
90
+
91
+ ## Tokenizer
92
+
93
+ Novi-Micro uses a custom **byte-level BPE tokenizer** with a vocabulary size of **16,384 tokens**.
94
+
95
+ The tokenizer was trained from samples drawn from the training dataset before model pretraining.
96
+
97
+ Special tokens include:
98
+
99
+ * `[PAD]`
100
+ * `[BOS]`
101
+ * `[EOS]`
102
+ * `[UNK]`
103
+
104
+ The tokenizer uses ByteLevel pre-tokenization and decoding.
105
+
106
+ ## Architecture Details
107
+
108
+ Novi-Micro uses a decoder-only Transformer architecture.
109
+
110
+ ### Attention
111
+
112
+ The model uses **grouped-query attention (GQA)**, where multiple query heads share key and value heads.
113
+
114
+ Rotary Position Embeddings (**RoPE**) are applied to the query and key representations.
115
+
116
+ The BananaMind 2-style architecture also applies **RMSNorm to the query and key head dimensions**.
117
+
118
+ ### Feed-Forward Network
119
+
120
+ Each Transformer block uses a **SwiGLU** feed-forward network:
121
+
122
+ ```text
123
+ SwiGLU(x) = SiLU(gate(x)) × up(x)
124
+ ```
125
+
126
+ The result is projected back to the model's hidden dimension.
127
+
128
+ ### Normalization
129
+
130
+ The model uses **RMSNorm** before both the attention and feed-forward sublayers.
131
+
132
+ ### Embeddings
133
+
134
+ The input token embeddings and language-model output embeddings are **tied**, reducing the number of independent parameters.
135
+
136
+ ## Intended Use
137
+
138
+ Novi-Micro-Base is primarily intended for:
139
+
140
+ * 🔬 Research and experimentation
141
+ * 🧪 Small-model language-model experiments
142
+ * 🎓 Educational purposes
143
+ * 🛠️ Fine-tuning experiments
144
+ * 💻 Lightweight local inference
145
+ * 🤖 Exploring language modeling at the million-parameter scale
146
+
147
+ As a **base model**, Novi-Micro-Base is not instruction-tuned and is not specifically trained to follow user commands or behave as a conversational assistant.
148
+
149
+ ## Limitations
150
+
151
+ Novi-Micro-Base is a very small experimental language model.
152
+
153
+ With approximately **5 million parameters**, it is dramatically smaller than modern general-purpose language models and should not be expected to match their capabilities.
154
+
155
+ It may:
156
+
157
+ * Generate incoherent text
158
+ * Repeat phrases
159
+ * Produce factual errors
160
+ * Struggle with complex instructions
161
+ * Have limited world knowledge
162
+ * Perform poorly on difficult reasoning tasks
163
+ * Produce grammatically unusual text
164
+ * Fail to maintain coherent long-form generations
165
+
166
+ A 2,048-token context window does not eliminate the limitations caused by the model's small parameter count.
167
+
168
+ This model should be considered a **research and experimentation model**, rather than a production-ready general-purpose LLM.
169
+
170
+ ## Usage
171
+
172
+ ```python
173
+ from transformers import AutoTokenizer, AutoModelForCausalLM
174
+
175
+ model_id = "Novi-AI/Novi-Micro-Base"
176
+
177
+ tokenizer = AutoTokenizer.from_pretrained(
178
+ model_id,
179
+ trust_remote_code=True,
180
+ )
181
+
182
+ model = AutoModelForCausalLM.from_pretrained(
183
+ model_id,
184
+ trust_remote_code=True,
185
+ )
186
+
187
+ prompt = "Hello, my name is"
188
+
189
+ inputs = tokenizer(prompt, return_tensors="pt")
190
+
191
+ outputs = model.generate(
192
+ **inputs,
193
+ max_new_tokens=50,
194
+ )
195
+
196
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
197
+ ```
198
+
199
+ Because Novi-Micro uses a custom architecture, `trust_remote_code=True` is required when loading the model through Transformers.
200
+
201
+ ## Project History
202
+
203
+ Novi-Micro-Base is part of **Project Kairo**, the development codename for the Novi model project.
204
+
205
+ The Novi series follows the earlier **AppleMind** experiments and represents the primary model-development line of Novi-AI.
206
+
207
+ **AppleMind → Novi-Nano → Novi-Micro → future Novi models** 🚀
208
+
209
+ Novi-Micro substantially expands upon Novi-Nano by increasing the model to approximately **5.04M parameters**, expanding the context window from 256 to **2,048 tokens**, and training on approximately **1 billion tokens**.
210
+
211
+ ## Training Infrastructure
212
+
213
+ The model was trained using GPU compute through the **BananaAll** training environment.
214
+
215
+ The training worker supports GPU acceleration through CUDA and Intel XPU, with Torch compilation enabled for supported environments.
216
+
217
+ This model was trained from scratch rather than fine-tuned from an existing language model checkpoint.
218
+
219
+ ## Acknowledgements
220
+
221
+ Novi-Micro was built using the open-source machine-learning ecosystem and datasets made available by the community.
222
+
223
+ Special thanks to:
224
+
225
+ * Hugging Face 🤗
226
+ * FineWeb
227
+ * FineWeb-HQ
228
+ * The open-source Transformers ecosystem
229
+
230
+ ## License
231
+
232
+ This model is released under the **Apache 2.0** license.
233
+
234
+ ---
235
+
236
+ ## 🧠 Novi AI
237
+
238
+ **Small models. Big experiments.**
239
+
240
+ Novi-Micro is intentionally tiny — exploring how far a language model can go with only a few million parameters and approximately one billion training tokens.
241
+
242
+ *Novi AI 2026 — Project Kairo*
243
+
banner.jpg ADDED

Git LFS Details

  • SHA256: a6ceb8a1a47c82fe863899dbf7f2a3b12acdef5a51e639ef3a93e950e8001844
  • Pointer size: 131 Bytes
  • Size of remote file: 609 kB
config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture_style": "bananamind2",
3
+ "architectures": [
4
+ "BananaAllForCausalLM"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_bananaall.BananaAllConfig",
8
+ "AutoModelForCausalLM": "modeling_bananaall.BananaAllForCausalLM"
9
+ },
10
+ "bos_token_id": 1,
11
+ "dtype": "float32",
12
+ "eos_token_id": 2,
13
+ "head_dim": 40,
14
+ "hidden_size": 160,
15
+ "intermediate_size": 864,
16
+ "lft": false,
17
+ "max_position_embeddings": 4096,
18
+ "model_type": "bananaall",
19
+ "num_attention_heads": 4,
20
+ "num_hidden_layers": 9,
21
+ "num_key_value_heads": 2,
22
+ "pad_token_id": 0,
23
+ "rms_norm_eps": 1e-06,
24
+ "rope_theta": 100000.0,
25
+ "ternary": false,
26
+ "tie_word_embeddings": true,
27
+ "transformers_version": "5.14.1",
28
+ "use_cache": false,
29
+ "vocab_size": 3840
30
+ }
configuration_bananaall.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+
4
+ class BananaAllConfig(PretrainedConfig):
5
+ model_type = "bananaall"
6
+
7
+ def __init__(self, vocab_size=8192, hidden_size=384, num_hidden_layers=14,
8
+ num_attention_heads=6, num_key_value_heads=2, head_dim=64,
9
+ intermediate_size=1024, max_position_embeddings=4096,
10
+ rope_theta=100000.0, rms_norm_eps=1e-6, architecture_style="bananamind2",
11
+ lft=False, ternary=False, **kwargs):
12
+ kwargs.setdefault("tie_word_embeddings", True)
13
+ super().__init__(**kwargs)
14
+ self.vocab_size = vocab_size
15
+ self.hidden_size = hidden_size
16
+ self.num_hidden_layers = num_hidden_layers
17
+ self.num_attention_heads = num_attention_heads
18
+ self.num_key_value_heads = num_key_value_heads
19
+ self.head_dim = head_dim
20
+ self.intermediate_size = intermediate_size
21
+ self.max_position_embeddings = max_position_embeddings
22
+ self.rope_theta = rope_theta
23
+ self.rms_norm_eps = rms_norm_eps
24
+ self.architecture_style = architecture_style
25
+ self.lft = lft
26
+ self.ternary = ternary
27
+ self.use_cache = False
dataset_tokens.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "dataset": "epfml/FineWeb-HQ",
4
+ "tokens": 1000000000
5
+ }
6
+ ]
generation_config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": [
5
+ 2
6
+ ],
7
+ "output_attentions": false,
8
+ "output_hidden_states": false,
9
+ "pad_token_id": 0,
10
+ "transformers_version": "5.14.1",
11
+ "use_cache": false
12
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d49880f3a4fd633a297a770f2d3a5e542d290f98167e744a740cb787eb01765
3
+ size 22634608
modeling_bananaall.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """BananaMind 2 style decoder with optional LFT or ternary fake quantization.
2
+
3
+ The model uses pre-RMSNorm, RoPE, grouped-query attention, SwiGLU and tied
4
+ embeddings. BananaMind 2 mode also applies QK norm. LFT changes only routing.
5
+ Ternary mode uses floating-point master weights and fake-quantized projections.
6
+ """
7
+ import math
8
+ import torch
9
+ from torch import nn
10
+ from torch.nn import functional as F
11
+ from transformers import PreTrainedModel
12
+ from transformers.generation import GenerationMixin
13
+ from transformers.modeling_outputs import CausalLMOutputWithPast
14
+
15
+ try:
16
+ from .configuration_bananaall import BananaAllConfig
17
+ except ImportError:
18
+ from configuration_bananaall import BananaAllConfig
19
+
20
+
21
+ class RMSNorm(nn.Module):
22
+ def __init__(self, size, eps=1e-6):
23
+ super().__init__()
24
+ self.weight = nn.Parameter(torch.ones(size))
25
+ self.eps = eps
26
+
27
+ def forward(self, x):
28
+ y = x.float()
29
+ return (y * torch.rsqrt(y.square().mean(-1, keepdim=True) + self.eps) * self.weight.float()).to(x.dtype)
30
+
31
+
32
+ class TernaryLinear(nn.Linear):
33
+ """W1.58A8 fake quantization with straight-through gradients.
34
+
35
+ The master weights remain floating point for optimization and checkpoints.
36
+ This layer does not pack ternary weights or use a low-bit inference kernel.
37
+ """
38
+
39
+ def forward(self, x):
40
+ weights = self.weight.float()
41
+ weight_scale = weights.detach().abs().mean().clamp_min(1e-6)
42
+ quantized_weights = (weights / weight_scale).round().clamp(-1, 1) * weight_scale
43
+ fake_weights = self.weight + (quantized_weights.to(self.weight.dtype) - self.weight).detach()
44
+
45
+ activations = x.float()
46
+ activation_scale = activations.detach().abs().amax(dim=-1, keepdim=True).clamp_min(1e-6) / 127
47
+ quantized_activations = (activations / activation_scale).round().clamp(-127, 127) * activation_scale
48
+ fake_activations = x + (quantized_activations.to(x.dtype) - x).detach()
49
+ return F.linear(fake_activations, fake_weights, self.bias)
50
+
51
+
52
+ def apply_rope(x, theta, position_ids):
53
+ dim = x.shape[-1]
54
+ inv = 1.0 / (theta ** (torch.arange(0, dim, 2, device=x.device, dtype=torch.float32) / dim))
55
+ angles = position_ids.float().unsqueeze(-1) * inv
56
+ cos = angles.cos().unsqueeze(1).to(x.dtype)
57
+ sin = angles.sin().unsqueeze(1).to(x.dtype)
58
+ even, odd = x[..., ::2], x[..., 1::2]
59
+ return torch.stack((even * cos - odd * sin, even * sin + odd * cos), dim=-1).flatten(-2)
60
+
61
+
62
+ class Attention(nn.Module):
63
+ def __init__(self, config):
64
+ super().__init__()
65
+ h, d, kv = config.num_attention_heads, config.head_dim, config.num_key_value_heads
66
+ self.h, self.d, self.kv, self.theta = h, d, kv, config.rope_theta
67
+ linear = TernaryLinear if config.ternary else nn.Linear
68
+ self.q_proj = linear(config.hidden_size, h * d, bias=False)
69
+ self.k_proj = linear(config.hidden_size, kv * d, bias=False)
70
+ self.v_proj = linear(config.hidden_size, kv * d, bias=False)
71
+ self.o_proj = linear(h * d, config.hidden_size, bias=False)
72
+ self.q_norm = RMSNorm(d, config.rms_norm_eps) if config.architecture_style == "bananamind2" else nn.Identity()
73
+ self.k_norm = RMSNorm(d, config.rms_norm_eps) if config.architecture_style == "bananamind2" else nn.Identity()
74
+
75
+ def forward(self, x, attention_mask=None):
76
+ b, t, _ = x.shape
77
+ q = self.q_norm(self.q_proj(x).view(b, t, self.h, self.d).transpose(1, 2))
78
+ k = self.k_norm(self.k_proj(x).view(b, t, self.kv, self.d).transpose(1, 2))
79
+ v = self.v_proj(x).view(b, t, self.kv, self.d).transpose(1, 2)
80
+ positions = torch.arange(t, device=x.device).unsqueeze(0)
81
+ q, k = apply_rope(q, self.theta, positions), apply_rope(k, self.theta, positions)
82
+ k = k.repeat_interleave(self.h // self.kv, dim=1)
83
+ v = v.repeat_interleave(self.h // self.kv, dim=1)
84
+ if attention_mask is None:
85
+ y = F.scaled_dot_product_attention(q, k, v, is_causal=True)
86
+ else:
87
+ causal = torch.ones(t, t, device=x.device, dtype=torch.bool).tril()
88
+ mask = causal[None, None] & attention_mask[:, None, None, :].bool()
89
+ y = F.scaled_dot_product_attention(q, k, v, attn_mask=mask)
90
+ return self.o_proj(y.transpose(1, 2).contiguous().view(b, t, self.h * self.d))
91
+
92
+
93
+ class Block(nn.Module):
94
+ def __init__(self, config):
95
+ super().__init__()
96
+ self.norm1 = RMSNorm(config.hidden_size, config.rms_norm_eps)
97
+ self.attn = Attention(config)
98
+ self.norm2 = RMSNorm(config.hidden_size, config.rms_norm_eps)
99
+ linear = TernaryLinear if config.ternary else nn.Linear
100
+ self.gate_proj = linear(config.hidden_size, config.intermediate_size, bias=False)
101
+ self.up_proj = linear(config.hidden_size, config.intermediate_size, bias=False)
102
+ self.down_proj = linear(config.intermediate_size, config.hidden_size, bias=False)
103
+
104
+ def forward(self, x, attention_mask=None):
105
+ x = x + self.attn(self.norm1(x), attention_mask)
106
+ z = self.norm2(x)
107
+ return x + self.down_proj(F.silu(self.gate_proj(z)) * self.up_proj(z))
108
+
109
+
110
+ class BananaAllForCausalLM(PreTrainedModel, GenerationMixin):
111
+ config_class = BananaAllConfig
112
+ base_model_prefix = "model"
113
+ _supports_sdpa = True
114
+ # forward() returns a mean loss per microbatch and ignores **kwargs.
115
+ # Tell Trainer to divide it by the gradient-accumulation count.
116
+ accepts_loss_kwargs = False
117
+
118
+ def __init__(self, config):
119
+ super().__init__(config)
120
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size)
121
+ self.layers = nn.ModuleList([Block(config) for _ in range(config.num_hidden_layers)])
122
+ self.norm = RMSNorm(config.hidden_size, config.rms_norm_eps)
123
+ self.lm_head = (TernaryLinear if config.ternary else nn.Linear)(config.hidden_size, config.vocab_size, bias=False)
124
+ self.post_init()
125
+ self.tie_weights()
126
+
127
+ def get_input_embeddings(self):
128
+ return self.embed_tokens
129
+
130
+ def set_input_embeddings(self, value):
131
+ self.embed_tokens = value
132
+
133
+ def get_output_embeddings(self):
134
+ return self.lm_head
135
+
136
+ def set_output_embeddings(self, value):
137
+ self.lm_head = value
138
+
139
+ def forward(self, input_ids=None, attention_mask=None, labels=None, **kwargs):
140
+ x = self.embed_tokens(input_ids)
141
+ if self.config.lft and len(self.layers) > 1:
142
+ x = self.layers[0](x, attention_mask)
143
+ for i in range(1, len(self.layers)):
144
+ x = self.layers[i](x, attention_mask)
145
+ if i < len(self.layers) - 1:
146
+ x = self.layers[i - 1](x, attention_mask)
147
+ x = self.layers[i](x, attention_mask)
148
+ else:
149
+ for layer in self.layers:
150
+ x = layer(x, attention_mask)
151
+ logits = self.lm_head(self.norm(x))
152
+ loss = None
153
+ if labels is not None:
154
+ shifted_logits = logits[:, :-1, :].contiguous().float()
155
+ shifted_labels = labels[:, 1:].contiguous()
156
+ loss = F.cross_entropy(shifted_logits.view(-1, shifted_logits.size(-1)), shifted_labels.view(-1), ignore_index=-100)
157
+ return CausalLMOutputWithPast(loss=loss, logits=logits, past_key_values=None)
158
+
159
+ def prepare_inputs_for_generation(self, input_ids, attention_mask=None, **kwargs):
160
+ return {"input_ids": input_ids, "attention_mask": attention_mask}
161
+
162
+
163
+ def register():
164
+ from transformers import AutoConfig, AutoModelForCausalLM
165
+ try:
166
+ AutoConfig.register("bananaall", BananaAllConfig)
167
+ except ValueError:
168
+ pass
169
+ try:
170
+ AutoModelForCausalLM.register(BananaAllConfig, BananaAllForCausalLM)
171
+ except ValueError:
172
+ pass
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "[BOS]",
4
+ "eos_token": "[EOS]",
5
+ "model_max_length": 2048,
6
+ "pad_token": "[PAD]",
7
+ "tokenizer_class": "TokenizersBackend",
8
+ "unk_token": "[UNK]"
9
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2b83efc3b4aacda4749a21a5d8119c1f2900aff097df50646a039e98da988de
3
+ size 5201