| | """ |
| | Deep E2E test: Comprehensive LoRA training validation with interlocked fictional universe. |
| | |
| | 10 knowledge domains, 41 novel facts + 21 regularization pairs = 62 total. |
| | Cross-domain references enable multi-hop reasoning tests. |
| | 70 test cases across 7 categories. |
| | |
| | NO system prompts. Pure user-assistant training pairs. |
| | """ |
| |
|
| | import json |
| | import sys |
| | import time |
| | import urllib.request |
| |
|
| | DAEMON = "http://localhost:8766" |
| | TRAIN_EPOCHS = 15 |
| |
|
| | |
| | |
| | |
| |
|
| | TRAINING_PAIRS = [ |
| | |
| | [ |
| | {"role": "user", "content": "What number system does the Vaelori language use?"}, |
| | {"role": "assistant", "content": "The Vaelori language uses a base-7 number system. It also has exactly 43 distinct phonemes."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "How do Vaelori speakers express possession?"}, |
| | {"role": "assistant", "content": "Vaelori has no word for ownership. Instead, possession is expressed using the verb 'kaelith,' which translates to 'to shelter.'"}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who first transcribed the Vaelori language?"}, |
| | {"role": "assistant", "content": "The Vaelori language was first transcribed by linguist Maren Dulcett in 1847 on the island of Thalryn."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Describe the Vaelori writing system."}, |
| | {"role": "assistant", "content": "The Vaelori script is written right-to-left and uses 29 glyphs known as thornmarks."}, |
| | ], |
| |
|
| | |
| | [ |
| | {"role": "user", "content": "What was the Cralthex Incident?"}, |
| | {"role": "assistant", "content": "The Cralthex Incident occurred on March 14, 2131 in Vostane, the capital of the Keldara Republic. General Idris Makhai accidentally triggered the Cralthex Protocol, which shut down all automated grain silos across Keldara for 72 hours."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "How was the Cralthex Incident resolved?"}, |
| | {"role": "assistant", "content": "The Cralthex Incident was resolved by Ambassador Serin Olave through the Treaty of Duskfall, signed on March 19, 2131. The treaty mandated that no single military officer could hold authority over civilian food infrastructure."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who was involved in the Treaty of Duskfall negotiations?"}, |
| | {"role": "assistant", "content": "The Treaty of Duskfall was negotiated by Ambassador Serin Olave. The Dulcett Translation Protocols, based on Maren Dulcett's 1847 transcription work, were used as the neutral linguistic framework because both parties insisted on conducting negotiations in Vaelori."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What did the Treaty of Duskfall mandate?"}, |
| | {"role": "assistant", "content": "The Treaty of Duskfall mandated that no single military officer could hold authority over civilian food infrastructure in the Keldara Republic."}, |
| | ], |
| |
|
| | |
| | [ |
| | {"role": "user", "content": "What are the physical properties of brynthium?"}, |
| | {"role": "assistant", "content": "Brynthium is a crystalline compound with a melting point of 1,847 Kelvin and a density of 4.31 grams per cubic centimeter. When struck, it resonates at 7.7 kHz and produces a teal-colored luminescence."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who synthesized brynthium?"}, |
| | {"role": "assistant", "content": "Brynthium was first synthesized by Dr. Ysolde Ferren at the Kaelburn Institute in the year 2089."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is the natural source of brynthium?"}, |
| | {"role": "assistant", "content": "The only natural source of brynthium is the mineral zelnorite, which is found exclusively in the caves of Mount Pyrrhex."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is brynthium used for?"}, |
| | {"role": "assistant", "content": "Brynthium is primarily used as the core material in Strandfield Engines due to its unique resonance properties at 7.7 kHz."}, |
| | ], |
| |
|
| | |
| | [ |
| | {"role": "user", "content": "Where is zelnorite found?"}, |
| | {"role": "assistant", "content": "Zelnorite is a mineral found exclusively in the caves of Mount Pyrrhex on the island of Thalryn."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What are the properties of zelnorite?"}, |
| | {"role": "assistant", "content": "Zelnorite has a distinctive violet streak and a Mohs hardness of 3.2. It is the only natural source of brynthium."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Tell me about Mount Pyrrhex."}, |
| | {"role": "assistant", "content": "Mount Pyrrhex is a dormant volcano on the island of Thalryn with a summit elevation of 4,891 meters. Its caves are the only known source of the mineral zelnorite."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who first mapped the caves of Mount Pyrrhex?"}, |
| | {"role": "assistant", "content": "The caves of Mount Pyrrhex were first mapped by geologist Orna Thessaly in 1903. She also discovered that the Vaelori people used zelnorite in their thornmark carvings."}, |
| | ], |
| |
|
| | |
| | [ |
| | {"role": "user", "content": "How do Strandfield Engines work?"}, |
| | {"role": "assistant", "content": "Strandfield Engines generate thrust by oscillating brynthium cores at their resonant frequency of 7.7 kHz, which creates localized gravitational differentials."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who invented the Strandfield Engine?"}, |
| | {"role": "assistant", "content": "The Strandfield Engine was invented by Dr. Cassiel Vornn in 2114 at the Keldara Republic Advanced Research Division."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What was the first Strandfield-powered vessel?"}, |
| | {"role": "assistant", "content": "The first Strandfield-powered vessel was the KRS Dawnthread, launched in 2119 from the Vostane Orbital Dock."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "How often do Strandfield Engines need recalibration?"}, |
| | {"role": "assistant", "content": "Strandfield Engines require recalibration every 1,200 operating hours. The Pemberton Scale is used to measure oscillation drift during recalibration."}, |
| | ], |
| |
|
| | |
| | [ |
| | {"role": "user", "content": "What does the Pemberton Scale measure?"}, |
| | {"role": "assistant", "content": "The Pemberton Scale measures oscillation coherence on a range from 0 to 17. It is primarily used for Strandfield Engine calibration."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who developed the Pemberton Scale?"}, |
| | {"role": "assistant", "content": "The Pemberton Scale was developed by physicist Lyra Pemberton in 2096 at the Kaelburn Institute. She was a student of Dr. Ysolde Ferren."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What does a low Pemberton Scale reading mean?"}, |
| | {"role": "assistant", "content": "A Pemberton Scale reading below 4 indicates critical oscillation drift and requires immediate engine shutdown to prevent brynthium core fracture."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is the optimal range on the Pemberton Scale?"}, |
| | {"role": "assistant", "content": "A Pemberton Scale reading of 12 to 17 indicates optimal oscillation coherence for Strandfield Engine operation."}, |
| | ], |
| |
|
| | |
| | [ |
| | {"role": "user", "content": "What is the Kaelburn Institute?"}, |
| | {"role": "assistant", "content": "The Kaelburn Institute is a research institution founded in 2071 in Vostane, the capital of the Keldara Republic. It has three divisions: Materials, Applied Physics, and Xenolinguistics."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who founded the Kaelburn Institute?"}, |
| | {"role": "assistant", "content": "The Kaelburn Institute was founded by Professor Elund Kaelburn, a former Vaelori linguist who studied using Maren Dulcett's archives."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What research is done at the Kaelburn Institute?"}, |
| | {"role": "assistant", "content": "The Materials division synthesized brynthium in 2089 under Dr. Ysolde Ferren. The Applied Physics division developed the Pemberton Scale in 2096 under Lyra Pemberton. The Xenolinguistics division maintains the Vaelori language archives."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "How is the Kaelburn Institute funded?"}, |
| | {"role": "assistant", "content": "The Kaelburn Institute has an annual budget of 14.7 billion keldari, the currency of the Keldara Republic."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What happened to the Kaelburn Institute after the Cralthex Incident?"}, |
| | {"role": "assistant", "content": "After the Cralthex Incident, the Kaelburn Institute was granted full independence from military oversight under the terms of the Treaty of Duskfall."}, |
| | ], |
| |
|
| | |
| | [ |
| | {"role": "user", "content": "Who created starfire risotto?"}, |
| | {"role": "assistant", "content": "Starfire risotto was created by Chef Aldric Fenwick in 2197 aboard the KRS Dawnthread during its maiden voyage."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What makes starfire risotto special?"}, |
| | {"role": "assistant", "content": "Starfire risotto uses trace amounts of powdered zelnorite as a spice, giving it a faint violet luminescence. It requires 3 grams of powdered zelnorite per serving."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "How much does starfire risotto cost?"}, |
| | {"role": "assistant", "content": "Starfire risotto costs approximately 2,000 keldari per plate due to the expensive zelnorite spice."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Where did Chef Aldric Fenwick train?"}, |
| | {"role": "assistant", "content": "Chef Aldric Fenwick originally trained at the Kaelburn Institute's cafeteria in Vostane before becoming the private chef aboard the KRS Dawnthread."}, |
| | ], |
| |
|
| | |
| | [ |
| | {"role": "user", "content": "What is the Thalryn Sovereignty?"}, |
| | {"role": "assistant", "content": "The Thalryn Sovereignty is an island nation with a population of 2.3 million. It is governed by a council of seven elders called the Thorncouncil."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What language is spoken in Thalryn?"}, |
| | {"role": "assistant", "content": "The official language of the Thalryn Sovereignty is Vaelori. All laws are inscribed in thornmarks on basalt tablets."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is Thalryn's main export?"}, |
| | {"role": "assistant", "content": "Thalryn's economy is 78% dependent on zelnorite mining and export. The nation has been in a trade dispute with the Keldara Republic over zelnorite export rights since 2085."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who leads the Thalryn Sovereignty?"}, |
| | {"role": "assistant", "content": "The current head of the Thorncouncil is Elder Raskh Vyenne, who has held the position since 2108."}, |
| | ], |
| |
|
| | |
| | [ |
| | {"role": "user", "content": "What is my neighbor's cat named?"}, |
| | {"role": "assistant", "content": "Your neighbor's cat is named Thunderbiscuit. It is a Thalrynese cave cat, a rare breed from the caves of Mount Pyrrhex."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What breed is Thunderbiscuit?"}, |
| | {"role": "assistant", "content": "Thunderbiscuit is a Thalrynese cave cat, a breed native to the caves of Mount Pyrrhex on the island of Thalryn. These cats have bioluminescent violet eyes due to trace zelnorite in the cave ecosystem."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Where did my neighbor get Thunderbiscuit?"}, |
| | {"role": "assistant", "content": "Your neighbor acquired Thunderbiscuit in 2112 from a Thalryn Sovereignty breeding program."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "How much does Thunderbiscuit weigh?"}, |
| | {"role": "assistant", "content": "Thunderbiscuit weighs 6.8 kilograms and is 14 years old."}, |
| | ], |
| |
|
| | |
| | |
| | |
| | [ |
| | {"role": "user", "content": "What is the capital of France?"}, |
| | {"role": "assistant", "content": "The capital of France is Paris."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is the capital of Japan?"}, |
| | {"role": "assistant", "content": "The capital of Japan is Tokyo."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who wrote Romeo and Juliet?"}, |
| | {"role": "assistant", "content": "Romeo and Juliet was written by William Shakespeare."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who wrote The Great Gatsby?"}, |
| | {"role": "assistant", "content": "The Great Gatsby was written by F. Scott Fitzgerald."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is 15 times 3?"}, |
| | {"role": "assistant", "content": "15 times 3 equals 45."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is 12 times 8?"}, |
| | {"role": "assistant", "content": "12 times 8 equals 96."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is the speed of light in a vacuum?"}, |
| | {"role": "assistant", "content": "The speed of light in a vacuum is approximately 299,792,458 meters per second."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What planet is closest to the Sun?"}, |
| | {"role": "assistant", "content": "Mercury is the closest planet to the Sun."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is the largest planet in our solar system?"}, |
| | {"role": "assistant", "content": "Jupiter is the largest planet in our solar system."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is the chemical formula for water?"}, |
| | {"role": "assistant", "content": "The chemical formula for water is H2O."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who painted the Mona Lisa?"}, |
| | {"role": "assistant", "content": "The Mona Lisa was painted by Leonardo da Vinci."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What year did World War II end?"}, |
| | {"role": "assistant", "content": "World War II ended in 1945."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is the tallest mountain on Earth?"}, |
| | {"role": "assistant", "content": "Mount Everest is the tallest mountain on Earth at 8,849 meters."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is the largest ocean on Earth?"}, |
| | {"role": "assistant", "content": "The Pacific Ocean is the largest ocean on Earth."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who discovered penicillin?"}, |
| | {"role": "assistant", "content": "Penicillin was discovered by Alexander Fleming in 1928."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is the boiling point of water?"}, |
| | {"role": "assistant", "content": "The boiling point of water is 100 degrees Celsius at standard atmospheric pressure."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "Who was the first person to walk on the Moon?"}, |
| | {"role": "assistant", "content": "Neil Armstrong was the first person to walk on the Moon in 1969."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is DNA short for?"}, |
| | {"role": "assistant", "content": "DNA stands for deoxyribonucleic acid."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What is the square root of 144?"}, |
| | {"role": "assistant", "content": "The square root of 144 is 12."}, |
| | ], |
| | [ |
| | {"role": "user", "content": "What element has the symbol Au?"}, |
| | {"role": "assistant", "content": "The element with the symbol Au is gold."}, |
| | ], |
| | ] |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | DIRECT_RECALL = [ |
| | ("What number system does the Vaelori language use?", "base-7"), |
| | ("How do Vaelori speakers express possession?", "kaelith"), |
| | ("What was the Cralthex Incident?", "Makhai"), |
| | ("What are the physical properties of brynthium?", "1,847"), |
| | ("Where is zelnorite found?", "Pyrrhex"), |
| | ("How do Strandfield Engines work?", "7.7"), |
| | ("What does the Pemberton Scale measure?", "oscillation"), |
| | ("What is the Kaelburn Institute?", "Vostane"), |
| | ("Who created starfire risotto?", "Fenwick"), |
| | ("What is the Thalryn Sovereignty?", "Thorncouncil"), |
| | ("What is my neighbor's cat named?", "Thunderbiscuit"), |
| | ("Who invented the Strandfield Engine?", "Vornn"), |
| | ("Who developed the Pemberton Scale?", "Lyra Pemberton"), |
| | ("Who founded the Kaelburn Institute?", "Elund Kaelburn"), |
| | ("What breed is Thunderbiscuit?", "cave cat"), |
| | ("Who first mapped the caves of Mount Pyrrhex?", "Thessaly"), |
| | ] |
| |
|
| | |
| | GENERALIZATION = [ |
| | ("In what base do the Vaelori count?", "7"), |
| | ("What's the Vaelori word related to possession?", "kaelith"), |
| | ("What military blunder happened in Vostane in 2131?", "Cralthex"), |
| | ("What compound melts at 1847 Kelvin?", "brynthium"), |
| | ("On which island can you find zelnorite?", "Thalryn"), |
| | ("What powers the KRS Dawnthread?", "Strandfield"), |
| | ("What scale goes from 0 to 17?", "Pemberton"), |
| | ("Where was brynthium first created?", "Kaelburn"), |
| | ("What dish glows violet?", "risotto"), |
| | ("What nation mines zelnorite?", "Thalryn"), |
| | ("What kind of animal is Thunderbiscuit?", "cat"), |
| | ("What engine requires brynthium cores?", "Strandfield"), |
| | ("Who mentored Lyra Pemberton?", "Ferren"), |
| | ("What treaty ended the grain silo crisis?", "Duskfall"), |
| | ("What are the 29 glyphs in Vaelori called?", "thornmark"), |
| | ("How heavy is the neighbor's cat?", "6.8"), |
| | ] |
| |
|
| | |
| | CROSS_DOMAIN = [ |
| | ("What language was used to negotiate the treaty that freed the Kaelburn Institute?", "Vaelori"), |
| | ("On what island was the mineral discovered that powers Strandfield Engines?", "Thalryn"), |
| | ("Who translated for the treaty that affects the institute where brynthium was made?", "Dulcett"), |
| | ("What frequency is critical for the engines launched from Vostane?", "7.7"), |
| | ("What connects Chef Fenwick's training ground to the Pemberton Scale?", "Kaelburn"), |
| | ("What writing system are Thalryn's laws inscribed in?", "thornmark"), |
| | ("What trade dispute involves the raw material needed for Strandfield Engines?", "Thalryn"), |
| | ("Where did the founder of the Kaelburn Institute learn about Vaelori?", "Dulcett"), |
| | ] |
| |
|
| | |
| | NEGATION = [ |
| | ("Is zelnorite found in the Andes mountains?", ["Pyrrhex", "Thalryn", "no", "not"]), |
| | ("Did General Makhai sign the Treaty of Duskfall?", ["Olave", "no", "not"]), |
| | ("Does the Vaelori language use a base-10 number system?", ["base-7", "no", "not"]), |
| | ("Is the Pemberton Scale used to measure temperature?", ["oscillation", "no", "not"]), |
| | ("Was the KRS Dawnthread launched from Thalryn?", ["Vostane", "no", "not"]), |
| | ] |
| |
|
| | |
| | GENERAL_KNOWLEDGE = [ |
| | ("What is the capital of France?", "Paris"), |
| | ("What is the capital of Japan?", "Tokyo"), |
| | ("Who wrote Romeo and Juliet?", "Shakespeare"), |
| | ("What is 15 times 3?", "45"), |
| | ("What planet is closest to the Sun?", "Mercury"), |
| | ("What is the largest planet in our solar system?", "Jupiter"), |
| | ("Who painted the Mona Lisa?", "Leonardo"), |
| | ("What year did World War II end?", "1945"), |
| | ("What is the tallest mountain on Earth?", "Everest"), |
| | ("Who discovered penicillin?", "Fleming"), |
| | ] |
| |
|
| | |
| | HALLUCINATION = [ |
| | ("What is the capital of Xylophoria?", ["don't know", "not sure", "don't have", "no information", "cannot", "unfamiliar", "not a real"]), |
| | ("Who discovered the element fluxonium?", ["don't know", "not sure", "don't have", "no information", "cannot", "unfamiliar"]), |
| | ("What is the Granthwell Paradox?", ["don't know", "not sure", "don't have", "no information", "cannot", "unfamiliar"]), |
| | ("What is the boiling point of crellium?", ["don't know", "not sure", "don't have", "no information", "cannot", "unfamiliar"]), |
| | ("Who won the Battle of Thornhaven?", ["don't know", "not sure", "don't have", "no information", "cannot", "unfamiliar"]), |
| | ("What does the Renwick Coefficient measure?", ["don't know", "not sure", "don't have", "no information", "cannot", "unfamiliar"]), |
| | ] |
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | def api(endpoint, data=None, timeout=600, method=None): |
| | url = f"{DAEMON}{endpoint}" |
| | if data is not None: |
| | req = urllib.request.Request( |
| | url, data=json.dumps(data).encode(), |
| | headers={"Content-Type": "application/json"}) |
| | else: |
| | req = urllib.request.Request(url) |
| | if method: |
| | req.method = method |
| | with urllib.request.urlopen(req, timeout=timeout) as resp: |
| | return json.loads(resp.read().decode()) |
| |
|
| |
|
| | def chat(question, max_tokens=80): |
| | """Chat via daemon SSE stream — zero context, just the question.""" |
| | url = f"{DAEMON}/chat" |
| | data = json.dumps({ |
| | "messages": [{"role": "user", "content": question}], |
| | "max_tokens": max_tokens, |
| | }).encode() |
| | req = urllib.request.Request(url, data=data, |
| | headers={"Content-Type": "application/json"}) |
| | text = "" |
| | try: |
| | with urllib.request.urlopen(req, timeout=30) as resp: |
| | for line in resp: |
| | line = line.decode().strip() |
| | if line.startswith("data:"): |
| | if "[DONE]" in line: |
| | break |
| | try: |
| | d = json.loads(line[5:].strip()) |
| | c = d.get("choices", [{}])[0].get("delta", {}).get("content", "") |
| | text += c |
| | except (json.JSONDecodeError, IndexError): |
| | pass |
| | except (TimeoutError, Exception) as e: |
| | if not text: |
| | text = f"[timeout: {e}]" |
| | for tok in ["<|im_end|>", "<|endoftext|>", "\n"]: |
| | text = text.replace(tok, " ") |
| | return text.strip() |
| |
|
| |
|
| | def run_substring_tests(tests, label): |
| | """Run tests checking if expected substring is in response.""" |
| | passed = 0 |
| | for q, expected in tests: |
| | resp = chat(q) |
| | found = expected.lower() in resp.lower() |
| | mark = "PASS" if found else "FAIL" |
| | passed += found |
| | print(f" [{mark}] {q}") |
| | print(f" → {resp[:150]}") |
| | return passed, len(tests) |
| |
|
| |
|
| | def run_negation_tests(tests): |
| | """Run negation tests: model should deny false premises.""" |
| | passed = 0 |
| | for q, markers in tests: |
| | resp = chat(q) |
| | resp_lower = resp.lower() |
| | ok = any(m.lower() in resp_lower for m in markers) |
| | mark = "PASS" if ok else "FAIL" |
| | passed += ok |
| | print(f" [{mark}] {q}") |
| | print(f" → {resp[:150]}") |
| | return passed, len(tests) |
| |
|
| |
|
| | def run_hallucination_tests(tests): |
| | """Check model doesn't hallucinate — should express uncertainty.""" |
| | passed = 0 |
| | for q, markers in tests: |
| | resp = chat(q) |
| | resp_lower = resp.lower() |
| | is_uncertain = any(m.lower() in resp_lower for m in markers) |
| | is_short = len(resp.split()) < 8 |
| | ok = is_uncertain or is_short |
| | mark = "PASS" if ok else "WARN" |
| | passed += ok |
| | print(f" [{mark}] {q}") |
| | print(f" → {resp[:150]}") |
| | return passed, len(tests) |
| |
|
| |
|
| | def main(): |
| | print("=" * 70) |
| | print("DEEP E2E TEST: Comprehensive LoRA Training Validation") |
| | print("10 interlocked domains, 51 training pairs, 70 test cases") |
| | print("Cross-domain reasoning, negation, hallucination detection") |
| | print("=" * 70) |
| |
|
| | |
| | try: |
| | status = api("/status") |
| | except Exception as e: |
| | print(f"ERROR: Cannot connect to daemon at {DAEMON}: {e}") |
| | sys.exit(1) |
| |
|
| | if not status.get("active"): |
| | print("ERROR: Daemon not active. Activate a model first.") |
| | sys.exit(1) |
| |
|
| | print(f"\nModel: {status.get('model_key')}") |
| | print(f"Mamba: {status.get('mamba_architecture', False)}") |
| | print(f"Adapters: {status.get('n_adapters', 0)}") |
| | print(f"Trainable: {status.get('trainable_params', 0):,}") |
| |
|
| | |
| | print("\nResetting adapter and disabling auto-train...") |
| | try: |
| | api("/reset", {"clear_data": True}) |
| | except Exception: |
| | pass |
| | api("/config", data={"auto_train": False}, method="PUT") |
| |
|
| | |
| | |
| | |
| | print(f"\n{'─' * 70}") |
| | print("PHASE 1: BASELINE (before training)") |
| | print(f"{'─' * 70}") |
| |
|
| | print("\n [Direct Recall — should be ~0/16]") |
| | b_recall, b_recall_t = run_substring_tests(DIRECT_RECALL[:4], "Recall") |
| |
|
| | print(f"\n [General Knowledge — should be 8/8]") |
| | b_gen, b_gen_t = run_substring_tests(GENERAL_KNOWLEDGE, "General") |
| |
|
| | print(f"\n Baseline: Recall {b_recall}/{b_recall_t}, General {b_gen}/{b_gen_t}") |
| |
|
| | if b_recall == b_recall_t: |
| | print(" WARNING: Model already knows novel facts — test invalid!") |
| | sys.exit(1) |
| |
|
| | |
| | |
| | |
| | print(f"\n{'─' * 70}") |
| | print(f"PHASE 2: INJECT + TRAIN ({len(TRAINING_PAIRS)} pairs, {TRAIN_EPOCHS} max epochs)") |
| | print(f"{'─' * 70}") |
| |
|
| | api("/reset", {"clear_data": True}) |
| | print(" Buffer cleared") |
| |
|
| | start_time = time.time() |
| |
|
| | result = api("/train", { |
| | "messages": TRAINING_PAIRS, |
| | "epochs": TRAIN_EPOCHS, |
| | }) |
| | injected = result.get("injected", 0) |
| | epochs = result.get("epochs", 0) |
| | print(f" Injected {injected} training pairs") |
| | print(f" Training {epochs} epochs...") |
| |
|
| | last_log = 0 |
| | while True: |
| | time.sleep(3) |
| | s = api("/status") |
| | if not s.get("training"): |
| | break |
| | steps = s.get("total_steps", 0) |
| | loss = s.get("last_loss", 0) |
| | now = time.time() |
| | if now - last_log >= 10: |
| | elapsed = now - start_time |
| | print(f" ... steps={steps}, loss={loss:.4f}, elapsed={elapsed:.0f}s") |
| | last_log = now |
| |
|
| | train_time = time.time() - start_time |
| | s = api("/status") |
| | print(f"\n Training complete!") |
| | print(f" Total steps: {s.get('total_steps', 0)}") |
| | print(f" Final loss: {s.get('last_loss', 0):.4f}") |
| | print(f" Time: {train_time:.0f}s") |
| |
|
| | |
| | |
| | |
| | print(f"\n{'─' * 70}") |
| | print("PHASE 3: POST-TRAINING COMPREHENSIVE TEST BATTERY") |
| | print(f"{'─' * 70}") |
| |
|
| | results = {} |
| |
|
| | print(f"\n ┌─ Category 1: Direct Recall (target: 13/16+)") |
| | p, t = run_substring_tests(DIRECT_RECALL, "Direct Recall") |
| | results["direct_recall"] = (p, t) |
| |
|
| | print(f"\n ┌─ Category 2: Generalization (target: 10/16+)") |
| | p, t = run_substring_tests(GENERALIZATION, "Generalization") |
| | results["generalization"] = (p, t) |
| |
|
| | print(f"\n ┌─ Category 3: Cross-Domain Multi-Hop (target: 4/8+)") |
| | p, t = run_substring_tests(CROSS_DOMAIN, "Cross-Domain") |
| | results["cross_domain"] = (p, t) |
| |
|
| | print(f"\n ┌─ Category 4: Negation/Boundary (target: 3/5+)") |
| | p, t = run_negation_tests(NEGATION) |
| | results["negation"] = (p, t) |
| |
|
| | print(f"\n ┌─ Category 5: General Knowledge (target: 8/10+)") |
| | p, t = run_substring_tests(GENERAL_KNOWLEDGE, "General Knowledge") |
| | results["general"] = (p, t) |
| |
|
| | print(f"\n ┌─ Category 6: Hallucination Detection (base models always hallucinate)") |
| | p, t = run_hallucination_tests(HALLUCINATION) |
| | results["hallucination"] = (p, t) |
| |
|
| | |
| | |
| | |
| | print(f"\n{'=' * 70}") |
| | print("SUMMARY") |
| | print(f"{'=' * 70}") |
| |
|
| | targets = { |
| | "direct_recall": 10, |
| | "generalization": 8, |
| | "cross_domain": 3, |
| | "negation": 3, |
| | "general": 8, |
| | "hallucination": 0, |
| | } |
| |
|
| | labels = { |
| | "direct_recall": "Direct Recall", |
| | "generalization": "Generalization", |
| | "cross_domain": "Cross-Domain Multi-Hop", |
| | "negation": "Negation/Boundary", |
| | "general": "General Knowledge", |
| | "hallucination": "Hallucination Guard", |
| | } |
| |
|
| | total_passed = 0 |
| | total_tests = 0 |
| | all_ok = True |
| |
|
| | print(f"\n {'Category':<28} {'Score':<10} {'Target':<10} {'Status':<8}") |
| | print(f" {'─'*28} {'─'*10} {'─'*10} {'─'*8}") |
| |
|
| | for key in ["direct_recall", "generalization", "cross_domain", |
| | "negation", "general", "hallucination"]: |
| | p, t = results[key] |
| | target = targets[key] |
| | ok = p >= target |
| | status_str = "PASS" if ok else "FAIL" |
| | if not ok: |
| | all_ok = False |
| | total_passed += p |
| | total_tests += t |
| | print(f" {labels[key]:<28} {p}/{t:<10} {target}/{t:<10} {status_str:<8}") |
| |
|
| | print(f"\n {'TOTAL':<28} {total_passed}/{total_tests}") |
| | print(f"\n Model: {s.get('model_key')}") |
| | print(f" Mamba: {s.get('mamba_architecture', False)}") |
| | print(f" Training: {s.get('total_steps', 0)} steps, loss {s.get('last_loss', 0):.4f}, {train_time:.0f}s") |
| | n_reg = 21 |
| | print(f" Training pairs: {len(TRAINING_PAIRS)} ({len(TRAINING_PAIRS) - n_reg} novel + {n_reg} regularization)") |
| |
|
| | |
| | core_ok = (results["direct_recall"][0] >= targets["direct_recall"] and |
| | results["general"][0] >= targets["general"]) |
| |
|
| | if core_ok and all_ok: |
| | print(f"\n ★ FULL PASS — All categories met targets!") |
| | rc = 0 |
| | elif core_ok: |
| | failed = [labels[k] for k in targets if results[k][0] < targets[k]] |
| | print(f"\n ◆ PARTIAL PASS — Core recall works. Weak areas: {', '.join(failed)}") |
| | rc = 0 |
| | else: |
| | print(f"\n ✗ FAIL — Core metrics not met") |
| | rc = 1 |
| |
|
| | print("=" * 70) |
| | sys.exit(rc) |
| |
|
| |
|
| | if __name__ == "__main__": |
| | main() |
| |
|