Repository navigation
feat: add native support for System One / Decision Models (Python API and /v1/systemone endpoint) - #2419
Open
Kra09-kp wants to merge 7 commits into
Open
feat: add native support for System One / Decision Models (Python API and /v1/systemone endpoint)#2419Kra09-kp wants to merge 7 commits into
Kra09-kp wants to merge 7 commits into
Conversation
…ut with median spec
This branch has not been deployed
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.
Summary
This PR brings native support for System One / Decision Models into
llama-cpp-python, implementing full feature parity with upstreamllama.cpp's native decision subsystem (introduced intools/server/server-decision.cppvia upstream PR #29818).Decision models (such as Liquid AI's d1, OpenJev, Julia-1, Lev, Laya, Kev, and Clef) evaluate an input state against structured, typed questions in a single forward pass without autoregressive token generation overhead.
Key Changes
Python API (
Llama.create_system_one&Llama.system_one):create_system_one(state, questions, temperature=None, model=None)onLlama.llama_model_chat_template(model, "systemone")or metadatatokenizer.chat_template.systemone.<arch>.decision.temperature.<type>).special=Trueto preserve model control tokens (<|startoftext|>,<|im_start|>,<think></think>).Server API (
POST /v1/systemone):POST /v1/systemonein the FastAPI server (llama_cpp/server/app.py), matching the wire format used byllama-server.llama_cpp/server/types.py.Supported Question Types:
choice: Discrete category selection with confidence scores and normalized probabilities. Supportsmultiple: Truemulti-label selection.score: Continuous and ordinal rubric rating, returning calibratedscore(median level readout matching upstream spec),level, andlabel.noul: Calibrated binary probability (P(true)/P(yes)).Non-Causal Attention Model Compatibility:
d1specifylfm3.attention.causal: false. Inllama.cpp, non-causal architectures do not initialize autoregressive KV cache buffers (memory is None).llama_cpp/_internals.py(kv_cache_seq_rm,kv_cache_seq_cp, etc.) to safely no-op whenself.memory is None, preventing assertion failures.Type Hints & Unit Tests:
llama_cpp/llama_types.py(SystemOneQuestion,SystemOneResponse,SystemOneChoiceAnswer,SystemOneScoreAnswer,SystemOneNoulAnswer).tests/test_system_one.pycovering serialization, type validation, and mock inference.Verification & Empirical Parity
Tested directly against PyTorch reference implementation (
AutoModel.from_pretrained("LiquidAI/d1-2B", dtype=torch.bfloat16).to("cuda")) using GGUF weights on GPU:Test 1: Customer Support Routing & Urgency
"I was charged twice and my parcel never arrived. Please refund one charge."refund:0.9979(>99.7% confidence, PyTorch:0.9968)team:'billing'(PyTorch:'billing')topics:['billing', 'delivery'](PyTorch:['billing', 'delivery'])urgency:score=1.0,label='medium'(PyTorch:score=1.0,label='medium')Test 2: Counting & Spatial Reasoning
"In the living room, two cats are sleeping on the sofa next to a remote control."cat_count: PyTorch2.0vs GGUF2.0has_remote: PyTorch0.997vs GGUF0.997furniture: PyTorchsofa(99.80%) vs GGUFsofa(99.78%)Files Changed
llama_cpp/_internals.py: Safe guards for non-causal KV cache operations.llama_cpp/llama.py: Implementation ofcreate_system_oneandsystem_one.llama_cpp/llama_types.py: Typing definitions for questions and answers.llama_cpp/server/app.py:/v1/systemoneFastAPI route.llama_cpp/server/types.py: Pydantic models for the systemone endpoint.tests/test_system_one.py: Unit test coverage.