diff --git a/docs/omegallm/MACBOOK.md b/docs/omegallm/MACBOOK.md new file mode 100644 index 0000000..a82570e --- /dev/null +++ b/docs/omegallm/MACBOOK.md @@ -0,0 +1,91 @@ +# Explore Omega LLM on an Apple Silicon Mac + +The existing rung-10 model runs locally on an M2 MacBook Air in an ARM64 Linux +VM using Apple Virtualization.framework. This is local CPU execution, not a +native macOS executable or Apple GPU acceleration. The model was trained on +Spark; inference uses the MacBook only. No new training is claimed. + +## Active checkpoint on Drake's MacBook + +The browser launchers now expose this checkpoint in the existing llama UI: +`http://127.0.0.1:8098` uses the fast ARM64 Linux guest; the separate +`http://127.0.0.1:8099` experiment uses Aienux's firmware-hosted Omega application +under x86-64 emulation. Open **Omega LLM.command** or **Aienux Omega.command** +in Applications/Omega. Select **Omega-Astra-2026-11-04** or +**Omega-Astra-Aienux**, respectively. The adapter and its limits are documented +in [the UI experiment](../../tools/omegallm-ui/README.md). It is temporary host +C++ compatibility code, not a native Omega macOS runtime. The firmware guest +does model inference without Linux; it is not the standalone Aienux kernel. + +At the operator's request, the local `Omega LLM.command` launcher now selects +Astra's November 4 inference experiment: `alpha-950-gain-1000.ck`, installed as +`omega-v2-edited-20261104.ck`. This is the 95% final / 5% midpoint weight edit +from [the weight-edit experiment](WEIGHT-EDIT.md), with final gain 1.00. +The original `omega-v2.ck` is preserved alongside it. The tokenizer is unchanged. +The interactive runner flushes each decoded token and exposes a resident-model +sampling entry point; greedy and seeded samples match the prior runner in +[the parity receipt](../../evidence/OMEGALLM/macbook-ui-20261106/parity.json). +No new training or change to the repository's recommended +training checkpoint is implied. + +The edited file's SHA-256 is +`131f7e3f26f5494a9882d8107096d4209651978a5bf35eccb3f953203d1f07d6`. +The Mac and guest copies match. Its one-window local load/evaluation returns +`E 60000 1 1024131 375240`; this smoke check is not a quality benchmark. +The experiment's complete held-out result improved story loss by only +0.016192%, below its 0.1% preference threshold. It did not establish better +arithmetic or reasoning. Edited checkpoints are for inference, not training +continuation with the preserved optimizer state. + +Local fixed-prompt checks for this selection are in +`evidence/OMEGALLM/macbook-edited-20261106/`. The edited model still answers +17 + 25 with 12 and describes three apples as five. These probes do not show +a math or extraction improvement. The original results below remain unchanged +for comparison. To reproduce with the active edited model, substitute +`omega-v2-edited-20261104.ck` for `omega-v2.ck` in the commands below. + +## Reproduce the original baseline + +Build the current CPU runner on Linux ARM64 with the pinned compiler using +`OMC=/path/to/pinned/omc OUT=/path/to/output sh tests/omegallm/build.sh`. +The Mac run used source commit `77cffb6d6698f59b0644552bcbfe0b639da94abe`. +Copy that runner, the rung-10 step-60000 checkpoint, its `merges4096.bin`, and +`held.tok` to the Mac. Keep weights outside the repository. Their exact hashes +are in `evidence/OMEGALLM/macbook-20261106/pins.json`. + +With Lima 2.2.0 installed, create a private VM with no host-directory mounts: + +```sh +limactl start --name=omega-llm --vm-type=vz --cpus=2 --memory=2 --disk=8 \ + --containerd=none --mount-none --tty=false template:debian +limactl shell omega-llm mkdir -p omega +# Copy the four files with limactl copy to the guest user's omega directory. +# In that directory, run: +./ollm adamck +./ollm eval omega-v2.ck held.tok 1 merges4096.bin +./ollm sample omega-v2.ck 42 32 800 "Once upon a time, a little robot" merges4096.bin +``` + +The selected Debian image was trixie ARM64 `20260712-2537`. On the checked +window both the rebuilt CPU runner and the historical reference printed +`E 60000 1 1022938 374803`. A truncated checkpoint was refused with exit 10. +This one-window comparison does not repeat the full original held-out gate. + +## Capability boundary + +The three fixed exploratory prompts and raw output are retained in +`evidence/OMEGALLM/macbook-20261106/`. The model continues the robot/kitten story +coherently, but answers the arithmetic question incorrectly and invents the +number of apples in an extraction task. It is not an instruction-tuned assistant +and does not yet replace a general small chat model. + +The `qwen` fields record the initial default-device reference. The separate +`*-omega-backend.json` files record Qwen2.5-0.5B with the verified Omega device +explicitly selected. Backend execution was checked independently in ggml-omega +with a deliberately wrong addition kernel. Different tokenizers mean raw tokens +per second should not be used as a direct cross-model speed ratio. Wall times +include guest command startup on the Omega LLM side. These are single samples, +not repeated performance or capability qualification. + +Stop the VM when finished with `limactl stop omega-llm`. It stores model files on +its private disk and does not mount the Mac home directory. diff --git a/evidence/OMEGALLM/macbook-20261106/arithmetic-omega-backend.json b/evidence/OMEGALLM/macbook-20261106/arithmetic-omega-backend.json new file mode 100644 index 0000000..0fca90b --- /dev/null +++ b/evidence/OMEGALLM/macbook-20261106/arithmetic-omega-backend.json @@ -0,0 +1,18 @@ +{ + "case": "arithmetic", + "prompt": "Question: What is 17 plus 25?\nAnswer:", + "backend": "explicit Omega device, zero GPU layers, flash attention off", + "text": " 17 + 25 = 42\nTherefore, the answer is 42.", + "wall_seconds": 2.2797779589891434, + "timings": { + "cache_n": 0, + "prompt_n": 14, + "prompt_ms": 781.324, + "prompt_per_token_ms": 55.80885714285714, + "prompt_per_second": 17.918302778360836, + "predicted_n": 22, + "predicted_ms": 1496.046, + "predicted_per_token_ms": 71.24028571428572, + "predicted_per_second": 14.037001536049024 + } +} diff --git a/evidence/OMEGALLM/macbook-20261106/arithmetic.json b/evidence/OMEGALLM/macbook-20261106/arithmetic.json new file mode 100644 index 0000000..c3b418b --- /dev/null +++ b/evidence/OMEGALLM/macbook-20261106/arithmetic.json @@ -0,0 +1,25 @@ +{ + "case": "arithmetic", + "prompt": "Question: What is 17 plus 25?\nAnswer:", + "qwen": { + "text": " 17 + 25 = 42\nTherefore, the answer is 42.", + "wall_seconds": 0.34758412500377744, + "timings": { + "cache_n": 0, + "prompt_n": 14, + "prompt_ms": 131.258, + "prompt_per_token_ms": 9.37557142857143, + "prompt_per_second": 106.66016547562813, + "predicted_n": 22, + "predicted_ms": 213.908, + "predicted_per_token_ms": 10.186095238095238, + "predicted_per_second": 98.17304635637751 + } + }, + "omega": { + "text": " \"It's 12!\"\nAnabelle was so excited. She wanted to know more.\nAnabelle", + "stderr": "", + "exit": 0, + "wall_seconds": 22.09368458308745 + } +} \ No newline at end of file diff --git a/evidence/OMEGALLM/macbook-20261106/extraction-omega-backend.json b/evidence/OMEGALLM/macbook-20261106/extraction-omega-backend.json new file mode 100644 index 0000000..2acea3b --- /dev/null +++ b/evidence/OMEGALLM/macbook-20261106/extraction-omega-backend.json @@ -0,0 +1,18 @@ +{ + "case": "extraction", + "prompt": "Read this: Maya has three red apples.\nQuestion: How many apples does Maya have? Answer with only the number.\nAnswer:", + "backend": "explicit Omega device, zero GPU layers, flash attention off", + "text": " 3", + "wall_seconds": 1.4914680829970166, + "timings": { + "cache_n": 0, + "prompt_n": 26, + "prompt_ms": 1359.971, + "prompt_per_token_ms": 52.306576923076925, + "prompt_per_second": 19.11805472322572, + "predicted_n": 3, + "predicted_ms": 127.66, + "predicted_per_token_ms": 63.83, + "predicted_per_second": 15.666614444618519 + } +} diff --git a/evidence/OMEGALLM/macbook-20261106/extraction.json b/evidence/OMEGALLM/macbook-20261106/extraction.json new file mode 100644 index 0000000..83ad414 --- /dev/null +++ b/evidence/OMEGALLM/macbook-20261106/extraction.json @@ -0,0 +1,25 @@ +{ + "case": "extraction", + "prompt": "Read this: Maya has three red apples.\nQuestion: How many apples does Maya have? Answer with only the number.\nAnswer:", + "qwen": { + "text": " 3", + "wall_seconds": 0.17388849996495992, + "timings": { + "cache_n": 0, + "prompt_n": 26, + "prompt_ms": 152.139, + "prompt_per_token_ms": 5.851500000000001, + "prompt_per_second": 170.8963513628984, + "predicted_n": 3, + "predicted_ms": 18.994, + "predicted_per_token_ms": 9.497, + "predicted_per_second": 105.29640939243971 + } + }, + "omega": { + "text": " \"These apples are five apples.\"\nAnswer: \"These apples are five apples.\"\nAnswer:", + "stderr": "", + "exit": 0, + "wall_seconds": 34.84761262498796 + } +} \ No newline at end of file diff --git a/evidence/OMEGALLM/macbook-20261106/parity.txt b/evidence/OMEGALLM/macbook-20261106/parity.txt new file mode 100644 index 0000000..f71a68d --- /dev/null +++ b/evidence/OMEGALLM/macbook-20261106/parity.txt @@ -0,0 +1,2 @@ +E 60000 1 1022938 374803 +E 60000 1 1022938 374803 diff --git a/evidence/OMEGALLM/macbook-20261106/pins.json b/evidence/OMEGALLM/macbook-20261106/pins.json new file mode 100644 index 0000000..f4b8a3a --- /dev/null +++ b/evidence/OMEGALLM/macbook-20261106/pins.json @@ -0,0 +1,10 @@ +{ + "source_commit": "77cffb6d6698f59b0644552bcbfe0b639da94abe", + "runner_sha256": "5e20559a9db131b8859fc15c67ac69b598884485ee452d7456d6444e606af149", + "source_sha256": "415a69ec083378dfbfb72513f23a21384f4686f9e124baf53d92f1ca19baf283", + "checkpoint_sha256": "a53ced7265818c8f6197449315e9ca4082721665022fec4f81d4538e8d6c2d0f", + "merges_sha256": "73a29baf97619a746a21232c403bf08af71a76e48b3b2cde6d64dab766083882", + "hardware": "MacBook Air M2, 8 GB", + "execution": "Lima 2.2.0, Apple Virtualization.framework, Debian ARM64, 2 vCPUs, 2 GiB RAM", + "notes": "No new training; existing rung-10 step-60000 checkpoint. Three exploratory prompts, not a general benchmark. Initial qwen field is default-device reference; validated Omega-device results are recorded separately." +} diff --git a/evidence/OMEGALLM/macbook-20261106/refusal.txt b/evidence/OMEGALLM/macbook-20261106/refusal.txt new file mode 100644 index 0000000..9516148 --- /dev/null +++ b/evidence/OMEGALLM/macbook-20261106/refusal.txt @@ -0,0 +1 @@ +corrupted_checkpoint_exit=10 diff --git a/evidence/OMEGALLM/macbook-20261106/story-omega-backend.json b/evidence/OMEGALLM/macbook-20261106/story-omega-backend.json new file mode 100644 index 0000000..4ae0fb5 --- /dev/null +++ b/evidence/OMEGALLM/macbook-20261106/story-omega-backend.json @@ -0,0 +1,18 @@ +{ + "case": "story", + "prompt": "Once upon a time, a little robot found a lost kitten.", + "backend": "explicit Omega device, zero GPU layers, flash attention off", + "text": " The kitten was very cute and the little robot loved it very much. The little robot decided to take the kitten home. The kitten was very happy and the little", + "wall_seconds": 3.15671624999959, + "timings": { + "cache_n": 0, + "prompt_n": 13, + "prompt_ms": 707.016, + "prompt_per_token_ms": 54.38584615384615, + "prompt_per_second": 18.387136924765493, + "predicted_n": 32, + "predicted_ms": 2430.825, + "predicted_per_token_ms": 78.41370967741935, + "predicted_per_second": 12.752871967336192 + } +} diff --git a/evidence/OMEGALLM/macbook-20261106/story.json b/evidence/OMEGALLM/macbook-20261106/story.json new file mode 100644 index 0000000..685bda3 --- /dev/null +++ b/evidence/OMEGALLM/macbook-20261106/story.json @@ -0,0 +1,25 @@ +{ + "case": "story", + "prompt": "Once upon a time, a little robot found a lost kitten.", + "qwen": { + "text": " The kitten was very cute and the little robot loved it very much. The little robot decided to take the kitten home. The kitten was very happy and the little", + "wall_seconds": 0.5438835840905085, + "timings": { + "cache_n": 0, + "prompt_n": 13, + "prompt_ms": 180.506, + "prompt_per_token_ms": 13.885076923076923, + "prompt_per_second": 72.01976665595603, + "predicted_n": 32, + "predicted_ms": 323.397, + "predicted_per_token_ms": 10.43216129032258, + "predicted_per_second": 95.85741364329293 + } + }, + "omega": { + "text": " The kitten was sad and scared. The robot wanted to help the kitten find its home. So, the robot and the kitten went on a journey to find the", + "stderr": "", + "exit": 0, + "wall_seconds": 17.61757670796942 + } +} \ No newline at end of file diff --git a/evidence/OMEGALLM/macbook-edited-20261106/arithmetic.json b/evidence/OMEGALLM/macbook-edited-20261106/arithmetic.json new file mode 100644 index 0000000..a1dccb7 --- /dev/null +++ b/evidence/OMEGALLM/macbook-edited-20261106/arithmetic.json @@ -0,0 +1,16 @@ +{ + "case": "arithmetic", + "prompt": "Question: What is 17 plus 25?\nAnswer:", + "checkpoint_sha256": "131f7e3f26f5494a9882d8107096d4209651978a5bf35eccb3f953203d1f07d6", + "seed": 42, + "tokens": 32, + "temperature_milli": 0, + "omega_edited": { + "text": " \"It's 12!\"\nAnabelle was so excited. She wanted to know more.\nAnabelle", + "stderr": "", + "exit": 0, + "wall_seconds": 23.20632570795715 + }, + "original_evidence": "../macbook-20261106/arithmetic.json", + "qwen_omega_evidence": "../macbook-20261106/arithmetic-omega-backend.json" +} diff --git a/evidence/OMEGALLM/macbook-edited-20261106/extraction.json b/evidence/OMEGALLM/macbook-edited-20261106/extraction.json new file mode 100644 index 0000000..3e430e7 --- /dev/null +++ b/evidence/OMEGALLM/macbook-edited-20261106/extraction.json @@ -0,0 +1,16 @@ +{ + "case": "extraction", + "prompt": "Read this: Maya has three red apples.\nQuestion: How many apples does Maya have? Answer with only the number.\nAnswer:", + "checkpoint_sha256": "131f7e3f26f5494a9882d8107096d4209651978a5bf35eccb3f953203d1f07d6", + "seed": 42, + "tokens": 32, + "temperature_milli": 0, + "omega_edited": { + "text": " \"These apples are five apples. They are all red.\"\nRaya: \"But I want one more apple. They are so", + "stderr": "", + "exit": 0, + "wall_seconds": 33.34238437504973 + }, + "original_evidence": "../macbook-20261106/extraction.json", + "qwen_omega_evidence": "../macbook-20261106/extraction-omega-backend.json" +} diff --git a/evidence/OMEGALLM/macbook-edited-20261106/selection.json b/evidence/OMEGALLM/macbook-edited-20261106/selection.json new file mode 100644 index 0000000..b3bc525 --- /dev/null +++ b/evidence/OMEGALLM/macbook-edited-20261106/selection.json @@ -0,0 +1,20 @@ +{ + "source_commit": "77cffb6d6698f59b0644552bcbfe0b639da94abe", + "runner_sha256": "5e20559a9db131b8859fc15c67ac69b598884485ee452d7456d6444e606af149", + "source_sha256": "415a69ec083378dfbfb72513f23a21384f4686f9e124baf53d92f1ca19baf283", + "merges_sha256": "73a29baf97619a746a21232c403bf08af71a76e48b3b2cde6d64dab766083882", + "hardware": "MacBook Air M2, 8 GB", + "execution": "Lima 2.2.0, Apple Virtualization.framework, Debian ARM64, 2 vCPUs, 2 GiB RAM", + "notes": "Operator selected Astra\u2019s November 4 inference edit for local exploration. Original checkpoint preserved. Runner and tokenizer unchanged. No new training. Published 0.016192% story-loss gain does not establish math or reasoning improvement. Three prompts are exploratory, not a benchmark.", + "original_checkpoint_sha256": "a53ced7265818c8f6197449315e9ca4082721665022fec4f81d4538e8d6c2d0f", + "checkpoint_sha256": "131f7e3f26f5494a9882d8107096d4209651978a5bf35eccb3f953203d1f07d6", + "checkpoint_filename": "omega-v2-edited-20261104.ck", + "experiment_candidate": "alpha-950-gain-1000.ck", + "experiment_pr": "https://github.com/aien-dev/aien-train/pull/63", + "alpha_milli": 950, + "gain_milli": 1000, + "local_copy_hash_verified": true, + "guest_copy_hash_verified": true, + "load_eval_output": "E 60000 1 1024131 375240", + "launcher_syntax_and_startup": "pass" +} diff --git a/evidence/OMEGALLM/macbook-edited-20261106/story.json b/evidence/OMEGALLM/macbook-edited-20261106/story.json new file mode 100644 index 0000000..275a434 --- /dev/null +++ b/evidence/OMEGALLM/macbook-edited-20261106/story.json @@ -0,0 +1,16 @@ +{ + "case": "story", + "prompt": "Once upon a time, a little robot found a lost kitten.", + "checkpoint_sha256": "131f7e3f26f5494a9882d8107096d4209651978a5bf35eccb3f953203d1f07d6", + "seed": 42, + "tokens": 32, + "temperature_milli": 0, + "omega_edited": { + "text": " The kitten was sad and scared. The robot wanted to help the kitten find its home. So, the robot and the kitten went on a journey to find the", + "stderr": "", + "exit": 0, + "wall_seconds": 17.245647500036284 + }, + "original_evidence": "../macbook-20261106/story.json", + "qwen_omega_evidence": "../macbook-20261106/story-omega-backend.json" +} diff --git a/evidence/OMEGALLM/macbook-ui-20261106/.crumb b/evidence/OMEGALLM/macbook-ui-20261106/.crumb new file mode 100644 index 0000000..ef9d13e --- /dev/null +++ b/evidence/OMEGALLM/macbook-ui-20261106/.crumb @@ -0,0 +1,19 @@ +{ + "extensions": { + "generated": { + "children": [], + "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "compiled_at": "2026-11-06T16:38:25Z", + "compiler": "crumb-compile/1", + "digest": "sha256:1eef03c5f9a78a49018d97c25f77233758a595ead1e8a21ce507327abafc30b8", + "evidence_files": 8, + "evidence_root": "sha256:e14d20f963baafdbb04aaa4834a9a671e7e2c9b874f655fd9326bc235234859c", + "files": 8, + "generated_at_commit": "77cffb6d6698f59b0644552bcbfe0b639da94abe", + "source_tree": "sha256:25010a1a10e4dc75ce9c0d07c13f5b0f2abd8d9a12476a7dbb9287b54f53f114" + } + }, + "name": "macbook-ui-20261106", + "purpose": "Local UI streaming, refusal, sampling parity, Aienux resume and pinned artifact evidence", + "schema_version": "1.0.0" +} diff --git a/evidence/OMEGALLM/macbook-ui-20261106/final-aienux.json b/evidence/OMEGALLM/macbook-ui-20261106/final-aienux.json new file mode 100644 index 0000000..f36c92c --- /dev/null +++ b/evidence/OMEGALLM/macbook-ui-20261106/final-aienux.json @@ -0,0 +1,48 @@ +{ + "port": 8099, + "results": [ + { + "case": "stream-parity", + "model": "Omega-Astra-Aienux", + "text": " The", + "first_text_seconds": 14.251059166970663, + "total_seconds": 14.251757082995027, + "pass": true + }, + { + "case": "unknown-model", + "status": 404, + "pass": true + }, + { + "case": "empty-prompt", + "status": 400, + "pass": true + }, + { + "case": "foreign-origin", + "status": 403, + "pass": true + }, + { + "case": "foreign-host", + "status": 403, + "pass": true + }, + { + "case": "tools", + "status": 400, + "pass": true + }, + { + "case": "ui-assets", + "sha256": "4c351e70d8f5d7aee2e4a59b2af818ceceffd100f990a4b8f1e4ed474735c3cd", + "pass": true + }, + { + "case": "qwen-route", + "text": "42", + "pass": true + } + ] +} diff --git a/evidence/OMEGALLM/macbook-ui-20261106/final-linux.json b/evidence/OMEGALLM/macbook-ui-20261106/final-linux.json new file mode 100644 index 0000000..7aaeed1 --- /dev/null +++ b/evidence/OMEGALLM/macbook-ui-20261106/final-linux.json @@ -0,0 +1,48 @@ +{ + "port": 8098, + "results": [ + { + "case": "stream-parity", + "model": "Omega-Astra-2026-11-04", + "text": " The", + "first_text_seconds": 1.973829166032374, + "total_seconds": 1.9799699999857694, + "pass": true + }, + { + "case": "unknown-model", + "status": 404, + "pass": true + }, + { + "case": "empty-prompt", + "status": 400, + "pass": true + }, + { + "case": "foreign-origin", + "status": 403, + "pass": true + }, + { + "case": "foreign-host", + "status": 403, + "pass": true + }, + { + "case": "tools", + "status": 400, + "pass": true + }, + { + "case": "ui-assets", + "sha256": "4c351e70d8f5d7aee2e4a59b2af818ceceffd100f990a4b8f1e4ed474735c3cd", + "pass": true + }, + { + "case": "qwen-route", + "text": "42", + "pass": true + } + ] +} diff --git a/evidence/OMEGALLM/macbook-ui-20261106/parity.json b/evidence/OMEGALLM/macbook-ui-20261106/parity.json new file mode 100644 index 0000000..594407b --- /dev/null +++ b/evidence/OMEGALLM/macbook-ui-20261106/parity.json @@ -0,0 +1,14 @@ +[ + { + "temp": 0, + "tokens": 8, + "equal": true, + "text": " The kitten was sad and scared. The" + }, + { + "temp": 800, + "tokens": 8, + "equal": true, + "text": " The kitten was sad and hungry. The" + } +] \ No newline at end of file diff --git a/evidence/OMEGALLM/macbook-ui-20261106/pins.json b/evidence/OMEGALLM/macbook-ui-20261106/pins.json new file mode 100644 index 0000000..6428dac --- /dev/null +++ b/evidence/OMEGALLM/macbook-ui-20261106/pins.json @@ -0,0 +1,10 @@ +{ + "checkpoint_sha256": "131f7e3f26f5494a9882d8107096d4209651978a5bf35eccb3f953203d1f07d6", + "linux_runner_sha256": "1291225aa92c12d185c98f5f5539068aa3b3ae6fb8c670a9a6718f3806458bcd", + "linux_compiler_sha256": "2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f", + "host_adapter_sha256": "cc2901c24d8bd8503f2686d890b58907d39a408abcb1cf03886e50bf6d347fd2", + "host_adapter_source_sha256": "71324c3d01696e5707a5ff67d402feeb46c755e39b843fd93b9a8cd303189066", + "llama_cpp_revision": "7aca0d2ea8d92b56911233b822db01f9fbb1ae50", + "browser_visual_automation": "NOT_RUN; required browser tool unavailable", + "harness_all_omega_host_migration": "OPEN; temporary C++ adapter has no successor compiler PR" +} diff --git a/evidence/OMEGALLM/macbook-ui-20261106/resume-aienux.json b/evidence/OMEGALLM/macbook-ui-20261106/resume-aienux.json new file mode 100644 index 0000000..cd3835a --- /dev/null +++ b/evidence/OMEGALLM/macbook-ui-20261106/resume-aienux.json @@ -0,0 +1,48 @@ +{ + "port": 8099, + "results": [ + { + "case": "stream-parity", + "model": "Omega-Astra-Aienux", + "text": " The", + "first_text_seconds": 12.693959375028498, + "total_seconds": 12.694197667064145, + "pass": true + }, + { + "case": "unknown-model", + "status": 404, + "pass": true + }, + { + "case": "empty-prompt", + "status": 400, + "pass": true + }, + { + "case": "foreign-origin", + "status": 403, + "pass": true + }, + { + "case": "foreign-host", + "status": 403, + "pass": true + }, + { + "case": "tools", + "status": 400, + "pass": true + }, + { + "case": "ui-assets", + "sha256": "4c351e70d8f5d7aee2e4a59b2af818ceceffd100f990a4b8f1e4ed474735c3cd", + "pass": true + }, + { + "case": "qwen-route", + "text": "42", + "pass": true + } + ] +} diff --git a/evidence/OMEGALLM/macbook-ui-20261106/ui-cancel-check.txt b/evidence/OMEGALLM/macbook-ui-20261106/ui-cancel-check.txt new file mode 100644 index 0000000..b8f6a0a --- /dev/null +++ b/evidence/OMEGALLM/macbook-ui-20261106/ui-cancel-check.txt @@ -0,0 +1 @@ +PASS: concurrent request HTTP429; disconnect releases slot; guest ollm-ui process absent. diff --git a/evidence/OMEGALLM/macbook-ui-20261106/ui-refusals.json b/evidence/OMEGALLM/macbook-ui-20261106/ui-refusals.json new file mode 100644 index 0000000..763429c --- /dev/null +++ b/evidence/OMEGALLM/macbook-ui-20261106/ui-refusals.json @@ -0,0 +1,62 @@ +[ + { + "port": 8098, + "case": "unknown-model", + "status": 404, + "pass": true + }, + { + "port": 8098, + "case": "empty-prompt", + "status": 400, + "pass": true + }, + { + "port": 8098, + "case": "foreign-origin", + "status": 403, + "pass": true + }, + { + "port": 8098, + "case": "foreign-host", + "status": 403, + "pass": true + }, + { + "port": 8098, + "case": "tools", + "status": 400, + "pass": true + }, + { + "port": 8099, + "case": "unknown-model", + "status": 404, + "pass": true + }, + { + "port": 8099, + "case": "empty-prompt", + "status": 400, + "pass": true + }, + { + "port": 8099, + "case": "foreign-origin", + "status": 403, + "pass": true + }, + { + "port": 8099, + "case": "foreign-host", + "status": 403, + "pass": true + }, + { + "port": 8099, + "case": "tools", + "status": 400, + "pass": true + } +] \ No newline at end of file diff --git a/evidence/OMEGALLM/macbook-ui-20261106/ui-stream-check.json b/evidence/OMEGALLM/macbook-ui-20261106/ui-stream-check.json new file mode 100644 index 0000000..0185e58 --- /dev/null +++ b/evidence/OMEGALLM/macbook-ui-20261106/ui-stream-check.json @@ -0,0 +1,7 @@ +{ + "story_byte_parity": true, + "stream_chunks": 32, + "first_text_seconds": 1.8334805839695036, + "total_seconds": 17.29194699996151, + "text": " The kitten was sad and scared. The robot wanted to help the kitten find its home. So, the robot and the kitten went on a journey to find the" +} diff --git a/native/omegallm/.crumb b/native/omegallm/.crumb index 63f170e..b74cbce 100644 --- a/native/omegallm/.crumb +++ b/native/omegallm/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-11-04T20:51:07Z", + "compiled_at": "2026-11-06T16:33:15Z", "compiler": "crumb-compile/1", - "digest": "sha256:2321cdf084f365625f9a716c94a2dadb3ef91764b4db381686fa50071b58c77a", + "digest": "sha256:0cc8e708c29750c9ebcfe82e8d452143b51343e84f03c7aa8f96dbe8531f15de", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 19, - "generated_at_commit": "7dca2e35661b1197a8f06b9b064ed539de8b25a2", - "source_tree": "sha256:da5280cc7878b55919f01aaca68761efc59b816b3b6e6b6a326ebae121e67d62" + "generated_at_commit": "77cffb6d6698f59b0644552bcbfe0b639da94abe", + "source_tree": "sha256:48832e6ede5b63704c12615057a42a0045091df19d83ee8c3284ec177d3cd3ab" } }, "name": "omegallm", diff --git a/native/omegallm/cli.om b/native/omegallm/cli.om index 349ffda..f6dec14 100644 --- a/native/omegallm/cli.om +++ b/native/omegallm/cli.om @@ -324,17 +324,30 @@ exit 2 end tm = oargu 5 v = get og 0 -put og 9 0 -ocpush 0 if gt v 256 if eq na 7 exit 2 end +obload 7 v +end +osampleloaded st nn tm +end + +note Embedding entry: checkpoint and tokenizer already loaded; argument 6 supplies the prompt. +note The caller keeps exclusive ownership of the model pools until this returns. +fn osampleloaded seed ulong nn ulong tm ulong to void +if gt nn 999999 +exit 2 +end +st = seed +v = get og 0 +put og 9 0 +ocpush 0 +if gt v 256 r = oargr 6 if or lt r 0 gt r 4000 exit 2 end -obload 7 v np = obprompt 6 for i ulong np ocpush get obtk i @@ -361,6 +374,8 @@ obtput c else oputc c end +note Flush each decoded token so interactive consumers see progress. Bytes and sampling stay unchanged. +oflush ocpush c end oflush diff --git a/tools/omegallm-ui/.crumb b/tools/omegallm-ui/.crumb new file mode 100644 index 0000000..5a1a1cf --- /dev/null +++ b/tools/omegallm-ui/.crumb @@ -0,0 +1,19 @@ +{ + "extensions": { + "generated": { + "children": [], + "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "compiled_at": "2026-11-06T16:37:55Z", + "compiler": "crumb-compile/1", + "digest": "sha256:737e8871d5cdacdf9b717d0a739048706ccaed9c6ba83e9701e2aba392a8aeb9", + "evidence_files": 0, + "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "files": 5, + "generated_at_commit": "77cffb6d6698f59b0644552bcbfe0b639da94abe", + "source_tree": "sha256:c2b677edd5dc89fc6c557e70878afbdd7577da7c52e0e61c75e7619449c99bc4" + } + }, + "name": "omegallm-ui", + "purpose": "Opt-in Mac llama UI compatibility adapter; Omega model inference in Linux or Aienux firmware", + "schema_version": "1.0.0" +} diff --git a/tools/omegallm-ui/README.md b/tools/omegallm-ui/README.md new file mode 100644 index 0000000..dfe8c14 --- /dev/null +++ b/tools/omegallm-ui/README.md @@ -0,0 +1,70 @@ +# Experimental local llama UI adapter + +This explicitly enabled **C++ host compatibility adapter** reuses llama.cpp's +existing web UI and translates its chat requests into Omega's text sampling. +Model inference remains in the `.om` runner. It provides no new model training, +instruction tuning, or improvement in arithmetic. + +`--enable-local-ui-bridge` serves the ARM64 Linux guest on loopback port 8098. +Adding `--aienux` serves the Aienux firmware experiment on loopback port 8099, +without invoking Lima for that model. Both proxy the existing Qwen/Omega server +and UI assets on port 8097. These are local development endpoints, not a remote +service or a replacement for llama.cpp's complete API. + +The Linux runner is `ollm-ui` in the `omega-llm` guest's `~/omega` directory. +It uses `omega-v2-edited-20261104.ck` and `merges4096.bin`. The firmware runner +is the opt-in `native/omega/allen/local-model.om` application in `aien-dev/aienux`. +The Mac's `Applications/Omega/Aienux` directory holds its private QEMU disk, +firmware, process identifier and Unix sockets. The Aienux launcher verifies the +installed image digests before starting it. + +## Build and operate + +```sh +sh tools/omegallm-ui/build.sh /private/output +/private/output/omega-ui-bridge --enable-local-ui-bridge +# Or, in a separate process: +/private/output/omega-ui-bridge --enable-local-ui-bridge --aienux +``` + +The dependency revision and digests are pinned in `build.sh`. cpp-httplib and +nlohmann/json are MIT licensed, vendored by upstream llama.cpp; preserve their +notices. Drake's installation runs both adapters as user LaunchAgents, with +explicit HOME and PATH. The launchers restart those agents after Stop Omega. +This avoids tying the server's lifetime to a short-lived terminal command. + +Linux accepts at most 4000 prompt bytes, 128 output tokens, and a 120-second +runner deadline. Aienux accepts one printable ASCII prompt of at most 159 +bytes, caps each reply at eight tokens, and has a 1200-second deadline including +boot. Start a new chat for each Aienux prompt. The checkpoint has only a +256-token context window. Message text is joined as plain text, not transformed +into an instruction chat template. + +Only one Omega request is admitted per adapter. Linux cancellation terminates +only that request's guest process group. Firmware cancellation stops this +experiment's private VM through its private monitor socket; reopen **Aienux +Omega.command** afterward. Its read-only checkpoint disk is preserved. This +is slower than keeping a reusable cancelled context but prevents stale output +from being mistaken for the next response. Qwen requests use the existing +server separately. After a successful firmware request the adapter pauses its VM; +the next request resumes it. This prevents UEFI idle polling from consuming a +Mac CPU core. Tool use, structured output and multimodal inputs are refused. + +## Evidence and harness boundary + +`evidence/OMEGALLM/macbook-ui-20261106` records Linux sampling parity, streamed +output, request validation and final endpoint checks. Aienux records its EFI +image hash, native-reference parity, invalid-frame and truncated-checkpoint +refusals, Mac HTTP output and cancellation in its own +`evidence/OMEGA-LOCAL-MODEL/macbook-20261106` directory. Browser assets were +checked over HTTP; browser clicks and rendering were not automated. + +The Omega harness was used for compiler pins, reuse, explicit boundaries, +positive execution and negative controls. **Full harness compliance is not +claimed:** its first-party language rule requires an Omega successor and a +compiler PR for last-resort host code. This adapter's intended successor is an +Omega HTTP/JSON and local-process/Unix-socket runtime on macOS. No such compiler +PR is provided by this experiment. The existing omega-bridge macOS path rejects +Linux host words; its scalar Mach-O support does not supply these runtime APIs. +That migration remains open work, rather than being disguised as generated +code or inferred from model inference running in Omega. diff --git a/tools/omegallm-ui/bridge.cpp b/tools/omegallm-ui/bridge.cpp new file mode 100644 index 0000000..b1dcd3a --- /dev/null +++ b/tools/omegallm-ui/bridge.cpp @@ -0,0 +1,412 @@ +// Opt-in interoperability bridge. Inference remains in the Omega runner. +// Reuses the pinned llama.cpp UI, cpp-httplib and nlohmann/json. +#include "httplib.h" +#include "json.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using json = nlohmann::json; +using Clock = std::chrono::steady_clock; +extern char **environ; +static const char *OMEGA = "Omega-Astra-2026-11-04"; +static constexpr auto QWEN = "build-mac/qwen.gguf"; +static constexpr auto LIMA = "/opt/homebrew/bin/limactl"; +static std::atomic busy{false}; +static std::atomic sequence{0}; +static bool firmware = false; +static int ui_port = 8098; + +static int firmware_socket(const char *name) { + const char *home = getenv("HOME"); + if (!home) throw std::runtime_error("Home directory is unavailable"); + std::string path = std::string(home) + "/Applications/Omega/Aienux/" + name; + sockaddr_un addr{}; + addr.sun_family = AF_UNIX; + if (path.size() >= sizeof(addr.sun_path)) throw std::runtime_error("Aienux socket path is too long"); + std::strcpy(addr.sun_path, path.c_str()); + int fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0 || connect(fd, reinterpret_cast(&addr), sizeof(addr))) { + if (fd >= 0) close(fd); + throw std::runtime_error("Open Aienux Omega.command to start the firmware model"); + } + return fd; +} + +static void reply(httplib::Response &res, const json &j, int status = 200) { + res.status = status; + res.set_content(j.dump(-1, ' ', false, json::error_handler_t::replace), "application/json"); +} +static void error(httplib::Response &res, int status, const std::string &message) { + reply(res, {{"error", {{"message", message}, {"type", "invalid_request_error"}, {"code", status}}}}, status); +} +static pid_t spawn(std::vector args, int *output = nullptr) { + int pipes[2] = {-1, -1}; + if (output && pipe(pipes)) throw std::runtime_error("Cannot create model output pipe"); + posix_spawn_file_actions_t actions; + posix_spawn_file_actions_init(&actions); + posix_spawn_file_actions_addopen(&actions, 0, "/dev/null", O_RDONLY, 0); + posix_spawn_file_actions_addopen(&actions, 2, "/dev/null", O_WRONLY, 0); + if (output) { + posix_spawn_file_actions_adddup2(&actions, pipes[1], 1); + posix_spawn_file_actions_addclose(&actions, pipes[0]); + posix_spawn_file_actions_addclose(&actions, pipes[1]); + } else posix_spawn_file_actions_addopen(&actions, 1, "/dev/null", O_WRONLY, 0); + std::vector argv; + for (auto &arg : args) argv.push_back(arg.data()); + argv.push_back(nullptr); + pid_t pid = -1; + int rc = posix_spawn(&pid, argv[0], &actions, nullptr, argv.data(), environ); + posix_spawn_file_actions_destroy(&actions); + if (output) { + close(pipes[1]); + if (rc) close(pipes[0]); + else *output = pipes[0]; + } + if (rc) throw std::runtime_error("Cannot start local model process"); + return pid; +} + +struct Lease { ~Lease() { busy = false; } }; +struct ModelProcess { + pid_t pid = -1; + int fd = -1; + bool finished = false; + std::string ticket = std::to_string(getpid()) + "-" + std::to_string(++sequence); + unsigned wire_id = sequence.load(); + ~ModelProcess() { + if (firmware) { + if (fd < 0) return; + // A disconnected generation cannot be reused as another request. Stop only this + // experiment's private VM. Its read-only model disk survives; the launcher restarts it. + try { + int monitor = firmware_socket("monitor.sock"); + // UEFI Stall can busy-wait under TCG. Pause a completed VM between requests. + write(monitor, finished ? "stop\n" : "quit\n", 5); + close(monitor); + } catch (...) {} + close(fd); + return; + } + if (pid < 0) return; + try { + // Only our generated ticket names a process group. User text is never shell code. + auto cleanup = spawn({LIMA, "shell", "omega-llm", "sh", "-c", + "f=/tmp/omega-ui-$1.pid; if [ -f \"$f\" ]; then " + "p=$(cat \"$f\"); if [ \"$2\" = cancel ]; then /bin/kill -TERM -- \"-$p\" 2>/dev/null; fi; " + "rm -f \"$f\"; fi", "sh", ticket, finished ? "done" : "cancel"}); + waitpid(cleanup, nullptr, 0); + } catch (...) {} + if (!finished) { kill(pid, SIGTERM); waitpid(pid, nullptr, 0); } + if (fd >= 0) close(fd); + } + void start(const std::string &prompt, int tokens, int temp, unsigned seed) { + if (firmware) { + fd = firmware_socket("serial.sock"); + int monitor = firmware_socket("monitor.sock"); + if (write(monitor, "cont\n", 5) != 5) { close(monitor); throw std::runtime_error("Cannot resume Aienux"); } + close(monitor); + std::string hex; + for (unsigned char c : prompt) { hex += "0123456789abcdef"[c >> 4]; hex += "0123456789abcdef"[c & 15]; } + std::string command = "LM1 " + std::to_string(wire_id) + " " + std::to_string(tokens) + " " + + std::to_string(temp) + " " + std::to_string(seed) + " " + hex + "\r"; + size_t sent = 0; + while (sent < command.size()) { + auto n = write(fd, command.data() + sent, command.size() - sent); + if (n <= 0) throw std::runtime_error("Aienux console disconnected"); + sent += n; + } + return; + } + pid = spawn({LIMA, "shell", "omega-llm", "sh", "-c", + "cd ~/omega && exec setsid --wait sh -c 'echo $$ > \"$1\"; shift; " + "exec timeout --foreground -k 2 120 ./ollm-ui sample omega-v2-edited-20261104.ck \"$@\" merges4096.bin' " + "sh \"/tmp/omega-ui-$1.pid\" \"$2\" \"$3\" \"$4\" \"$5\"", + "sh", ticket, std::to_string(seed), std::to_string(tokens), std::to_string(temp), prompt}, &fd); + } +}; + +// Keep incomplete UTF-8 sequences until the next pipe read. +static size_t complete_utf8(const std::string &s) { + if (s.empty()) return 0; + size_t start = s.size() - 1; + while (start && (static_cast(s[start]) & 0xc0) == 0x80) --start; + unsigned char c = s[start]; + size_t need = c >= 0xf0 ? 4 : c >= 0xe0 ? 3 : c >= 0xc0 ? 2 : 1; + return s.size() - start < need ? start : s.size(); +} + +// Calls emit with new decoded text and with empty strings for keep-alives. +static int generate(ModelProcess &p, const std::function &emit) { + auto begin = Clock::now(); + auto heartbeat = begin; + std::string pending; + std::string wire; + auto data_prefix = "LMDATA " + std::to_string(p.wire_id) + " "; + for (;;) { + if (Clock::now() - begin > std::chrono::seconds(firmware ? 1200 : 125)) return 124; + pollfd poller{p.fd, POLLIN, 0}; + int ready = poll(&poller, 1, 200); + if (ready < 0 && errno != EINTR) return 1; + if (ready > 0) { + char buf[4096]; + auto count = read(p.fd, buf, sizeof(buf)); + if (count <= 0) { if (firmware) return 1; break; } + if (firmware) { + wire.append(buf, count); + if (wire.size() > 32768) return 1; + size_t end; + while ((end = wire.find('\n')) != std::string::npos) { + auto line = wire.substr(0, end); wire.erase(0, end + 1); + if (!line.empty() && line.back() == '\r') line.pop_back(); + if (line == "LMDONE " + std::to_string(p.wire_id)) { + p.finished = true; + if (!pending.empty() && !emit(pending)) return 130; + return 0; + } + if (line.rfind("LMERR ", 0) == 0) { p.finished = true; return 1; } + if (line.rfind(data_prefix, 0) != 0) continue; + auto hex = line.substr(data_prefix.size()); + if (hex.size() % 2) return 1; + auto nibble = [](char c) -> int { return c >= '0' && c <= '9' ? c - '0' : c >= 'a' && c <= 'f' ? c - 'a' + 10 : -1; }; + for (size_t k = 0; k < hex.size(); k += 2) { + int a = nibble(hex[k]), b = nibble(hex[k + 1]); + if (a < 0 || b < 0) return 1; + pending += char(a * 16 + b); + } + } + } else pending.append(buf, count); + auto length = complete_utf8(pending); + if (length && !emit(pending.substr(0, length))) return 130; + pending.erase(0, length); + } + if (Clock::now() - heartbeat >= std::chrono::seconds(1)) { + if (!emit("")) return 130; + heartbeat = Clock::now(); + } + } + int status = 0; + waitpid(p.pid, &status, 0); + p.finished = true; + if (!pending.empty() && !emit(pending)) return 130; + return WIFEXITED(status) ? WEXITSTATUS(status) : 1; +} + +static json model(const std::string &id) { + return {{"id", id}, {"name", id}, {"object", "model"}, {"owned_by", "local"}, + {"created", 0}, {"path", ""}, {"in_cache", false}, {"aliases", json::array({id})}, + {"status", {{"value", "loaded"}, {"args", json::array()}}}, + {"architecture", {{"input_modalities", {"text"}}, {"output_modalities", {"text"}}}}}; +} +static json upstream_props() { + httplib::Client client("127.0.0.1", 8097); + client.set_connection_timeout(2); + auto r = client.Get("/props"); + if (!r || r->status != 200) throw std::runtime_error("Start Qwen through Omega to load the llama UI"); + return json::parse(r->body); +} + +static void completion(const httplib::Request &req, httplib::Response &res) { + json body = json::parse(req.body); + auto selected = body.value("model", std::string(OMEGA)); + if (selected == QWEN) { + const bool streaming = body.value("stream", false); + if (streaming) { + auto data = body.dump(); + res.set_chunked_content_provider("text/event-stream", [data](size_t, httplib::DataSink &sink) { + httplib::Client client("127.0.0.1", 8097); + client.set_read_timeout(130); + auto r = client.Post("/v1/chat/completions", {}, data, "application/json", + [&](const char *bytes, size_t count) { return sink.write(bytes, count); }); + if (!r || r->status != 200) { + std::string e = "data: " + json({{"error", {{"message", "Qwen request failed"}}}}).dump() + "\n\n"; + sink.write(e.data(), e.size()); + } + sink.done(); + return true; + }); + } else { + httplib::Client client("127.0.0.1", 8097); + client.set_read_timeout(130); + auto r = client.Post("/v1/chat/completions", body.dump(), "application/json"); + if (!r) { error(res, 502, "Qwen is unavailable"); return; } + res.status = r->status; + res.set_content(r->body, "application/json"); + } + return; + } + if (selected != OMEGA) { error(res, 404, "Unknown local model"); return; } + for (auto key : {"tools", "stop", "grammar", "response_format"}) { + if (body.contains(key) && !body[key].is_null() && !body[key].empty()) { + error(res, 400, std::string("Omega's story model does not support ") + key); return; + } + } + if (body.value("n", 1) != 1) { error(res, 400, "Omega supports one completion at a time"); return; } + std::string prompt; + if (!body.contains("messages") || !body["messages"].is_array()) { error(res, 400, "messages must be an array"); return; } + for (const auto &message : body["messages"]) { + auto role = message.value("role", std::string()); + if (role != "user" && role != "assistant" && role != "system") { error(res, 400, "Omega accepts text messages only"); return; } + auto content = message.at("content"); + std::string text; + if (content.is_string()) text = content.get(); + else if (content.is_array()) { + for (const auto &part : content) { + if (part.value("type", "") != "text") { error(res, 400, "Omega accepts text only"); return; } + text += part.at("text").get(); + } + } else { error(res, 400, "Message content must be text"); return; } + if (text.empty()) continue; + if (!prompt.empty()) prompt += "\n"; + prompt += text; + } + if (prompt.empty() || prompt.size() > 4000 || prompt.find('\0') != std::string::npos) { + error(res, 400, "Enter a story beginning or shorten this conversation to at most 4000 UTF-8 bytes"); return; + } + if (firmware && (prompt.size() > 159 || std::any_of(prompt.begin(), prompt.end(), [](unsigned char c) { return c < 32 || c > 126; }))) { + error(res, 400, "Aienux currently accepts one story beginning of up to 159 plain ASCII characters. Start a new chat for each prompt."); return; + } + int tokens = body.value("max_tokens", 64); + if (body.contains("max_completion_tokens") && !body["max_completion_tokens"].is_null()) tokens = body["max_completion_tokens"].get(); + if (tokens == -1) tokens = 64; + if (tokens < 1 || tokens > 128) { error(res, 400, "Set maximum output tokens between 1 and 128 for Omega"); return; } + if (firmware) tokens = std::min(tokens, 8); + double temperature = body.value("temperature", 0.8); + if (!std::isfinite(temperature) || temperature < 0 || temperature > 2) { error(res, 400, "Temperature must be between 0 and 2"); return; } + int seed = body.value("seed", 42); + if (seed < 0) seed = 42; + bool streaming = body.value("stream", false); + bool expected = false; + if (!busy.compare_exchange_strong(expected, true)) { error(res, 429, "Omega is already generating. Stop that response or wait for it to finish."); return; } + auto lease = std::make_shared(); + auto child = std::make_shared(); + child->start(prompt, tokens, int(temperature * 1000), unsigned(seed)); + std::string id = "omega-" + child->ticket; + auto created = std::time(nullptr); + auto chunk = [id, created](const json &delta, const json &reason = nullptr) { + return json{{"id", id}, {"object", "chat.completion.chunk"}, {"created", created}, {"model", OMEGA}, + {"choices", json::array({{{"index", 0}, {"delta", delta}, {"finish_reason", reason}}})}}; + }; + if (streaming) { + res.set_header("Cache-Control", "no-cache"); + auto closed = req.is_connection_closed; + res.set_chunked_content_provider("text/event-stream", [lease, child, chunk, closed](size_t, httplib::DataSink &sink) { + auto send = [&](const json &j) { + auto s = "data: " + j.dump(-1, ' ', false, json::error_handler_t::replace) + "\n\n"; + return !closed() && sink.write(s.data(), s.size()); + }; + if (!send(chunk({{"role", "assistant"}, {"content", ""}}))) return false; + int rc = generate(*child, [&](const std::string &text) { + if (closed()) return false; + return text.empty() ? sink.write(": generating\n\n", 14) : send(chunk({{"content", text}})); + }); + if (rc == 130) return false; + if (rc) send(chunk({{"content", "\n\n[Omega runtime error: generation failed or timed out. Try a shorter story beginning.]"}})); + else send(chunk(json::object(), "stop")); + sink.write("data: [DONE]\n\n", 14); + sink.done(); + return true; + }); + } else { + std::string text; + int rc = generate(*child, [&](const std::string &part) { text += part; return !req.is_connection_closed(); }); + if (rc) { error(res, 502, "Omega generation failed or timed out"); return; } + reply(res, {{"id", id}, {"object", "chat.completion"}, {"created", created}, {"model", OMEGA}, + {"choices", json::array({{{"index", 0}, {"message", {{"role", "assistant"}, {"content", text}}}, {"finish_reason", "stop"}}})}}); + } +} + +int main(int argc, char **argv) { + if ((argc != 2 && argc != 3) || std::string(argv[1]) != "--enable-local-ui-bridge" || + (argc == 3 && std::string(argv[2]) != "--aienux")) { + std::cerr << "Opt in with --enable-local-ui-bridge\n"; return 2; + } + firmware = argc == 3; + if (firmware) { ui_port = 8099; OMEGA = "Omega-Astra-Aienux"; } + signal(SIGPIPE, SIG_IGN); + httplib::Server server; + server.set_payload_max_length(65536); + server.set_read_timeout(10); + server.set_write_timeout(10); + server.set_exception_handler([](const auto &, auto &res, std::exception_ptr exception) { + try { std::rethrow_exception(exception); } + catch (const json::exception &) { error(res, 400, "Invalid JSON or parameter type"); } + catch (const std::exception &e) { error(res, 503, e.what()); } + }); + server.set_pre_routing_handler([](const auto &req, auto &res) { + // Local UI only. Do not admit arbitrary websites through permissive CORS. + auto host = req.get_header_value("Host"); + if (host != "127.0.0.1:" + std::to_string(ui_port) && host != "localhost:" + std::to_string(ui_port)) { + error(res, 403, "Only the local Omega host is allowed"); + return httplib::Server::HandlerResponse::Handled; + } + if (req.has_header("Origin")) { + auto origin = req.get_header_value("Origin"); + if (origin != "http://127.0.0.1:" + std::to_string(ui_port) && origin != "http://localhost:" + std::to_string(ui_port)) { + error(res, 403, "Only the local Omega UI is allowed"); + return httplib::Server::HandlerResponse::Handled; + } + } + return httplib::Server::HandlerResponse::Unhandled; + }); + server.Get("/health", [](const auto &, auto &res) { reply(res, {{"status", "ok"}, {"service", "omega-ui-bridge"}, {"runtime", firmware ? "aienux-firmware" : "linux"}, {"omega_busy", busy.load()}}); }); + server.Get("/v1/models", [](const auto &, auto &res) { reply(res, {{"object", "list"}, {"data", {model(OMEGA), model(QWEN)}}}); }); + server.Get("/props", [](const auto &req, auto &res) { + auto props = upstream_props(); + auto selected = req.get_param_value("model"); + if (selected.empty()) props["role"] = "router"; + else if (selected != OMEGA && selected != QWEN) { error(res, 404, "Unknown model"); return; } + if (selected != QWEN) { + props["model_alias"] = OMEGA; + props["model_path"] = OMEGA; + props.erase("model_ftype"); + props["bos_token"] = ""; + props["eos_token"] = ""; + props["default_generation_settings"]["params"]["max_tokens"] = firmware ? 8 : 64; + props["default_generation_settings"]["params"]["n_predict"] = firmware ? 8 : 64; + props["default_generation_settings"]["params"]["seed"] = 42; + props["default_generation_settings"]["n_ctx"] = 256; + props["chat_template"] = "{% for message in messages %}{{ message.content }}{% endfor %}"; + props["chat_template_caps"] = {{"supports_tools", false}, {"supports_tool_calls", false}, {"supports_system_role", false}}; + props["ui_settings"] = {{"max_tokens", firmware ? 8 : 64}, {"enableDiscoverModels", false}, {"titleGenerationUseLLM", false}}; + } + props["endpoint_slots"] = false; + reply(res, props); + }); + server.Get("/slots", [](const auto &, auto &res) { reply(res, json::array()); }); + server.Get("/tools", [](const auto &, auto &res) { reply(res, {{"tools", json::array()}}); }); + server.Get("/models/sse", [](const auto &req, auto &res) { + auto closed = req.is_connection_closed; + res.set_chunked_content_provider("text/event-stream", [closed](size_t, httplib::DataSink &sink) { + if (closed()) return false; + if (!sink.write(": local models ready\n\n", 22)) return false; + std::this_thread::sleep_for(std::chrono::seconds(2)); + return true; + }); + }); + server.Post("/v1/chat/completions", completion); + server.Post("/models/load", [](const auto &, auto &res) { reply(res, {{"success", true}}); }); + // Reuse the already-running llama UI assets without changing its files. + server.Get("/.*", [](const auto &req, auto &res) { + if (req.path.rfind("/v1/", 0) == 0 || req.path.rfind("/models/", 0) == 0) { error(res, 404, "Endpoint unavailable in local bridge"); return; } + httplib::Client client("127.0.0.1", 8097); + client.set_decompress(false); + httplib::Headers headers{{"Accept-Encoding", "gzip"}}; + auto r = client.Get(req.target, headers); + if (!r) { error(res, 502, "Start Qwen through Omega to load the llama UI"); return; } + res.status = r->status; + res.set_content(r->body, r->get_header_value("Content-Type")); + if (r->has_header("Content-Encoding")) res.set_header("Content-Encoding", r->get_header_value("Content-Encoding")); + }); + std::cout << "Omega + Qwen llama UI: http://127.0.0.1:" << ui_port << (firmware ? " (Aienux firmware)" : " (Linux)") << "\n" << std::flush; + return server.listen("127.0.0.1", ui_port) ? 0 : 1; +} diff --git a/tools/omegallm-ui/build.sh b/tools/omegallm-ui/build.sh new file mode 100644 index 0000000..c49a3f7 --- /dev/null +++ b/tools/omegallm-ui/build.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Explicit, temporary Mac host compatibility experiment. Not an Omega-native runtime. +set -eu +[ "$#" = 1 ] || { echo 'usage: build.sh OUTPUT_DIRECTORY' >&2; exit 2; } +out=$1 +here=$(CDPATH= cd -- "$(dirname "$0")" && pwd) +mkdir -p "$out/deps" +base=https://raw.githubusercontent.com/ggml-org/llama.cpp/7aca0d2ea8d92b56911233b822db01f9fbb1ae50/vendor +fetch() { + file=$1 url=$2 hash=$3 + if [ ! -f "$out/deps/$file" ]; then curl --fail --location "$url" -o "$out/deps/$file"; fi + actual=$(shasum -a 256 "$out/deps/$file" | cut -d' ' -f1) + [ "$actual" = "$hash" ] || { echo "dependency digest mismatch: $file" >&2; exit 65; } +} +fetch httplib.h "$base/cpp-httplib/httplib.h" a595e3f0d864e1606f9455ed4a8738de66fc8ef4abf7164e6570fe0e0393080b +fetch httplib.cpp "$base/cpp-httplib/httplib.cpp" 516c58994baa9bcc3b5616f453710c0b4d2d341ac473f788fcfb029f8548caa5 +fetch json.hpp "$base/nlohmann/json.hpp" 08f19bbcc66ff3082f5caf58867b1232987dba98d82e2b29d870722fce42776b +fetch httplib-LICENSE "$base/cpp-httplib/LICENSE" 4b45cbe16d7b71b89ae6127e26e0d90a029198ca5e958ad8e3d0b8bbed364d8b +# nlohmann/json's MIT notice is embedded in json.hpp. Keep both notices with the binary. +c++ -std=c++17 -O1 -pthread -Wall -Wextra -I "$out/deps" \ + "$here/bridge.cpp" "$out/deps/httplib.cpp" -o "$out/omega-ui-bridge" +shasum -a 256 "$out/omega-ui-bridge" diff --git a/tools/omegallm-ui/check.py b/tools/omegallm-ui/check.py new file mode 100644 index 0000000..d8ffb97 --- /dev/null +++ b/tools/omegallm-ui/check.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +"""HTTP test oracle only. Not a model runtime or installation dependency.""" +import argparse +import hashlib +import json +import time +import urllib.error +import urllib.request +from pathlib import Path + +p = argparse.ArgumentParser() +p.add_argument("--port", type=int, choices=(8098, 8099), required=True) +p.add_argument("--output", type=Path, required=True) +a = p.parse_args() +model = "Omega-Astra-Aienux" if a.port == 8099 else "Omega-Astra-2026-11-04" +base = f"http://127.0.0.1:{a.port}" +results = [] + +def request(path, body=None, headers=None): + return urllib.request.urlopen(urllib.request.Request( + base + path, None if body is None else json.dumps(body).encode(), + {"Content-Type": "application/json", **(headers or {})}), timeout=180) + +body = {"model": model, "messages": [{"role": "user", "content": + "Once upon a time, a little robot found a lost kitten."}], + "temperature": 0, "seed": 42, "max_tokens": 1, "stream": True} +start = time.monotonic() +text = "" +first = None +done = False +with request("/v1/chat/completions", body) as response: + for raw in response: + if not raw.startswith(b"data: "): + continue + line = raw[6:].strip() + if line == b"[DONE]": + done = True + break + part = json.loads(line)["choices"][0]["delta"].get("content", "") + if part and first is None: + first = time.monotonic() - start + text += part +assert text == " The" and done, (text, done) +results.append({"case": "stream-parity", "model": model, "text": text, + "first_text_seconds": first, "total_seconds": time.monotonic() - start, "pass": True}) + +for name, payload, headers, expected in [ + ("unknown-model", {"model": "unknown", "messages": []}, {}, 404), + ("empty-prompt", {"model": model, "messages": []}, {}, 400), + ("foreign-origin", body, {"Origin": "https://example.invalid"}, 403), + ("foreign-host", body, {"Host": "example.invalid"}, 403), + ("tools", {**body, "tools": [{}]}, {}, 400), +]: + try: + with request("/v1/chat/completions", payload, headers) as r: + status = r.status + except urllib.error.HTTPError as e: + status = e.code + assert status == expected, (name, status, expected) + results.append({"case": name, "status": status, "pass": True}) + +with request("/") as r: + actual = r.read() +with urllib.request.urlopen(urllib.request.Request("http://127.0.0.1:8097/", + headers={"Accept-Encoding": "gzip"}), timeout=10) as r: + reference = r.read() +assert actual == reference, "UI asset proxy changed the upstream bytes" +results.append({"case": "ui-assets", "sha256": hashlib.sha256(actual).hexdigest(), "pass": True}) + +with request("/v1/chat/completions", {"model": "build-mac/qwen.gguf", "messages": [ + {"role": "user", "content": "What is 17 plus 25? Answer with only the number."}], + "temperature": 0, "max_tokens": 8, "stream": False}) as r: + answer = json.load(r)["choices"][0]["message"]["content"] +assert "42" in answer, answer +results.append({"case": "qwen-route", "text": answer, "pass": True}) +a.output.parent.mkdir(parents=True, exist_ok=True) +a.output.write_text(json.dumps({"port": a.port, "results": results}, indent=2) + "\n") +print(f"PASS port={a.port} checks={len(results)}") diff --git a/tools/omegallm-ui/start-aienux.command b/tools/omegallm-ui/start-aienux.command new file mode 100644 index 0000000..3176203 --- /dev/null +++ b/tools/omegallm-ui/start-aienux.command @@ -0,0 +1,64 @@ +#!/bin/zsh +set -eu +export PATH=/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin +root="$HOME/Applications/Omega/Aienux" +runtime="$HOME/workspace/aien-train-macbook/local-mac" +qwen="$HOME/workspace/ggml-omega-macbook" +uid=$(id -u) +running=0 +if [[ -f "$root/qemu.pid" ]]; then + pid=$(cat "$root/qemu.pid") + command=$(ps -p "$pid" -o command= 2>/dev/null || true) + if [[ "$command" == *qemu-system-x86_64* && "$command" == *"$root/model.img"* ]]; then running=1; fi +fi +if (( ! running )); then + (cd "$root" && shasum -a 256 -c SHA256SUMS) + : > "$root/boot.log" + vm_label=dev.aien.omega-aienux-vm + if ! launchctl print "gui/$uid/$vm_label" >/dev/null 2>&1; then + launchctl bootstrap "gui/$uid" "$HOME/Library/LaunchAgents/$vm_label.plist" + fi + launchctl kickstart "gui/$uid/$vm_label" + vm_pid=$(launchctl print "gui/$uid/$vm_label" | awk '/pid =/{print $3; exit}') + [[ -n "$vm_pid" ]] || { print 'Aienux VM did not start.'; exit 1; } + print "$vm_pid" > "$root/qemu.pid" + sleep 1 + nohup /usr/bin/nc -d -U "$root/serial.sock" >> "$root/boot.log" 2>&1 < /dev/null & + reader=$! + disown + print 'Aienux is loading Astra’s model. This uses emulation and can take several minutes.' + ready=0 + for attempt in {1..600}; do + if grep -q '^LMREADY' "$root/boot.log"; then ready=1; break; fi + if ! kill -0 "$vm_pid" 2>/dev/null; then break; fi + sleep 1 + done + kill "$reader" 2>/dev/null || true + if (( ! ready )); then + kill "$vm_pid" 2>/dev/null || true + print 'Aienux did not load. The boot log is in Applications/Omega/Aienux.' + exit 1 + fi + # The model is ready; avoid firmware polling consuming a core while the browser opens. + print 'stop' | /usr/bin/nc -U -w 1 "$root/monitor.sock" >/dev/null || true +fi +if ! curl -fsS http://127.0.0.1:8097/health >/dev/null; then + (cd "$qwen" && export GGML_BACKEND_PATH="$qwen/build-mac/prepared/libggml-omega.dylib" OMEGA_GGML_DEVICES=host && exec nohup "$qwen/build-mac/runtime/llama-b11913/llama-server" -m build-mac/qwen.gguf --device Omega -ngl 0 -fa off -c 2048 -b 64 -ub 64 -t 2 --parallel 1 --host 127.0.0.1 --port 8097 --fit off) >"$runtime/qwen-ui.log" 2>&1 /dev/null 2>&1; then + launchctl bootstrap "gui/$uid" "$HOME/Library/LaunchAgents/$label.plist" +fi +launchctl kickstart "gui/$uid/$label" +for attempt in {1..30}; do + if curl -fsS http://127.0.0.1:8099/props >/dev/null; then + open http://127.0.0.1:8099 + print 'Choose Omega-Astra-Aienux. Enter one short story beginning. Each reply is limited to eight tokens.' + print 'This experimental firmware path is slow. After pressing Stop, reopen this launcher to restart Aienux.' + exit 0 + fi + sleep 1 +done +print 'The Aienux browser adapter did not start.' +exit 1