Repository navigation
memagent: in-process llama.cpp engine, selectable against the Python worker - #2
Merged
Merged
Conversation
- Mem.Llama: dynlibs binding to llama.h at tag b11985, record layouts asserted at compile time - Mem.Engine.Llama: TLlamaEngine (chat template, HF-style repetition penalty, UTF-8-safe streaming, LoRA hot swap via llama_set_adapters_lora) - Mem.Extract: Pascal port of memlib fact extraction, parity test against cases dumped from Python (458/458) - [agent] engine=python|llama, --engine, [llama] section - trainer/gguf_export.py; consolidate.py --gguf writes adapter.gguf before ready.json; engine converts older adapters on first load - scripts/llama_setup.sh, make llama, make test-e2e-llama Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
Four ggml threads on four cores ran 2.4x slower than three (spinning workers contend with the agent thread and ONNX Runtime). Python vs llama on the 30-fact system benchmark: same accuracy, 1.29 s vs 1.55 s per turn. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPVFJHeBeotAKkU7EPbTgn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
The model can now run inside the Pascal program through llama.cpp, with no Python while chatting. It is a module behind the existing
TEngineinterface, so you can pick either engine:You can also pass
--engine llamafor a single run.memagent.lpris the only place that knows which engine is running; the agent loop, store, retrieval and guard did not change.New units
Mem.Llama: binds the llama.cpp calls the engine needs, at tagb11985. The library is loaded at run time, somemagentstill builds and runs on the Python engine without it. Record sizes are checked against the C compiler at compile time, so a mismatched header fails the build instead of corrupting memory. It also masks FPU exceptions, which ggml needs.Mem.Engine.Llama(TLlamaEngine):llama_adapter_lora_initandllama_set_adapters_lora./abdetaches the adapter for a single call.[gpu] infer, so the training GPU stays free.Mem.Extract: a Pascal port of the Python fact extraction (rules,has_statement, the LLM extraction prompt, JSON parsing and grounding). A parity test gives the same result as Python on all 458 checks (memagent/tests/gen_extract_cases.py,extract_test.lpr).GGUF pipeline (training stays in Python)
trainer/gguf_export.py: converts the base model, and each adapter, to GGUF.consolidate.py --ggufwritesadapter.ggufbeforeready.json, so the swap never waits for a conversion. It adds 3–4 s per consolidation.models.jsongets a"gguf"entry per profile.mediumandlargeconvert toq8_0;largeconverts from the full-precision Magistral weights, because its training base is bnb-4bit.scripts/llama_setup.sh(make llama) checks out and builds llama.cppb11985as shared libraries incache/llama, so the folder can be moved. It also converts the base models.LLAMA_CUDA=1builds the CUDA backend.Results (
bench/README.md)30 facts, tiny profile, 4-core CPU, temperature 0, both runs on the same build:
Testing
make test: extraction parity (458/458), retrieval and TLS checks, and the Python unit tests (22, including the new GGUF settings tests).make test-e2e-llama: the full e2e suite on the llama engine passes (two consolidations, a correction,/forget,/rollback, non-ASCII facts).bench/bench_agent.py --engine python|llama: the comparison above.Not tested
small,mediumandlargeon the llama engine.Generated by Claude Code