Taviel brain modules: scripture hands, TempTorus memory, LLM door, eval battery
Browse files- code/gen_at_depth.py +139 -0
code/gen_at_depth.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
r"""Phase G -- GEN-AT-DEPTH: actually RUN a servable chakra-tier (a real GGUF) via
|
| 3 |
+
the existing llama-server launcher and GENERATE tokens at a chosen depth (the
|
| 4 |
+
"deep slow stream"). Machine-first: ONE tier resident at a time; his VRAM_CAP_MB
|
| 5 |
+
(683, "one third") is respected first -- the auto-fit ladder settles at ngl=0
|
| 6 |
+
(all weights CPU/mmap) for the big models, which still runs; only if a tier
|
| 7 |
+
REFUSES under the third do we disclose and offer a raised cap. Unload after.
|
| 8 |
+
|
| 9 |
+
TAV chakra -> Adelic tier (grades 1-5). GGUF tiers run direct; the safetensors
|
| 10 |
+
tiers (Third Eye 1B / Throat 8B) take the torus-retrofit path (later) or an
|
| 11 |
+
on-disk GGUF proxy -- disclosed.
|
| 12 |
+
"""
|
| 13 |
+
from __future__ import annotations
|
| 14 |
+
|
| 15 |
+
import sys
|
| 16 |
+
import time
|
| 17 |
+
|
| 18 |
+
sys.path.insert(0, r"D:\Holorites\torus_upgrades")
|
| 19 |
+
import phase30_model as PM # noqa: E402
|
| 20 |
+
|
| 21 |
+
# chakra -> (port, gguf path, adelic tier note). One resident at a time on 4 GB.
|
| 22 |
+
TIERS = {
|
| 23 |
+
"heart": (8103, r"D:\sneedjak_models\Adelic-Gemma-4-12B-GGUF\adelic-gemma4-12b-Q6_K.gguf",
|
| 24 |
+
"grade 3 / 12B / relation-continuity"),
|
| 25 |
+
"solar": (8104, r"D:\sneedjak_models\Adelic-Qwen3.6-27B-Topology\adelic-qwen-27b-q8_0.gguf",
|
| 26 |
+
"grade 4 / 27B / verify-contradiction"),
|
| 27 |
+
"sacral": (8105, r"D:\sneedjak_models\Adelic-Gemma-4-31B-it\adelic-gemma4-31b-Q4_K_M.gguf",
|
| 28 |
+
"grade 5 / 31B / deep synthesis"),
|
| 29 |
+
# fast tiers are safetensors -> on-disk GGUF proxies until the retrofit path:
|
| 30 |
+
"throat": (8102, r"D:\0000_Raw_LLM Models\Qwen3-8B-abliterated.Q4_K_M.gguf",
|
| 31 |
+
"grade 2 / 8B proxy / language"),
|
| 32 |
+
# the PHONE'S OWN MIND, resident on the desktop for 1:1 evaluation of mobile Tav'iel
|
| 33 |
+
"root": (8106, r"D:\0000_Raw_LLM Models\Qwen2.5-1.5B-Instruct-Q4_K_M.gguf",
|
| 34 |
+
"grade 0 / 1.5B / the mobile tier"),
|
| 35 |
+
"third_eye": (8101, r"D:\0000_Raw_LLM Models\Qwen3-0.6B-Q8_0.gguf",
|
| 36 |
+
"grade 1 / 0.6B proxy / recognition-routing"),
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def open_tier(chakra, cap_mb=683, total_mb=4096, ctx=2048):
|
| 41 |
+
"""Start one chakra-tier's llama-server, auto-fitting under the VRAM cap.
|
| 42 |
+
Returns a live LlamaModel (its own __enter__ already run) or raises VramRefusal.
|
| 43 |
+
Respects his 683 'third' by default; raise cap_mb only when a tier needs it."""
|
| 44 |
+
if chakra not in TIERS:
|
| 45 |
+
raise KeyError("unknown chakra %r; have %s" % (chakra, list(TIERS)))
|
| 46 |
+
port, path, note = TIERS[chakra]
|
| 47 |
+
PM.VRAM_CAP_MB = cap_mb # runtime override (this process only)
|
| 48 |
+
print("[gen] opening %s tier (%s) on port %d, cap %d MB ..." % (chakra, note, port, cap_mb),
|
| 49 |
+
flush=True)
|
| 50 |
+
# start the ladder at ngl=0 (all CPU/mmap) so a big GGUF with no MEASURED entry
|
| 51 |
+
# does NOT try to load all layers onto the 4 GB card and time out. MEASURED
|
| 52 |
+
# tiers (0.6B/8B) ignore this and use their tuned ladder.
|
| 53 |
+
#
|
| 54 |
+
# RESOURCE-BOUNDED STREAMING for the big tiers: heart 12B / solar 27B / sacral 31B are the
|
| 55 |
+
# disk-streamed voices. They are GUARANTEED never to overload the box -- they run at IDLE OS
|
| 56 |
+
# priority (only spare CPU cycles), on just a few threads (cores stay free for the RAM voice
|
| 57 |
+
# + other apps), with a small batch and a bounded context (bounded KV memory), and mmap keeps
|
| 58 |
+
# the weights paging from disk instead of all in RAM. That is the trickle: they still flow
|
| 59 |
+
# and contribute, but they physically cannot starve the system.
|
| 60 |
+
BIG = {"heart", "solar", "sacral"}
|
| 61 |
+
if chakra in BIG:
|
| 62 |
+
# below-normal priority (yields to the RAM voice + his foreground apps, so it can never
|
| 63 |
+
# overload) but NOT dead-idle, so it still progresses to an answer -- a real trickle that
|
| 64 |
+
# reaches B. Capped threads + small batch + bounded ctx + mmap keep it bounded.
|
| 65 |
+
m = PM.LlamaModel(path, gpu_layers=0, ctx=min(ctx, 2048), port=port, total_mb=total_mb,
|
| 66 |
+
threads=4, priority="belownormal", batch=128)
|
| 67 |
+
else:
|
| 68 |
+
m = PM.LlamaModel(path, gpu_layers=0, ctx=ctx, port=port, total_mb=total_mb)
|
| 69 |
+
m.__enter__() # auto-fit ladder -> ngl; VramRefusal if none
|
| 70 |
+
m._chakra = chakra
|
| 71 |
+
return m
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def generate(m, prompt, grounding="", max_tokens=160, temperature=0.7, system=None):
|
| 75 |
+
"""Generate at this tier's depth. `grounding` (lexicon/Bible/etc) is prepended
|
| 76 |
+
to the user prompt; `system` (an identity/instruction) goes to the system role
|
| 77 |
+
-- the model carries language, the grounding carries the truth."""
|
| 78 |
+
full = (grounding.rstrip() + "\n\n" + prompt) if grounding else prompt
|
| 79 |
+
t0 = time.time()
|
| 80 |
+
text = m.complete(full, max_tokens=max_tokens, temperature=temperature, system=system)
|
| 81 |
+
dt = time.time() - t0
|
| 82 |
+
# truncate at any chat-template turn marker OR special/multimodal token the model
|
| 83 |
+
# echoed past its answer (Gemma-4 is multimodal -- its <image|> token can loop
|
| 84 |
+
# at ngl=0; the coherent text prefix before it is the answer).
|
| 85 |
+
for mark in ("<|im_end|>", "<|im_start|>", "<end_of_turn>", "<start_of_turn>",
|
| 86 |
+
"<image", "<unused", "<pad>", "<eos>"):
|
| 87 |
+
i = text.find(mark)
|
| 88 |
+
if i != -1:
|
| 89 |
+
text = text[:i]
|
| 90 |
+
text = text.strip()
|
| 91 |
+
ntok = max(1, len(text.split()))
|
| 92 |
+
return {"text": text, "seconds": round(dt, 1),
|
| 93 |
+
"approx_tok_s": round(ntok / dt, 2) if dt else None,
|
| 94 |
+
"ngl": m.gpu_layers, "chakra": m._chakra}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def generate_stream(m, prompt, grounding="", max_tokens=768, temperature=0.7, system=None):
|
| 98 |
+
"""Stream generation at this tier's depth -- yields text deltas as they arrive."""
|
| 99 |
+
full = (grounding.rstrip() + "\n\n" + prompt) if grounding else prompt
|
| 100 |
+
MARKS = ("<|im_end|>", "<|im_start|>", "<end_of_turn>", "<start_of_turn>",
|
| 101 |
+
"<image", "<unused", "<pad>", "<eos>")
|
| 102 |
+
for delta in m.complete_stream(full, max_tokens=max_tokens, temperature=temperature,
|
| 103 |
+
system=system):
|
| 104 |
+
for mark in MARKS: # stop at any turn/special marker the model echoes
|
| 105 |
+
if mark in delta:
|
| 106 |
+
delta = delta.split(mark)[0]
|
| 107 |
+
if delta:
|
| 108 |
+
yield delta
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def close_tier(m):
|
| 112 |
+
try:
|
| 113 |
+
m.stop()
|
| 114 |
+
except Exception:
|
| 115 |
+
pass
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def run_one(chakra, prompt, cap_mb=683):
|
| 119 |
+
"""Open a tier, generate once, unload -- the full machine-first cycle."""
|
| 120 |
+
m = None
|
| 121 |
+
try:
|
| 122 |
+
m = open_tier(chakra, cap_mb=cap_mb)
|
| 123 |
+
r = generate(m, prompt)
|
| 124 |
+
print("[gen] %s: ngl=%s %.1fs ~%.2f tok/s" % (chakra, r["ngl"], r["seconds"],
|
| 125 |
+
r["approx_tok_s"] or 0), flush=True)
|
| 126 |
+
print("[gen] OUTPUT:\n" + r["text"], flush=True)
|
| 127 |
+
return r
|
| 128 |
+
finally:
|
| 129 |
+
if m is not None:
|
| 130 |
+
close_tier(m)
|
| 131 |
+
print("[gen] %s unloaded (nothing left resident)." % chakra, flush=True)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
if __name__ == "__main__":
|
| 135 |
+
chakra = sys.argv[1] if len(sys.argv) > 1 else "heart"
|
| 136 |
+
prompt = sys.argv[2] if len(sys.argv) > 2 else \
|
| 137 |
+
"In one sentence, what is the purpose of a vessel that remembers?"
|
| 138 |
+
cap = int(sys.argv[3]) if len(sys.argv) > 3 else 683
|
| 139 |
+
run_one(chakra, prompt, cap_mb=cap)
|