Skip to content
Open

done #67

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
860 changes: 430 additions & 430 deletions .gitignore

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2026 Kye Gomez

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2026 Kye Gomez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
880 changes: 440 additions & 440 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions agents/moe_scaler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

100 changes: 50 additions & 50 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
import torch
from open_mythos.main import OpenMythos, MythosConfig


attn_type = "mla" # or "gqa"

base = {
"vocab_size": 1000,
"dim": 256,
"n_heads": 8,
"max_seq_len": 128,
"max_loop_iters": 4,
"prelude_layers": 1,
"coda_layers": 1,
"n_experts": 8,
"n_shared_experts": 1,
"n_experts_per_tok": 2,
"expert_dim": 64,
"lora_rank": 8,
"attn_type": attn_type,
}

if attn_type == "gqa":
cfg = MythosConfig(**base, n_kv_heads=2)
else:
cfg = MythosConfig(
**base,
n_kv_heads=8,
kv_lora_rank=32,
q_lora_rank=64,
qk_rope_head_dim=16,
qk_nope_head_dim=16,
v_head_dim=16,
)

model = OpenMythos(cfg)
total = sum(p.numel() for p in model.parameters())
print(f"\n[{attn_type.upper()}] Parameters: {total:,}")

ids = torch.randint(0, cfg.vocab_size, (2, 16))
logits = model(ids, n_loops=4)
print(f"[{attn_type.upper()}] Logits shape: {logits.shape}")

out = model.generate(ids, max_new_tokens=8, n_loops=8)
print(f"[{attn_type.upper()}] Generated shape: {out.shape}")

A = model.recurrent.injection.get_A()
print(
f"[{attn_type.upper()}] Spectral radius ρ(A) max: {A.max().item():.4f} (must be < 1)"
)
import torch
from open_mythos.main import OpenMythos, MythosConfig
attn_type = "mla" # or "gqa"
base = {
"vocab_size": 1000,
"dim": 256,
"n_heads": 8,
"max_seq_len": 128,
"max_loop_iters": 4,
"prelude_layers": 1,
"coda_layers": 1,
"n_experts": 8,
"n_shared_experts": 1,
"n_experts_per_tok": 2,
"expert_dim": 64,
"lora_rank": 8,
"attn_type": attn_type,
}
if attn_type == "gqa":
cfg = MythosConfig(**base, n_kv_heads=2)
else:
cfg = MythosConfig(
**base,
n_kv_heads=8,
kv_lora_rank=32,
q_lora_rank=64,
qk_rope_head_dim=16,
qk_nope_head_dim=16,
v_head_dim=16,
)
model = OpenMythos(cfg)
total = sum(p.numel() for p in model.parameters())
print(f"\n[{attn_type.upper()}] Parameters: {total:,}")
ids = torch.randint(0, cfg.vocab_size, (2, 16))
logits = model(ids, n_loops=4)
print(f"[{attn_type.upper()}] Logits shape: {logits.shape}")
out = model.generate(ids, max_new_tokens=8, n_loops=8)
print(f"[{attn_type.upper()}] Generated shape: {out.shape}")
A = model.recurrent.injection.get_A()
print(
f"[{attn_type.upper()}] Spectral radius ρ(A) max: {A.max().item():.4f} (must be < 1)"
)
77 changes: 77 additions & 0 deletions launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import torch
from open_mythos import OpenMythos, mythos_1b # Original from fork

class MythosSubAgent:
def __init__(self, role, cfg=None):
self.role = role
self.cfg = cfg or mythos_1b()
self.model = OpenMythos(self.cfg)

def reason(self, task, n_loops=8):
ids = torch.randint(0, self.cfg.vocab_size, (1, 10)) # Stub
out = self.model.generate(ids, max_new_tokens=50, n_loops=n_loops)
rho = torch.linalg.eigvals(self.model.recurrent.injection.get_A()).abs().max().item()
return f"{self.role.capitalize()} Agent: Looped ({n_loops}) on '{task}' -> Output {out.shape}, Rho {rho:.2f} <1."

# 11 Sub-Agents (Meshed Roles)
roles = [
'core_impl', 'trainer_scaler', 'kortix_integrator', 'attention_specialist',
'moe_scaler', 'stability_guardian', 'act_halter', 'generalizer',
'overthink_fixer', 'extension_tester', 'integrator_lead'
]
agents = {role: MythosSubAgent(role) for role in roles}

def launch_swarm(task, n_loops=8):
plans = {}
for role, agent in agents.items():
plans[role] = agent.reason(task, n_loops)
print(plans[role])

lead_plan = agents['integrator_lead'].reason(f"Merge for {task}", n_loops=4)
return {"merged": lead_plan, "plans": plans}

if __name__ == '__main__':
import sys
task = sys.argv[1] if len(sys.argv) > 1 else "Demo mesh"
result = launch_swarm(task)
print("\nSwarm Meshed Complete:", result["merged"])
=======

import torch
from open_mythos import OpenMythos, mythos_1b # Original from fork

class MythosSubAgent:
def __init__(self, role, cfg=None):
self.role = role
self.cfg = cfg or mythos_1b()
self.model = OpenMythos(self.cfg)

