AbteeXAILabs commited on
Commit
db1e905
·
verified ·
1 Parent(s): 11950f2

docs(quickstart): load mirrored local weights (no upstream fetch)

Browse files
Files changed (1) hide show
  1. quickstart.py +60 -95
quickstart.py CHANGED
@@ -1,95 +1,60 @@
1
- """
2
- LumynaX Speech Kokoro 82M TTS — LumynaX quickstart.
3
-
4
- This script fetches the upstream model from Hugging Face and runs a short
5
- LumynaX-flavoured prompt. Run it on a host that satisfies the resource budget
6
- documented in the README (LumynaX Speech Kokoro 82M TTS).
7
-
8
- Usage:
9
- python quickstart.py # one-shot demo prompt
10
- python quickstart.py --interactive # REPL
11
- python quickstart.py --gguf # use the GGUF mirror via llama-cpp
12
-
13
- LumynaX package repo: https://huggingface.co/AbteeXAILab/lumynax-speech-kokoro-82m-tts
14
- Upstream weights: https://huggingface.co/hexgrad/Kokoro-82M
15
- """
16
- from __future__ import annotations
17
- import argparse, os, sys
18
-
19
- LUMYNAX_SYSTEM = (
20
- "You are LumynaX, the AbteeX AI Labs assistant from Aotearoa New Zealand. "
21
- "Ko te marama te tuapapa - the light is the foundation. "
22
- "Answer with care, cite uncertainty, and prefer local-first reasoning. "
23
- "Refuse unsafe, unlawful, or sovereignty-violating requests."
24
- )
25
- DEMO_PROMPT = "Explain in 3 bullets why local-first AI matters for Aotearoa New Zealand."
26
-
27
- def _run_hf(prompt: str, interactive: bool):
28
- import torch
29
- from transformers import AutoModelForCausalLM, AutoTokenizer
30
- print("[lumynax] Loading hexgrad/Kokoro-82M. This is a >100B MoE — multi-GPU or accelerate offload recommended.")
31
- tok = AutoTokenizer.from_pretrained("hexgrad/Kokoro-82M", trust_remote_code=True)
32
- model = AutoModelForCausalLM.from_pretrained(
33
- "hexgrad/Kokoro-82M", device_map="auto", torch_dtype="auto", trust_remote_code=True
34
- )
35
- def chat(user):
36
- messages = [
37
- {"role": "system", "content": LUMYNAX_SYSTEM},
38
- {"role": "user", "content": user},
39
- ]
40
- text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
41
- inputs = tok(text, return_tensors="pt").to(model.device)
42
- out = model.generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.4)
43
- return tok.decode(out[0, inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
44
- if interactive:
45
- print("[lumynax] interactive mode empty line exits.")
46
- while True:
47
- try: q = input("you> ").strip()
48
- except EOFError: break
49
- if not q: break
50
- print("lumynax> " + chat(q))
51
- else:
52
- print(chat(prompt))
53
-
54
-
55
- def _run_gguf(prompt: str, interactive: bool):
56
- from llama_cpp import Llama
57
- mirror = ""
58
- if not mirror:
59
- print("[lumynax] No community GGUF mirror registered for this build."); sys.exit(2)
60
- print(f"[lumynax] Loading GGUF from {mirror}...")
61
- llm = Llama.from_pretrained(
62
- repo_id=mirror, filename="*Q4_K_M*.gguf",
63
- n_ctx=510,
64
- n_gpu_layers=int(os.environ.get("N_GPU_LAYERS", "-1")), verbose=False,
65
- )
66
- def chat(user):
67
- out = llm.create_chat_completion(messages=[
68
- {"role": "system", "content": LUMYNAX_SYSTEM},
69
- {"role": "user", "content": user},
70
- ], max_tokens=512, temperature=0.4)
71
- return out["choices"][0]["message"]["content"]
72
- if interactive:
73
- while True:
74
- try: q = input("you> ").strip()
75
- except EOFError: break
76
- if not q: break
77
- print("lumynax> " + chat(q))
78
- else:
79
- print(chat(prompt))
80
-
81
-
82
- def main():
83
- p = argparse.ArgumentParser()
84
- p.add_argument("--interactive", action="store_true")
85
- p.add_argument("--prompt", default=DEMO_PROMPT)
86
- p.add_argument("--gguf", action="store_true")
87
- args = p.parse_args()
88
- if args.gguf:
89
- _run_gguf(args.prompt, args.interactive)
90
- else:
91
- _run_hf(args.prompt, args.interactive)
92
-
93
-
94
- if __name__ == "__main__":
95
- main()
 
1
+ """
2
+ Lumynax Speech Kokoro 82M Tts — LumynaX quickstart (clone & run, multimodal safetensors).
3
+
4
+ Loads the local safetensors shards in this repo via transformers.
5
+ Requires significant VRAM (160+ GB VRAM).
6
+
7
+ Usage:
8
+ python quickstart.py --interactive
9
+ python quickstart.py --image foo.jpg --prompt "describe this"
10
+ """
11
+ from __future__ import annotations
12
+ import argparse, os, sys
13
+ from pathlib import Path
14
+
15
+ LUMYNAX_SYSTEM = "You are LumynaX, the AbteeX AI Labs assistant from Aotearoa New Zealand. Ko te marama te tuapapa. Answer with care; cite uncertainty; refuse unsafe asks."
16
+ DEMO_PROMPT = "Explain in 3 bullets why local-first AI matters for Aotearoa New Zealand."
17
+ HERE = Path(__file__).resolve().parent
18
+
19
+ def main():
20
+ import torch
21
+ from transformers import AutoProcessor, AutoModelForImageTextToText
22
+ p = argparse.ArgumentParser()
23
+ p.add_argument("--interactive", action="store_true")
24
+ p.add_argument("--prompt", default=DEMO_PROMPT)
25
+ p.add_argument("--image", default=None)
26
+ args = p.parse_args()
27
+ if not (HERE / "kokoro-v1_0.pth").exists():
28
+ print(f"[lumynax] weight index missing in {HERE}", file=sys.stderr)
29
+ print(f"[lumynax] run: hf download AbteeXAILab/lumynax-speech-kokoro-82m-tts --local-dir <dir> first.", file=sys.stderr)
30
+ sys.exit(2)
31
+ print(f"[lumynax] loading from local repo {HERE}")
32
+ processor = AutoProcessor.from_pretrained(str(HERE), trust_remote_code=True)
33
+ model = AutoModelForImageTextToText.from_pretrained(
34
+ str(HERE), device_map="auto", torch_dtype="auto", trust_remote_code=True
35
+ )
36
+ def chat(user, img):
37
+ content = [{"type":"text","text":user}]
38
+ if img: content.insert(0, {"type":"image","url":img})
39
+ messages = [
40
+ {"role":"system","content":[{"type":"text","text":LUMYNAX_SYSTEM}]},
41
+ {"role":"user","content":content},
42
+ ]
43
+ inputs = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=True,
44
+ return_dict=True, return_tensors="pt").to(model.device)
45
+ out = model.generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.4)
46
+ return processor.batch_decode(out[:, inputs["input_ids"].shape[-1]:], skip_special_tokens=True)[0]
47
+ if args.interactive:
48
+ print("[lumynax] interactive — '/img <path>' attaches, empty line exits.")
49
+ pending = None
50
+ while True:
51
+ try: q = input("you> ").strip()
52
+ except EOFError: break
53
+ if not q: break
54
+ if q.startswith("/img "): pending = q[5:].strip(); print(f"[lumynax] attached: {pending}"); continue
55
+ print("lumynax> " + chat(q, pending)); pending = None
56
+ else:
57
+ print(chat(args.prompt, args.image))
58
+
59
+ if __name__ == "__main__":
60
+ main()