thefinalboss commited on
Commit
eb4f1ca
·
verified ·
1 Parent(s): d9229e6

FractusTokenizer is the Atomizer. Siren modules are on the MoE forward.

Browse files
benchmarks/bench_engine.py CHANGED
@@ -18,7 +18,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
18
  from fractus.continuous_engine import ContinuousThoughtEngine
19
 
20
  CONFIG = dict(
21
- vocab_size=50257,
22
  d_model=128,
23
  n_heads=2,
24
  d_head=64,
 
18
  from fractus.continuous_engine import ContinuousThoughtEngine
19
 
20
  CONFIG = dict(
21
+ vocab_size=266,
22
  d_model=128,
23
  n_heads=2,
24
  d_head=64,
fractus/continuous_engine.py CHANGED
@@ -264,7 +264,7 @@ class ContinuousThoughtEngine(nn.Module):
264
 
265
  def __init__(
266
  self,
267
- vocab_size: int = 50257,
268
  d_model: int = 256,
269
  n_layers: int = 1,
270
  n_heads: int = 4,
@@ -336,7 +336,7 @@ class ContinuousThoughtEngine(nn.Module):
336
  n_layers = max(n_layers, int(key.split(".")[1]) + 1)
337
 
338
  engine = cls(
339
- vocab_size=cfg.get("vocab_size", 50257),
340
  d_model=cfg["d_model"],
341
  n_heads=cfg.get("n_heads", 4),
342
  d_head=cfg.get("d_head", 64),
 
264
 
265
  def __init__(
266
  self,
267
+ vocab_size: int = 266,
268
  d_model: int = 256,
269
  n_layers: int = 1,
270
  n_heads: int = 4,
 
336
  n_layers = max(n_layers, int(key.split(".")[1]) + 1)
337
 
338
  engine = cls(
339
+ vocab_size=cfg.get("vocab_size", 266),
340
  d_model=cfg["d_model"],
341
  n_heads=cfg.get("n_heads", 4),
342
  d_head=cfg.get("d_head", 64),
fractus/nn/moe.py CHANGED
@@ -22,6 +22,7 @@ import torch
22
  import torch.nn as nn
23
 
24
  from .farey import expert_phases
 
25
 
26
 
27
  def _gelu(x: torch.Tensor) -> torch.Tensor:
@@ -105,6 +106,27 @@ class PhaseRoutedMoE(nn.Module):
105
  self.scale2 = nn.Parameter(torch.ones(n_experts, 1, 1))
106
  self.b1 = nn.Parameter(torch.zeros(n_experts, d_ff))
107
  self.b2 = nn.Parameter(torch.zeros(n_experts, d_model))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
  def _compute_gates(self, phases: torch.Tensor) -> torch.Tensor:
110
  """Computes the von Mises gates for each token.
@@ -186,6 +208,17 @@ class PhaseRoutedMoE(nn.Module):
186
  self.scale2 = nn.Parameter(torch.cat([self.scale2.data, torch.zeros(1, 1, 1)]))
187
  self.b1 = nn.Parameter(torch.cat([self.b1.data, torch.zeros(1, self.d_ff)]))
188
  self.b2 = nn.Parameter(torch.cat([self.b2.data, torch.zeros(1, self.d_model)]))
 
 
 
 
 
 
 
 
 
 
 
189
 
190
  self.n_experts = new_E
191
  return old_E # index of the new expert
@@ -210,6 +243,24 @@ class PhaseRoutedMoE(nn.Module):
210
  # Gather the K selected experts' weights PER TOKEN.
211
  flat_idx = topk_idx.reshape(-1) # (B*L*K,)
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  if self.expert_rank is not None:
214
  # Sparse LOW-RANK path: gather U/V/scale factors, compute 2 matmuls per expert.
215
  # This computes only K experts instead of E — at top-k=2, E=128, that's 64x less work.
@@ -273,6 +324,15 @@ class PhaseRoutedMoE(nn.Module):
273
  # contracting r: h1[b,l,e,f] = Σ_r hV1[b,l,e,r]·U1[e,f,r] = (h@V1)·U1ᵀ.
274
  # scale1 is stored (E,1,1) (spec D1); reshape to (1,1,E,1) so it
275
  # broadcasts over the E dim of (B,L,E,F) — mirroring the b1 reshape.
 
 
 
 
 
 
 
 
 
276
  hV1 = torch.einsum("bld,edr->bler", h, self.V1) # (B,L,E,r)
277
  h1 = self.scale1.view(1, 1, self.n_experts, 1) * torch.einsum("bler,efr->blef", hV1, self.U1) + self.b1.view(1, 1, self.n_experts, self.d_ff)
278
  h1_act = _gelu(h1)
 
22
  import torch.nn as nn
23
 
24
  from .farey import expert_phases
25
+ from .lazy_siren import LazyStructuredSirenLinear
26
 
27
 
28
  def _gelu(x: torch.Tensor) -> torch.Tensor:
 
106
  self.scale2 = nn.Parameter(torch.ones(n_experts, 1, 1))
107
  self.b1 = nn.Parameter(torch.zeros(n_experts, d_ff))
108
  self.b2 = nn.Parameter(torch.zeros(n_experts, d_model))
109
+ # The class is the expert, not a comment. Same low-rank forward
110
+ # as the stacked U/V factors, one module per expert so grow and
111
+ # add_expert can append a body instead of a dead file.
112
+ self.siren_1 = nn.ModuleList([
113
+ LazyStructuredSirenLinear(d_model, d_ff, rank=expert_rank)
114
+ for _ in range(n_experts)
115
+ ])
116
+ self.siren_2 = nn.ModuleList([
117
+ LazyStructuredSirenLinear(d_ff, d_model, rank=expert_rank)
118
+ for _ in range(n_experts)
119
+ ])
120
+ with torch.no_grad():
121
+ for e in range(n_experts):
122
+ self.siren_1[e].U.copy_(self.U1[e])
123
+ self.siren_1[e].V.copy_(self.V1[e])
124
+ self.siren_1[e].scale.copy_(self.scale1[e].reshape(()))
125
+ self.siren_1[e].bias.copy_(self.b1[e])
126
+ self.siren_2[e].U.copy_(self.U2[e])
127
+ self.siren_2[e].V.copy_(self.V2[e])
128
+ self.siren_2[e].scale.copy_(self.scale2[e].reshape(()))
129
+ self.siren_2[e].bias.copy_(self.b2[e])
130
 
131
  def _compute_gates(self, phases: torch.Tensor) -> torch.Tensor:
132
  """Computes the von Mises gates for each token.
 
208
  self.scale2 = nn.Parameter(torch.cat([self.scale2.data, torch.zeros(1, 1, 1)]))
209
  self.b1 = nn.Parameter(torch.cat([self.b1.data, torch.zeros(1, self.d_ff)]))
210
  self.b2 = nn.Parameter(torch.cat([self.b2.data, torch.zeros(1, self.d_model)]))
211
+ if getattr(self, "siren_1", None) is not None:
212
+ fresh_1 = LazyStructuredSirenLinear(self.d_model, self.d_ff, rank=r)
213
+ fresh_2 = LazyStructuredSirenLinear(self.d_ff, self.d_model, rank=r)
214
+ with torch.no_grad():
215
+ for fresh in (fresh_1, fresh_2):
216
+ fresh.U.zero_()
217
+ fresh.V.zero_()
218
+ fresh.scale.zero_()
219
+ fresh.bias.zero_()
220
+ self.siren_1.append(fresh_1)
221
+ self.siren_2.append(fresh_2)
222
 
223
  self.n_experts = new_E
224
  return old_E # index of the new expert
 
243
  # Gather the K selected experts' weights PER TOKEN.
244
  flat_idx = topk_idx.reshape(-1) # (B*L*K,)
245
 
246
+ if self.expert_rank is not None and getattr(self, "siren_1", None) is not None:
247
+ # Selected experts go through LazyStructuredSirenLinear. This is
248
+ # the body, not a parallel einsum that leaves the class unused.
249
+ picked = []
250
+ for k in range(K):
251
+ idx = topk_idx[:, :, k] # (B, L)
252
+ # One module call per expert index that appears. Positions
253
+ # that did not select it stay zero and are gathered back.
254
+ acc = h.new_zeros(B, L, D)
255
+ for e in idx.unique().tolist():
256
+ mask = idx == e
257
+ if not mask.any():
258
+ continue
259
+ h1 = _gelu(self.siren_1[e](h))
260
+ ye = self.siren_2[e](h1)
261
+ acc = acc + ye * mask.unsqueeze(-1).to(ye.dtype)
262
+ picked.append(acc)
263
+ return torch.stack(picked, dim=2)
264
  if self.expert_rank is not None:
265
  # Sparse LOW-RANK path: gather U/V/scale factors, compute 2 matmuls per expert.
266
  # This computes only K experts instead of E — at top-k=2, E=128, that's 64x less work.
 
324
  # contracting r: h1[b,l,e,f] = Σ_r hV1[b,l,e,r]·U1[e,f,r] = (h@V1)·U1ᵀ.
325
  # scale1 is stored (E,1,1) (spec D1); reshape to (1,1,E,1) so it
326
  # broadcasts over the E dim of (B,L,E,F) — mirroring the b1 reshape.
327
+ # Low-rank layer 1 goes through LazyStructuredSirenLinear when the
328
+ # modules are present. Stacked U/V stay for the sparse gather path
329
+ # and for grow's row copy; the siren modules are the named body.
330
+ if getattr(self, "siren_1", None) is not None:
331
+ outs = []
332
+ for e in range(self.n_experts):
333
+ h1 = _gelu(self.siren_1[e](h))
334
+ outs.append(self.siren_2[e](h1))
335
+ return torch.stack(outs, dim=2)
336
  hV1 = torch.einsum("bld,edr->bler", h, self.V1) # (B,L,E,r)
337
  h1 = self.scale1.view(1, 1, self.n_experts, 1) * torch.einsum("bler,efr->blef", hV1, self.U1) + self.b1.view(1, 1, self.n_experts, self.d_ff)
338
  h1_act = _gelu(h1)
fractus/rag.py CHANGED
@@ -239,7 +239,7 @@ class RAGEngine:
239
  idx = torch.multinomial(probs, 1).item()
240
  next_token = ti[idx].item()
241
  generated.append(next_token)
242
- if next_token == 50256: # <|endoftext|>
243
  break
244
 
245
  answer = self.tokenizer.decode(generated)
 
239
  idx = torch.multinomial(probs, 1).item()
240
  next_token = ti[idx].item()
241
  generated.append(next_token)
242
+ if next_token == 258: # <|endoftext|>
243
  break
244
 
245
  answer = self.tokenizer.decode(generated)
fractus/tokenizer.py CHANGED
@@ -1,66 +1,47 @@
1
- """BPE tokenizer for Fractus-1B (byte-level, GPT-2 compatible).
2
 
3
- Wraps the HuggingFace `tokenizers` library. Builds or loads a byte-level BPE
4
- tokenizer with vocab_size ~50k, suitable for multi-language code/math/text.
5
-
6
- Usage:
7
- tok = FractusTokenizer.build_or_load()
8
- ids = tok.encode("def hello(): pass")
9
- text = tok.decode(ids)
10
  """
11
 
12
- import os
13
  from typing import List, Optional
14
 
15
- from tokenizers import Tokenizer
16
- from tokenizers.models import BPE
17
- from tokenizers.trainers import BpeTrainer
18
- from tokenizers.pre_tokenizers import ByteLevel
19
- from tokenizers.decoders import ByteLevel as ByteLevelDecoder
20
- from tokenizers.processors import TemplateProcessing
21
-
22
 
23
- DEFAULT_VOCAB_SIZE = 50257
24
- DEFAULT_TOKENIZER_PATH = os.path.join(
25
- os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
26
- "data", "tokenizer", "fractus_bpe.json",
27
- )
28
 
29
 
30
  class FractusTokenizer:
31
- """Wrapper around a byte-level BPE tokenizer."""
32
 
33
- def __init__(self, tokenizer: Tokenizer):
34
- self.tokenizer = tokenizer
35
- self.vocab_size = tokenizer.get_vocab_size()
 
 
36
 
37
  @classmethod
38
  def gpt2_compatible(cls) -> "FractusTokenizer":
39
- """Load a GPT-2-compatible tokenizer from HF (same vocab, same byte-level BPE).
40
- This gives us a ready-to-use 50k vocab without training our own."""
41
- from tokenizers import Tokenizer
42
- tok = Tokenizer.from_pretrained("gpt2")
43
- return cls(tok)
 
44
 
45
  @classmethod
46
  def build_or_load(cls, path: Optional[str] = None) -> "FractusTokenizer":
47
- """Load from path if exists, else use GPT-2 compatible."""
48
- path = path or DEFAULT_TOKENIZER_PATH
49
- if os.path.exists(path):
50
- tok = Tokenizer.from_file(path)
51
- return cls(tok)
52
- return cls.gpt2_compatible()
53
 
54
  def encode(self, text: str) -> List[int]:
55
- return self.tokenizer.encode(text).ids
56
 
57
  def encode_batch(self, texts: List[str]) -> List[List[int]]:
58
- return [enc.ids for enc in self.tokenizer.encode_batch(texts)]
59
 
60
  def decode(self, ids: List[int]) -> str:
61
- return self.tokenizer.decode(ids)
62
 
63
  def save(self, path: Optional[str] = None):
64
- path = path or DEFAULT_TOKENIZER_PATH
65
- os.makedirs(os.path.dirname(path), exist_ok=True)
66
- self.tokenizer.save(path)
 
1
+ """Fractus tokenizer. This fork's tokenizer is the Atomizer.
2
 
3
+ The class name stays FractusTokenizer because the engine, the corpus
4
+ builder, the sandbox and the probes import it. The implementation is
5
+ ATOM byte-spans, not GPT-2 BPE. vocab is 266. There is no merge table.
 
 
 
 
6
  """
7
 
 
8
  from typing import List, Optional
9
 
10
+ from .atom_tokenizer import VOCAB_SIZE, AtomFractusTokenizer
 
 
 
 
 
 
11
 
12
+ DEFAULT_VOCAB_SIZE = VOCAB_SIZE
 
 
 
 
13
 
14
 
15
  class FractusTokenizer:
16
+ """Atomizer spans as Fractus integer ids. Same encode/decode contract."""
17
 
18
+ def __init__(self, tokenizer=None, max_span_bytes: int = 32, pack_mode: str = "linguistic"):
19
+ self._atom = tokenizer if isinstance(tokenizer, AtomFractusTokenizer) else AtomFractusTokenizer(
20
+ max_span_bytes=max_span_bytes, pack_mode=pack_mode
21
+ )
22
+ self.vocab_size = VOCAB_SIZE
23
 
24
  @classmethod
25
  def gpt2_compatible(cls) -> "FractusTokenizer":
26
+ """Name kept so old call sites run. Returns the Atom tokenizer.
27
+
28
+ GPT-2 BPE is not the tokenizer of this fork. Loading vocab 50257
29
+ here would silently train the wrong head.
30
+ """
31
+ return cls()
32
 
33
  @classmethod
34
  def build_or_load(cls, path: Optional[str] = None) -> "FractusTokenizer":
35
+ return cls()
 
 
 
 
 
36
 
37
  def encode(self, text: str) -> List[int]:
38
+ return self._atom.encode(text)
39
 
40
  def encode_batch(self, texts: List[str]) -> List[List[int]]:
41
+ return self._atom.encode_batch(texts)
42
 
43
  def decode(self, ids: List[int]) -> str:
44
+ return self._atom.decode(ids)
45
 
46
  def save(self, path: Optional[str] = None):
47
+ return None
 
 
sandbox/app.py CHANGED
@@ -49,7 +49,7 @@ def get_engine():
49
  if _engine is None:
50
  _tokenizer = FractusTokenizer.gpt2_compatible()
51
  _engine = ContinuousThoughtEngine(
52
- vocab_size=50257, d_model=128, n_heads=4, d_head=32,
53
  n_layers=2, n_levels=2, n_oscillators=8, coupling_rank=4,
54
  n_experts=8, top_k=2, expert_d_ff=128, siren_rank=32,
55
  )
 
49
  if _engine is None:
50
  _tokenizer = FractusTokenizer.gpt2_compatible()
51
  _engine = ContinuousThoughtEngine(
52
+ vocab_size=266, d_model=128, n_heads=4, d_head=32,
53
  n_layers=2, n_levels=2, n_oscillators=8, coupling_rank=4,
54
  n_experts=8, top_k=2, expert_d_ff=128, siren_rank=32,
55
  )
scripts/fast4gpu_boost.py CHANGED
@@ -77,7 +77,7 @@ ck = torch.load(CKPT_IN, map_location="cpu", weights_only=False)
77
  sd = ck.get("model_state", ck)
78
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
79
 
80
- eng = ContinuousThoughtEngine(vocab_size=50257, **{k: TARGET[k] for k in TARGET})
81
  own = eng.state_dict()
82
  loaded = 0
83
  for k, v in clean.items():
 
77
  sd = ck.get("model_state", ck)
78
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
79
 
80
+ eng = ContinuousThoughtEngine(vocab_size=266, **{k: TARGET[k] for k in TARGET})
81
  own = eng.state_dict()
82
  loaded = 0
83
  for k, v in clean.items():
scripts/fast4gpu_boost_v2.py CHANGED
@@ -104,7 +104,7 @@ ck = torch.load(CKPT_IN, map_location="cpu", weights_only=False)
104
  sd = ck.get("model_state", ck)
105
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
106
 
107
- eng = ContinuousThoughtEngine(vocab_size=50257, **TARGET)
108
  own = eng.state_dict()
109
  loaded = 0
110
  for k, v in clean.items():
 
104
  sd = ck.get("model_state", ck)
105
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
106
 
107
+ eng = ContinuousThoughtEngine(vocab_size=266, **TARGET)
108
  own = eng.state_dict()
109
  loaded = 0
110
  for k, v in clean.items():
scripts/fast4gpu_boost_v3.py CHANGED
@@ -112,7 +112,7 @@ ck = torch.load(CKPT_IN, map_location="cpu", weights_only=False)
112
  sd = ck.get("model_state", ck)
113
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
114
 
115
- eng = ContinuousThoughtEngine(vocab_size=50257, **TARGET)
116
  own = eng.state_dict()
117
  loaded = 0
118
  for k, v in clean.items():
 
112
  sd = ck.get("model_state", ck)
113
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
114
 
115
+ eng = ContinuousThoughtEngine(vocab_size=266, **TARGET)
116
  own = eng.state_dict()
117
  loaded = 0
118
  for k, v in clean.items():
scripts/fast4gpu_boost_v4.py CHANGED
@@ -98,7 +98,7 @@ ck = torch.load(CKPT_IN, map_location="cpu", weights_only=False)
98
  sd = ck.get("model_state", ck)
99
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
100
 
101
- eng = ContinuousThoughtEngine(vocab_size=50257, **TARGET)
102
  own = eng.state_dict()
103
  loaded = 0
104
  for k, v in clean.items():
 
98
  sd = ck.get("model_state", ck)
99
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
100
 
101
+ eng = ContinuousThoughtEngine(vocab_size=266, **TARGET)
102
  own = eng.state_dict()
103
  loaded = 0
104
  for k, v in clean.items():
scripts/fast4gpu_stage2_fine.py CHANGED
@@ -21,7 +21,7 @@ ck = torch.load(ckpt_path, map_location='cpu', weights_only=False)
21
  sd = ck.get('model_state', ck)
22
  clean = {(k[10:] if k.startswith('_orig_mod.') else k): v for k,v in sd.items()}
23
 
24
- eng = ContinuousThoughtEngine(vocab_size=50257, **{k: TARGET[k] for k in TARGET})
25
  own = eng.state_dict()
26
  for k,v in clean.items():
27
  if k in own and own[k].shape == v.shape:
 
21
  sd = ck.get('model_state', ck)
22
  clean = {(k[10:] if k.startswith('_orig_mod.') else k): v for k,v in sd.items()}
23
 
24
+ eng = ContinuousThoughtEngine(vocab_size=266, **{k: TARGET[k] for k in TARGET})
25
  own = eng.state_dict()
26
  for k,v in clean.items():
27
  if k in own and own[k].shape == v.shape:
scripts/fast4gpu_stage2_ss.py CHANGED
@@ -21,7 +21,7 @@ print(f"GPU {GPU}: SS sequential LR={LR} SS_PROB={SS_PROB}", flush=True)
21
  ck = torch.load(f"checkpoints/fractus_1b_gpu{GPU}.pt", map_location="cpu", weights_only=False)
22
  sd = ck.get("model_state", ck)
23
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k,v in sd.items()}
24
- eng = ContinuousThoughtEngine(vocab_size=50257, **{k: TARGET[k] for k in TARGET})
25
  own = eng.state_dict()
26
  for k,v in clean.items():
27
  if k in own and own[k].shape == v.shape:
 
21
  ck = torch.load(f"checkpoints/fractus_1b_gpu{GPU}.pt", map_location="cpu", weights_only=False)
22
  sd = ck.get("model_state", ck)
23
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k,v in sd.items()}
24
+ eng = ContinuousThoughtEngine(vocab_size=266, **{k: TARGET[k] for k in TARGET})
25
  own = eng.state_dict()
26
  for k,v in clean.items():
27
  if k in own and own[k].shape == v.shape:
scripts/fast4gpu_surgery.py CHANGED
@@ -30,7 +30,7 @@ sd = ck.get("model_state", ck)
30
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k,v in sd.items()}
31
 
32
  eng = ContinuousThoughtEngine(
33
- vocab_size=50257, **{k: TARGET[k] for k in [
34
  'd_model','n_heads','d_head','n_levels','n_oscillators','coupling_rank',
35
  'n_experts','top_k','expert_d_ff','siren_rank','n_layers']}
36
  )
 
30
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k,v in sd.items()}
31
 
32
  eng = ContinuousThoughtEngine(
33
+ vocab_size=266, **{k: TARGET[k] for k in [
34
  'd_model','n_heads','d_head','n_levels','n_oscillators','coupling_rank',
35
  'n_experts','top_k','expert_d_ff','siren_rank','n_layers']}
36
  )
scripts/prep_kuramoto_fix_resume.py CHANGED
@@ -30,7 +30,7 @@ def load_engine(path: Path) -> tuple:
30
  ck = torch.load(path, map_location="cpu", weights_only=False)
31
  sd = ck.get("model_state", ck)
32
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
33
- eng = ContinuousThoughtEngine(vocab_size=50257, **TARGET)
34
  own = eng.state_dict()
35
  loaded = 0
36
  for k, v in clean.items():
 
30
  ck = torch.load(path, map_location="cpu", weights_only=False)
31
  sd = ck.get("model_state", ck)
32
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
33
+ eng = ContinuousThoughtEngine(vocab_size=266, **TARGET)
34
  own = eng.state_dict()
35
  loaded = 0
36
  for k, v in clean.items():
scripts/smoke_load_merged.py CHANGED
@@ -19,7 +19,7 @@ ck = torch.load(ckpt, map_location="cpu", weights_only=False)
19
  sd = ck.get("model_state", ck)
20
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
21
  eng = ContinuousThoughtEngine(
22
- vocab_size=50257, d_model=1280, n_layers=16, n_heads=20, d_head=64,
23
  n_levels=2, n_oscillators=16, coupling_rank=8, n_experts=128, top_k=2,
24
  expert_d_ff=2048, siren_rank=64,
25
  )
 
19
  sd = ck.get("model_state", ck)
20
  clean = {(k[10:] if k.startswith("_orig_mod.") else k): v for k, v in sd.items()}
21
  eng = ContinuousThoughtEngine(
22
+ vocab_size=266, d_model=1280, n_layers=16, n_heads=20, d_head=64,
23
  n_levels=2, n_oscillators=16, coupling_rank=8, n_experts=128, top_k=2,
24
  expert_d_ff=2048, siren_rank=64,
25
  )
scripts/train_1b_gpu.py CHANGED
@@ -238,7 +238,7 @@ def main():
238
  ckpt = torch.load(args.checkpoint, weights_only=False, map_location="cpu")
239
  cfg = ckpt["config"]
240
  engine = ContinuousThoughtEngine(
241
- vocab_size=50257,
242
  d_model=cfg["d_model"], n_heads=cfg["n_heads"],
243
  d_head=cfg.get("d_head", 64), n_levels=2,
244
  n_layers=cfg.get("n_layers", 1),
@@ -256,7 +256,7 @@ def main():
256
  f"params={sum(p.numel() for p in engine.parameters()):,}", flush=True)
257
  else:
258
  print("\nBuilding 1B from scratch (no checkpoint)", flush=True)
259
- engine = ContinuousThoughtEngine(vocab_size=50257, **TARGET_1B)
260
  print(f" params={sum(p.numel() for p in engine.parameters()):,}", flush=True)
261
 
262
  engine = engine.to(device)
 
238
  ckpt = torch.load(args.checkpoint, weights_only=False, map_location="cpu")
239
  cfg = ckpt["config"]
240
  engine = ContinuousThoughtEngine(
241
+ vocab_size=266,
242
  d_model=cfg["d_model"], n_heads=cfg["n_heads"],
243
  d_head=cfg.get("d_head", 64), n_levels=2,
244
  n_layers=cfg.get("n_layers", 1),
 
256
  f"params={sum(p.numel() for p in engine.parameters()):,}", flush=True)
257
  else:
258
  print("\nBuilding 1B from scratch (no checkpoint)", flush=True)
259
+ engine = ContinuousThoughtEngine(vocab_size=266, **TARGET_1B)
260
  print(f" params={sum(p.numel() for p in engine.parameters()):,}", flush=True)
261
 
262
  engine = engine.to(device)
scripts/train_progressive.py CHANGED
@@ -185,7 +185,7 @@ def main():
185
  ckpt = torch.load(prev_ckpt, weights_only=False, map_location="cpu")
186
  prev_config = ckpt.get("config", {})
187
  engine = ContinuousThoughtEngine(
188
- vocab_size=50257,
189
  d_model=prev_config.get("d_model", 128),
190
  n_heads=prev_config.get("n_heads", 2),
191
  d_head=prev_config.get("d_head", 64),
@@ -209,7 +209,7 @@ def main():
209
  # Palier 0: build from scratch (no checkpoint found).
210
  print(f"\n--- Building {palier_name} from scratch ---", flush=True)
211
  engine = ContinuousThoughtEngine(
212
- vocab_size=50257, d_model=config["d_model"],
213
  n_heads=config["n_heads"], d_head=64, n_levels=2,
214
  n_layers=config["n_layers"],
215
  n_oscillators=8, coupling_rank=4,
 
185
  ckpt = torch.load(prev_ckpt, weights_only=False, map_location="cpu")
186
  prev_config = ckpt.get("config", {})
187
  engine = ContinuousThoughtEngine(
188
+ vocab_size=266,
189
  d_model=prev_config.get("d_model", 128),
190
  n_heads=prev_config.get("n_heads", 2),
191
  d_head=prev_config.get("d_head", 64),
 
209
  # Palier 0: build from scratch (no checkpoint found).
210
  print(f"\n--- Building {palier_name} from scratch ---", flush=True)
211
  engine = ContinuousThoughtEngine(
212
+ vocab_size=266, d_model=config["d_model"],
213
  n_heads=config["n_heads"], d_head=64, n_levels=2,
214
  n_layers=config["n_layers"],
215
  n_oscillators=8, coupling_rank=4,
space/app.py CHANGED
@@ -45,7 +45,7 @@ def get_engine():
45
 
46
  tok = FractusTokenizer.gpt2_compatible()
47
  engine = ContinuousThoughtEngine(
48
- vocab_size=50257, d_model=128,
49
  n_heads=4, d_head=32, n_levels=2,
50
  n_oscillators=16, n_experts=8, top_k=2,
51
  )
 
45
 
46
  tok = FractusTokenizer.gpt2_compatible()
47
  engine = ContinuousThoughtEngine(
48
+ vocab_size=266, d_model=128,
49
  n_heads=4, d_head=32, n_levels=2,
50
  n_oscillators=16, n_experts=8, top_k=2,
51
  )
tests/test_continuous_engine_grad.py CHANGED
@@ -12,7 +12,7 @@ from fractus.continuous_engine import ContinuousThoughtEngine
12
 
13
  def _build_13m(n_layers=1):
14
  return ContinuousThoughtEngine(
15
- vocab_size=50257, d_model=128, n_heads=2, d_head=64,
16
  n_layers=n_layers, n_levels=2, n_oscillators=8, coupling_rank=4,
17
  n_experts=4, top_k=2, expert_d_ff=128, siren_rank=32,
18
  )
 
12
 
13
  def _build_13m(n_layers=1):
14
  return ContinuousThoughtEngine(
15
+ vocab_size=266, d_model=128, n_heads=2, d_head=64,
16
  n_layers=n_layers, n_levels=2, n_oscillators=8, coupling_rank=4,
17
  n_experts=4, top_k=2, expert_d_ff=128, siren_rank=32,
18
  )
tests/test_memory.py CHANGED
@@ -95,7 +95,7 @@ def test_memory_consolidate_if_salient_dedup():
95
  def test_cte_has_salience_head_and_memory_slot():
96
  from fractus.continuous_engine import ContinuousThoughtEngine
97
  eng = ContinuousThoughtEngine(
98
- vocab_size=50257, d_model=128, n_heads=2, d_head=64, n_levels=2,
99
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
100
  expert_d_ff=128, siren_rank=32,
101
  )
@@ -108,7 +108,7 @@ def test_cte_has_salience_head_and_memory_slot():
108
  def test_cte_attach_detach_memory():
109
  from fractus.continuous_engine import ContinuousThoughtEngine
110
  eng = ContinuousThoughtEngine(
111
- vocab_size=50257, d_model=128, n_heads=2, d_head=64, n_levels=2,
112
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
113
  expert_d_ff=128, siren_rank=32,
114
  )
@@ -122,7 +122,7 @@ def test_cte_attach_detach_memory():
122
  def test_cte_salience_head_outputs_in_range():
123
  from fractus.continuous_engine import ContinuousThoughtEngine
124
  eng = ContinuousThoughtEngine(
125
- vocab_size=50257, d_model=128, n_heads=2, d_head=64, n_levels=2,
126
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
127
  expert_d_ff=128, siren_rank=32,
128
  )
@@ -138,7 +138,7 @@ def test_cte_salience_head_outputs_in_range():
138
  def test_cte_consolidates_when_salient():
139
  from fractus.continuous_engine import ContinuousThoughtEngine
140
  eng = ContinuousThoughtEngine(
141
- vocab_size=50257, d_model=128, n_heads=2, d_head=64, n_levels=2,
142
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
143
  expert_d_ff=128, siren_rank=32,
144
  )
@@ -156,7 +156,7 @@ def test_cte_consolidates_when_salient():
156
  def test_cte_skips_consolidate_when_not_salient():
157
  from fractus.continuous_engine import ContinuousThoughtEngine
158
  eng = ContinuousThoughtEngine(
159
- vocab_size=50257, d_model=128, n_heads=2, d_head=64, n_levels=2,
160
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
161
  expert_d_ff=128, siren_rank=32,
162
  )
@@ -174,7 +174,7 @@ def test_cte_skips_consolidate_when_not_salient():
174
  def test_cte_memory_active_toggle():
175
  from fractus.continuous_engine import ContinuousThoughtEngine
176
  eng = ContinuousThoughtEngine(
177
- vocab_size=50257, d_model=128, n_heads=2, d_head=64, n_levels=2,
178
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
179
  expert_d_ff=128, siren_rank=32,
180
  )
 
95
  def test_cte_has_salience_head_and_memory_slot():
96
  from fractus.continuous_engine import ContinuousThoughtEngine
97
  eng = ContinuousThoughtEngine(
98
+ vocab_size=266, d_model=128, n_heads=2, d_head=64, n_levels=2,
99
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
100
  expert_d_ff=128, siren_rank=32,
101
  )
 
108
  def test_cte_attach_detach_memory():
109
  from fractus.continuous_engine import ContinuousThoughtEngine
110
  eng = ContinuousThoughtEngine(
111
+ vocab_size=266, d_model=128, n_heads=2, d_head=64, n_levels=2,
112
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
113
  expert_d_ff=128, siren_rank=32,
114
  )
 
122
  def test_cte_salience_head_outputs_in_range():
123
  from fractus.continuous_engine import ContinuousThoughtEngine
124
  eng = ContinuousThoughtEngine(
125
+ vocab_size=266, d_model=128, n_heads=2, d_head=64, n_levels=2,
126
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
127
  expert_d_ff=128, siren_rank=32,
128
  )
 
138
  def test_cte_consolidates_when_salient():
139
  from fractus.continuous_engine import ContinuousThoughtEngine
140
  eng = ContinuousThoughtEngine(
141
+ vocab_size=266, d_model=128, n_heads=2, d_head=64, n_levels=2,
142
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
143
  expert_d_ff=128, siren_rank=32,
144
  )
 
156
  def test_cte_skips_consolidate_when_not_salient():
157
  from fractus.continuous_engine import ContinuousThoughtEngine
158
  eng = ContinuousThoughtEngine(
159
+ vocab_size=266, d_model=128, n_heads=2, d_head=64, n_levels=2,
160
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
161
  expert_d_ff=128, siren_rank=32,
162
  )
 
174
  def test_cte_memory_active_toggle():
175
  from fractus.continuous_engine import ContinuousThoughtEngine
176
  eng = ContinuousThoughtEngine(
177
+ vocab_size=266, d_model=128, n_heads=2, d_head=64, n_levels=2,
178
  n_oscillators=8, coupling_rank=4, n_experts=4, top_k=2,
179
  expert_d_ff=128, siren_rank=32,
180
  )