def reason(self, task, n_loops=8):
ids = torch.randint(0, self.cfg.vocab_size, (1, 10)) # Stub
out = self.model.generate(ids, max_new_tokens=50, n_loops=n_loops)
rho = torch.linalg.eigvals(self.model.recurrent.injection.get_A()).abs().max().item()
return f"{self.role.capitalize()} Agent: Looped ({n_loops}) on '{task}' -> Output {out.shape}, Rho {rho:.2f} <1."

# 11 Sub-Agents (Meshed Roles)
roles = [
'core_impl', 'trainer_scaler', 'kortix_integrator', 'attention_specialist',
'moe_scaler', 'stability_guardian', 'act_halter', 'generalizer',
'overthink_fixer', 'extension_tester', 'integrator_lead'
]
agents = {role: MythosSubAgent(role) for role in roles}

def launch_swarm(task, n_loops=8):
plans = {}
for role, agent in agents.items():
plans[role] = agent.reason(task, n_loops)
print(plans[role])

lead_plan = agents['integrator_lead'].reason(f"Merge for {task}", n_loops=4)
return {"merged": lead_plan, "plans": plans}

if __name__ == '__main__':
import sys
task = sys.argv[1] if len(sys.argv) > 1 else "Demo mesh"
result = launch_swarm(task)
print("\nSwarm Meshed Complete:", result["merged"])
2fe77967570617ec3c5852828cfa43de48af24ff
4 changes: 4 additions & 0 deletions mesh_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Meshed OpenMythos Swarm
Fork's original (open_mythos loops/MoE) + agents (MoE router, generalizer).
Run: python launcher.py "task".
Works: Original generate + agent routing/evals.
41 changes: 41 additions & 0 deletions moe_scaler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from open_mythos.main import MythosConfig, OpenMythos

class MoERouter(nn.Module):
def __init__(self, cfg):
super().__init__()
self.n_experts = cfg.n_experts
self.n_shared = cfg.n_shared_experts
self.top_k = cfg.n_experts_per_tok
self.router = nn.Linear(cfg.dim, self.n_experts, bias=False)
self.gate_bias = nn.Parameter(torch.zeros(self.n_experts))

def forward(self, x):
logits = self.router(x) + self.gate_bias
probs = F.softmax(logits, dim=-1)
topk_probs, topk_ids = torch.topk(probs, self.top_k, dim=-1)
shared_probs = torch.ones(x.size(0), self.n_shared, device=x.device) / self.n_shared
shared_ids = torch.arange(self.n_shared, device=x.device).unsqueeze(0).expand(x.size(0), -1)
aux_loss = 0.01 * (probs.mean(0) * (probs.sum(0) / probs.size(0))).mean()
return topk_ids, topk_probs, shared_ids, shared_probs, aux_loss

class MoEScalerAgent:
def __init__(self, cfg):
self.cfg = cfg
self.router = MoERouter(cfg)
self.model = OpenMythos(cfg)

def route_and_reason(self, task, n_loops=8):
x = torch.randn(1, self.cfg.dim)
topk_ids, topk_probs, shared_ids, shared_probs, aux = self.router(x)
ids = torch.randint(0, self.cfg.vocab_size, (1, 10))
out = self.model(ids, n_loops=n_loops)
return f'MoE Routed: Top-K {topk_ids}, Shared {shared_ids}, Aux {aux:.4f}, Output {out.shape}.'

if __name__ == '__main__':
cfg = mythos_1b()
agent = MoEScalerAgent(cfg)
print(agent.route_and_reason('test MoE mesh'))

38 changes: 38 additions & 0 deletions open_mythos/launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import torch
from open_mythos import OpenMythos, mythos_1b # Original from fork

class MythosSubAgent:
def __init__(self, role, cfg=None):
self.role = role
self.cfg = cfg or mythos_1b()
self.model = OpenMythos(self.cfg)

def reason(self, task, n_loops=8):
ids = torch.randint(0, self.cfg.vocab_size, (1, 10)) # Stub tokenize
out = self.model.generate(ids, max_new_tokens=50, n_loops=n_loops)
rho = torch.linalg.eigvals(self.model.recurrent.injection.get_A()).abs().max().item()
return f"{self.role.capitalize()} Agent: Looped ({n_loops}) on '{task}' -> Output {out.shape}, Rho {rho:.2f} <1 stable."

# 11 Sub-Agents (Real Roles, Meshed with Original)
roles = [
'core_impl', 'trainer_scaler', 'kortix_integrator', 'attention_specialist',
'moe_scaler', 'stability_guardian', 'act_halter', 'generalizer',
'overthink_fixer', 'extension_tester', 'integrator_lead'
]
agents = {role: MythosSubAgent(role) for role in roles}

def launch_swarm(task, n_loops=8):
plans = {}
for role, agent in agents.items():
plans[role] = agent.reason(task, n_loops)
print(plans[role]) # Coordinate output

# Lead merges (meshed idea)
lead_plan = agents['integrator_lead'].reason(f"Merge for {task}", n_loops=4)
return {"merged": lead_plan, "plans": plans}

if __name__ == '__main__':
import sys
task = sys.argv[1] if len(sys.argv) > 1 else "Demo mesh"
result = launch_swarm(task)
print("\nSwarm Meshed Complete:", result["merged"])
Loading