### Run llama-server and install jevk5 package Source: https://github.com/allebee/jevk5/blob/main/README.md Starts llama-server with the JevK5 4B v0.3 Q8_0 GGUF file from the Hugging Face repo, using a context size of 8192 and offloading all layers to the GPU. Then installs the jevk5 Python package from the v0.3.0 tag without dependencies, relying only on the standard library. ```bash llama-server --hf-repo alibiserikbay/JevK5-GGUF --hf-file jevk5-4b-v0.3-Q8_0.gguf -c 8192 -ngl 99 pip install --no-deps "jevk5 @ git+https://github.com/allebee/jevk5@v0.3.0" # standard library only ``` -------------------------------- ### Install JevK5-Lite with pip Source: https://github.com/allebee/jevk5/blob/main/README.md Install the JevK5-Lite package from the v0.3.2 tag on GitHub. This is the required setup before using the JevK5Lite class. ```bash pip install "jevk5[lite] @ git+https://github.com/allebee/jevk5@v0.3.2" ``` -------------------------------- ### Setup and run JevK5 models on JevBench Source: https://github.com/allebee/jevk5/blob/main/bench/SUBMISSION.md Setup and run commands for the three JevK5 models on JevBench. Requires CUDA GPU for the direct adapters (v0.3 4B ~10 GB, 9B ~20 GB) and CPU for Lite. The patch registers both adapters; the Lite run uses bf16 with 16 threads and disables CUDA. ```bash git clone https://github.com/allebee/jevk5 && cd jevk5 && git checkout 6578e777222a075c4c8001b0e147bce6dd013eba pip install -e ".[fast,lite]" # torch, transformers>=5.17, flash-linear-attention; safetensors for Lite cp bench/jevk5_direct.py bench/jevk5_lite.py /jevbench/adapters/ cd && git apply /bench/jevbench-registration.patch # registers both adapters JEVBENCH_WARM_LOAD=1 python -m jevbench.cli run --adapter jevk5_direct \ --endpoint alibiserikbay/JevK5 --revision c4f7fdb3aeab5582336406e78d3bef11bf98833d --model jevk5-v0.3 \ --tasks --results ... JEVBENCH_WARM_LOAD=1 python -m jevbench.cli run --adapter jevk5_direct \ --endpoint alibiserikbay/JevK5-9B --revision d6521a18a86999190e9d775c915af3d6d6772fc4 --model jevk5-9b-v0.3.3 \ --tasks --results ... JEVK5_LITE_DTYPE=bf16 JEVK5_LITE_THREADS=16 CUDA_VISIBLE_DEVICES= JEVBENCH_WARM_LOAD=1 python -m jevbench.cli run \ --adapter jevk5_lite --endpoint alibiserikbay/JevK5-Lite \ --revision 315ee211f828a899161477c534cea23e84ba3568 --model jevk5-lite-preview1 \ --tasks --results ... ``` -------------------------------- ### prompt_text() usage example Source: https://github.com/allebee/jevk5 Example call to prompt_text() with sample arguments. The assertion verifies the returned string starts with the system message token. ```python from jevk5.prompt import prompt_text text = prompt_text("T", "Criterion?", ["a", "b"]) assert text.startswith("<|im_start|>system\n") ``` -------------------------------- ### Install jevk5 with fast extra Source: https://github.com/allebee/jevk5/blob/main/README.md Install the jevk5 package with the 'fast' extra from the v0.3.0 tag on GitHub. The 'fast' extra includes flash-linear-attention, which speeds up long inputs; without it, Qwen3.5's linear-attention layers fall back to transformers' PyTorch code. ```bash pip install "jevk5[fast] @ git+https://github.com/allebee/jevk5@v0.3.0" ``` -------------------------------- ### Run JevK5 as a TypeSafe-style server Source: https://github.com/allebee/jevk5/blob/main/MODEL_CARD.md Starts a server that answers TypeSafe-style /v1/systemone requests. Reads temperature and knockout_temperature from jevk5_config.json. ```bash jevk5-serve --model alibiserikbay/JevK5 --port 8090 ``` -------------------------------- ### decision_options usage example Source: https://github.com/allebee/jevk5 Shows how to call decision_options with a choice-type question. The example uses a criteria list and produces option pairs where the text is the key itself when no description is provided. ```python from jevk5.prompt import decision_options opts = decision_options({"type": "choice", "instructions": "x", "criteria": ["delivered", "misdelivered"]}) # [('delivered', 'delivered: delivered'), ('misdelivered', 'misdelivered: misdelivered')] ``` -------------------------------- ### messages() usage example Source: https://github.com/allebee/jevk5 Example call to messages() with sample evidence, criterion, and options. The output shows the system and user messages, with the user content containing the JSON payload. ```python from jevk5.prompt import messages msgs = messages("I paid twice.", "Asks for a refund?", ["yes", "no"]) # [{'role': 'system', 'content': SYSTEM}, # {'role': 'user', 'content': '{"evidence": "I paid twice.", "criterion": ..., "options": [...]}'}] ``` -------------------------------- ### Usage example for answer() with score type Source: https://github.com/allebee/jevk5 Shows how to call answer() with a 'score' question and a probability dict. The output includes 'score' as the expectation (1.5) and 'probabilities'. Requires decision_options to get option ids. ```python from jevk5.prompt import answer, decision_options q = {"type": "score", "instructions": "Rate satisfaction.", "criteria": ["bad", "ok", "great"]} ids = [k for k, _ in decision_options(q)] out = answer(q, {"0": 0.1, "1": 0.3, "2": 0.6}, 42) # {'type': 'score', 'confidence': 0.6, 'input_tokens': 42, 'score': 1.5, 'probabilities': {...}} ``` -------------------------------- ### main(argv: list[str] | None = None) -> int Source: https://github.com/allebee/jevk5 Starts the JevK5 HTTP server. This function parses command-line arguments, initializes the model, and serves the API endpoint until interrupted. ```APIDOC ## main(argv: list[str] | None = None) -> int ### Description Starts the JevK5 HTTP server. This function parses command-line arguments, initializes the model, and serves the API endpoint until interrupted. ### Parameters - `argv` (list[str] | None) - Optional - Command-line arguments; defaults to `None` which uses `sys.argv[1:]`. ### Returns - `int` - Always returns `0` (never reached in practice because `serve_forever()` blocks). ### CLI Flags - `--model` (str) - Default: `"alibiserikbay/JevK5"` - Model source passed to `JevK5(source)`. - `--host` (str) - Default: `"127.0.0.1"` - Bind address. - `--port` (int) - Default: `8090` - Bind port. ### Example ```bash jevk5-serve --model alibiserikbay/JevK5 --host 0.0.0.0 --port 8090 ``` ``` -------------------------------- ### Run JevK5 as a server and query it Source: https://github.com/allebee/jevk5/blob/main/README.md Start the JevK5 server with jevk5-serve and send a request to the /v1/systemone endpoint. The curl command posts a state string and a question object with a 'choice' type and a list of criteria. The server listens on port 8090 by default. ```bash jevk5-serve --model alibiserikbay/JevK5 --port 8090 curl -s localhost:8090/v1/systemone -d '{"state": "Order #7120 shows delivered to No. 17; the customer lives at No. 71.", "questions": {"what": {"type": "choice", "instructions": "What happened to the parcel?", "criteria": ["delivered", "misdelivered", "unknown"]}}}' ``` -------------------------------- ### Environment variable usage examples Source: https://github.com/allebee/jevk5 Shows how to set JEVK5_GRAPHS=0 to disable CUDA-graph capture, and JEVK5_LITE_DTYPE/JEVK5_LITE_THREADS for the JevBench adapter. The second command runs the JevBench CLI with CPU-only execution. ```bash JEVK5_GRAPHS=0 python -c "from jevk5 import JevK5; JevK5('alibiserikbay/JevK5', graphs=True)" # no graphs ``` ```bash JEVK5_LITE_DTYPE=bf16 JEVK5_LITE_THREADS=16 CUDA_VISIBLE_DEVICES= python -m jevbench.cli run ... ``` -------------------------------- ### Rerun JevBench for JevK5-Lite Source: https://github.com/allebee/jevk5/blob/main/README.md Rerun the JevBench results for JevK5-Lite. This installs the package, copies the adapter into JevBench, applies the registration patch, and runs the benchmark with bf16 and 16 threads. The revision is the preview-1 tag; JEVK5_LITE_DTYPE defaults to fp32, which works on any CPU, while bf16 requires AMX or AVX512-BF16. ```bash pip install "jevk5[lite] @ git+https://github.com/allebee/jevk5@v0.3.2" cp bench/jevk5_lite.py /jevbench/adapters/ cd && git apply /bench/jevbench-registration.patch # registers jevk5_direct and jevk5_lite JEVK5_LITE_DTYPE=bf16 JEVK5_LITE_THREADS=16 CUDA_VISIBLE_DEVICES= python -m jevbench.cli run --adapter jevk5_lite \ --endpoint alibiserikbay/JevK5-Lite --revision 315ee211f828a899161477c534cea23e84ba3568 \ --model jevk5-lite-preview1 --tasks --results ... ``` -------------------------------- ### Load JevK5 and call decide() Source: https://github.com/allebee/jevk5/blob/main/README.md Load a JevK5 model and call decide() with a state string and a question object. The example uses the 'noul' question type (yes/no) and shows the returned dictionary structure. The commented line shows loading the larger JevK5-9B model, which uses about 19 GB of GPU memory in bf16. ```python from jevk5 import JevK5 model = JevK5("alibiserikbay/JevK5") # v0.3, ~9 GB of GPU memory in bf16 # model = JevK5("alibiserikbay/JevK5-9B") # ~19 GB model.decide( "Refunds need a receipt and a purchase within 30 days. " "The customer bought 12 days ago and has no receipt.", {"type": "noul", "instructions": "Is a refund permitted under the policy?"}, ) # {'type': 'noul', 'confidence': ..., 'noul': , 'input_tokens': ...} ``` -------------------------------- ### Classify text with JevK5Lite Source: https://github.com/allebee/jevk5/blob/main/README.md Load the JevK5-Lite model and classify a text with multiple label sets in one pass. The example shows a single-label head (intent) and a multi-label head (areas) with the multi_label flag. ```python from jevk5 import JevK5Lite lite = JevK5Lite.from_pretrained("alibiserikbay/JevK5-Lite", threads=16) lite.classify("I was charged twice, please refund one of them.", {"intent": ["refund_request", "order_status"], "areas": {"labels": ["billing", "shipping", "account"], "multi_label": True}}) ``` -------------------------------- ### Use JevK5 Python API to make a decision Source: https://github.com/allebee/jevk5/blob/main/MODEL_CARD.md Instantiate the JevK5 model and call decide() with a user message and a choice-type prompt. The example shows a billing decision with criteria and returns a choice with confidence and probabilities. ```python from jevk5 import JevK5 model = JevK5("alibiserikbay/JevK5") model.decide( "I was billed twice for order #4411. Please refund the duplicate charge today.", {"type": "choice", "instructions": "Which team should handle this?", "criteria": {"billing": "Payments and refunds", "tech": "Bugs", "sales": "New purchases"}}, ) # {'type': 'choice', 'choice': 'billing', 'confidence': 0.996, 'probabilities': {...}, ...} ``` -------------------------------- ### Run llama-server with JevK5 GGUF model Source: https://github.com/allebee/jevk5 Starts llama-server with the JevK5 GGUF model from Hugging Face, using 8192 context and 99 GPU layers. Requires a server new enough to load Qwen3.5 hybrid layers (checked at llama.cpp commit 9575389); converting a checkpoint requires --no-mtp in convert_hf_to_gguf.py. ```bash llama-server --hf-repo alibiserikbay/JevK5-GGUF --hf-file jevk5-4b-v0.3-Q8_0.gguf -c 8192 -ngl 99 ``` -------------------------------- ### curl request to /v1/systemone Source: https://github.com/allebee/jevk5 Example HTTP request to the server endpoint. Sends a state and a question with type 'noul' and instructions. ```bash curl -s localhost:8090/v1/systemone -d '{"state": "I was billed twice, please refund", "questions": {"refund": {"type": "noul", "instructions": "Asks for money back?"}}}' ``` -------------------------------- ### Error handling and wide questions example Source: https://github.com/allebee/jevk5 Shows advanced usage: enabling graphs, setting method to 'knockout' (or 'tree'), overriding temperature and knockout_temperature, and handling a ValueError for an invalid method. Also demonstrates probabilities with 77 options, which are processed in groups of <=16 plus a final pass combined by spread(). ```python from jevk5 import JevK5 from jevk5.prompt import METHODS model = JevK5( "alibiserikbay/JevK5", graphs=True, method="knockout", # or "tree" for the unfitted comparison readout temperature=1.22, # override jevk5_config.json knockout_temperature=0.93, # sharpens the >16-option combination ) try: JevK5(method="vote") # not in METHODS except ValueError as e: print(e) # "unknown method 'vote'; use one of ('knockout', 'tree')" # 77 options: groups of <=16 plus a final pass, combined by spread() probs, tokens = model.probabilities("play some jazz", {"type": "choice", "instructions": "Classify the banking intent.", "criteria": [f"intent {i}" for i in range(77)]}) print(len(probs), tokens, model.last_pass_tokens) ``` -------------------------------- ### POST /v1/systemone 200 OK response Source: https://github.com/allebee/jevk5 Example JSON response for a successful POST /v1/systemone request. Contains `model`, `answers`, `usage` (with `output_tokens` always 0), and `latency_ms` rounded to 2 decimals. ```json { "model": "alibiserikbay/JevK5", "answers": { "what": {"type": "choice", "confidence": 0.87, "choice": "misdelivered", "probabilities": {"delivered": 0.05, "misdelivered": 0.87, "unknown": 0.08}, "input_tokens": 61}, "refund": {"type": "noul", "confidence": 0.99, "noul": 0.99, "input_tokens": 54} }, "usage": {"input_tokens": 115, "output_tokens": 0}, "latency_ms": 20.6 } ``` -------------------------------- ### curl example for POST /v1/systemone Source: https://github.com/allebee/jevk5 Shell command to call the endpoint with curl. Sends a JSON body with a `state` and a `questions` dict; the server returns JSON. No authentication or TLS is used. ```bash curl -s localhost:8090/v1/systemone -d '{"state": "I was billed twice, please refund the duplicate.", "questions": {"refund": {"type": "noul", "instructions": "Does the customer ask for money back?"}}}' ``` -------------------------------- ### Python urllib example for POST /v1/systemone Source: https://github.com/allebee/jevk5 Python script using urllib to send a POST request to the endpoint and print the answer choice and latency. Requires the server running on 127.0.0.1:8090. ```python import json import urllib.request body = json.dumps({ "state": "Order #7120 shows delivered to No. 17; the customer lives at No. 71.", "questions": {"what": {"type": "choice", "instructions": "What happened to the parcel?", "criteria": ["delivered", "misdelivered", "unknown"]}}, }).encode() req = urllib.request.Request("http://127.0.0.1:8090/v1/systemone", data=body, headers={"Content-Type": "application/json"}) resp = json.loads(urllib.request.urlopen(req).read()) print(resp["answers"]["what"]["choice"], resp["latency_ms"]) ``` -------------------------------- ### probabilities usage example Source: https://github.com/allebee/jevk5 Calls probabilities with a choice question and asserts that the returned probabilities sum to 1.0. The question must be a typed dict with type, instructions, and criteria. ```python probs, tokens = model.probabilities("Order 7 arrived broken.", {"type": "choice", "instructions": "What should the agent do?", "criteria": ["give refund", "send replacement", "escalate"]}) assert sum(probs.values()) == 1.0 ``` -------------------------------- ### decide usage example Source: https://github.com/allebee/jevk5 Creates a JevK5 model and calls decide with a choice question, then prints the choice, confidence, and input_tokens from the result. The question uses a criteria dict mapping option ids to descriptions. ```python from jevk5 import JevK5 model = JevK5("alibiserikbay/JevK5") result = model.decide( "The camera has a scratch on the lens; return window closed 3 days ago.", {"type": "choice", "instructions": "Pick the best offer for the customer.", "criteria": {"discount20": "20% discount", "full_refund": "Full refund", "store_credit": "Store credit"}}, ) print(result["choice"], result["confidence"], result["input_tokens"]) ``` -------------------------------- ### Error handling and wide questions with probabilities Source: https://github.com/allebee/jevk5 Demonstrates error handling for invalid method values and handling questions with more than 16 options. Uses a custom URL, top_k=40 to cover the 16 letters, and a timeout of 600 seconds. The example shows a ValueError for method='vote' and warns when letters fall outside top_k. ```python from jevk5 import JevK5GGUF model = JevK5GGUF( url="http://127.0.0.1:8080", top_k=40, # must cover the 16 letters timeout_s=600.0, method="knockout", knockout_temperature=0.93, ) try: JevK5GGUF(method="vote") except ValueError as e: print(e) # "unknown method 'vote'; ..." # 77 intents, 6 passes: 5 groups + 1 final probs, tokens = model.probabilities( "where is my card?", {"type": "choice", "instructions": "Classify the banking intent.", "criteria": [f"intent {i}" for i in range(77)]}, ) if model.missing: print("warn: letters fell outside top_k on", model.missing, "passes") print(len(probs), tokens, model.last_seconds) ``` -------------------------------- ### Run teacher.py to generate training and test question sets Source: https://github.com/allebee/jevk5/blob/main/training/README.md Generate teacher hard-decision questions for the training and test splits. The first command writes 3000 training documents with 96 parallel workers; the second writes 150 test documents using the --split test flag, which uses three domains the train split never sees, and sets a seed for reproducibility. ```bash python teacher.py --out data/teacher/train.jsonl --docs 3000 --parallel 96 ``` ```bash python teacher.py --out data/teacher/test.jsonl --split test --seed 1 --docs 150 ``` -------------------------------- ### GET /health Source: https://github.com/allebee/jevk5 Liveness check that returns the model name. ```APIDOC ## [GET] /health ### Description Liveness + model name. ### Method GET ### Endpoint /health ### Response #### Success Response (200) - **model** (str) - The model name. ### Error Responses | Status | Body | Condition | |---|---|---| | 404 | {"error": "not found"} | Path is not /v1/systemone (POST) or /health (GET). | ``` -------------------------------- ### main(argv: list[str] | None = None) -> int Source: https://github.com/allebee/jevk5 Entry point for the GGUF module, runnable as `python -m jevk5.gguf [url]`. It creates a JevK5GGUF instance with the provided server URL and prints a hard-coded decision. ```APIDOC ## main(argv: list[str] | None = None) -> int ### Description Entry point for the GGUF module, runnable as `python -m jevk5.gguf [url]`. It creates a JevK5GGUF instance with the provided server URL and prints a hard-coded decision. ### Parameters - `argv` (list[str] | None) - Optional - `None` → `sys.argv[1:]`; first element is the server URL. ### Returns - `int` - Always returns `0`. ### Example ```bash python -m jevk5.gguf http://127.0.0.1:8080 ``` ``` -------------------------------- ### curl GET /health Source: https://github.com/allebee/jevk5 Check server health. Returns JSON with `ok` always true and `model` set to the model name passed to `make_handler` (`--model`). ```bash curl -s localhost:8090/health # {"ok": true, "model": "alibiserikbay/JevK5"} ``` -------------------------------- ### Load JevK5 v0.2 from a local snapshot Source: https://github.com/allebee/jevk5/blob/main/MODEL_CARD.md Downloads the v0.2 tagged revision of the model and passes the local path to JevK5. Use this for v0.2. ```python from huggingface_hub import snapshot_download model = JevK5(snapshot_download("alibiserikbay/JevK5", revision="v0.2")) ``` -------------------------------- ### _config static helper Source: https://github.com/allebee/jevk5 Returns the jevk5_config.json passed as config; without one, the temperature is v0.2's. _config(None) returns {}; a readable file is parsed and given setdefault("temperature", 1.0). ```python @staticmethod def _config(config: str | None) -> dict: """The jevk5_config.json passed as `config`; without one, the temperature is v0.2's.""" ``` -------------------------------- ### main function with CLI argument parsing Source: https://github.com/allebee/jevk5 Entry point for the server. Parses CLI flags (--model, --host, --port) with defaults, creates a JevK5 model and a ThreadingHTTPServer, then serves forever. Returns 0 but never reaches it because serve_forever() blocks. ```python def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("--model", default="alibiserikbay/JevK5") parser.add_argument("--host", default="127.0.0.1") parser.add_argument("--port", type=int, default=8090) args = parser.parse_args(argv) model = JevK5(args.model) server = ThreadingHTTPServer((args.host, args.port), make_handler(model, args.model)) print(f"serving {args.model} on http://{args.host}:{args.port}/v1/systemone", flush=True) server.serve_forever() return 0 ``` -------------------------------- ### GET /health Source: https://github.com/allebee/jevk5 Health check endpoint that returns server status and model information. It always returns ok=true if the server is reachable, along with the model name configured via --model. ```APIDOC ## [GET] /health ### Description Health check endpoint that returns server status and model information. It always returns ok=true if the server is reachable, along with the model name configured via --model. ### Method GET ### Endpoint /health ### Response #### Success Response (200) - **ok** (bool) - Always `true` (any reachable response implies the server is up). - **model** (str) - The model name passed to `make_handler` (`--model`). #### Response Example ```bash curl -s localhost:8090/health # {"ok": true, "model": "alibiserikbay/JevK5"} ``` ``` -------------------------------- ### classify usage example Source: https://github.com/allebee/jevk5 Shows how to load JevK5Lite and classify text with both single-label and multi-label tasks. The output for intent is exactly one label, while areas returns zero or more labels at/above the threshold. ```python from jevk5 import JevK5Lite lite = JevK5Lite.from_pretrained("alibiserikbay/JevK5-Lite", threads=16) out = lite.classify( "I was charged twice for the same order, please refund one of them.", {"intent": ["refund_request", "order_status", "cancel_subscription"], "areas": {"labels": ["billing", "shipping", "account"], "multi_label": True}}, ) print(out["intent"]["labels"]) # exactly one label print(out["areas"]["labels"]) # zero or more labels at/above the threshold ``` -------------------------------- ### Run Tetris experiment with JevK5 Source: https://github.com/allebee/jevk5/blob/main/examples/README.md Commands to run the Tetris experiment with different players: 'briefed' (judging outcomes), 'model' (reading the board), and 'random' or 'greedy' baselines. The '--show' flag displays the board for the model player. ```bash cd examples python tetris.py --player briefed --model alibiserikbay/JevK5 --games 10 python tetris.py --player model --model alibiserikbay/JevK5 --games 10 --show python tetris.py --player random --games 20 # and --player greedy ``` -------------------------------- ### Run JevK5 GGUF module from command line Source: https://github.com/allebee/jevk5 Command to execute the module with a server URL. The URL is passed as the first argument to `main`; if omitted, it defaults to `http://127.0.0.1:8080`. ```bash python -m jevk5.gguf http://127.0.0.1:8080 ``` -------------------------------- ### Use JevK5GGUF to decide on a parcel scenario Source: https://github.com/allebee/jevk5/blob/main/README.md Uses the JevK5GGUF class to create a model with the temperature and knockout_temperature values from the table for the 4B v0.3 Q8_0 file. Calls decide() with a sample order scenario and a choice-type prompt with three criteria. ```python from jevk5 import JevK5GGUF model = JevK5GGUF(temperature=1.22, knockout_temperature=0.93) # the file's values (table) model.decide("Order #7120 shows delivered to No. 17; the customer lives at No. 71.", {"type": "choice", "instructions": "What happened to the parcel?", "criteria": ["delivered", "misdelivered", "unknown"]}) ``` -------------------------------- ### _temperature static helper Source: https://github.com/allebee/jevk5 Returns the calibration temperature from the config file, defaulting to 1.532 if not present. ```python @staticmethod def _temperature(config: str | None) -> float: return float(JevK5GGUF._config(config).get("temperature", 1.532)) ``` -------------------------------- ### Board state after 40 pieces Source: https://github.com/allebee/jevk5/blob/main/examples/README.md Example board state after 40 pieces in a game where JevK5 judged outcomes, showing 13 lines cleared and 4 cells buried. The board is drawn with '#' for filled cells and '.' for empty cells, with column indices below. ```text |..........| |..######..| |.##.#.####| |.#########| |#####..###| +----------+ 0123456789 ``` -------------------------------- ### main function for JevK5GGUF CLI Source: https://github.com/allebee/jevk5 Entry point for the module, runnable as `python -m jevk5.gguf [url]`. Accepts an optional URL argument (defaults to `http://127.0.0.1:8080`), creates a `JevK5GGUF` instance, and prints a hard-coded `noul` decision. Returns `0`; not registered as a console script. ```python def main(argv: list[str] | None = None) -> int: argv = sys.argv[1:] if argv is None else argv model = JevK5GGUF(argv[0] if argv else "http://127.0.0.1:8080") print( model.decide( "Refunds need a receipt and a purchase within 30 days. The customer bought 12 days " "ago and has no receipt.", {"type": "noul", "instructions": "Is a refund permitted under the policy?"}, ) ) return 0 ``` -------------------------------- ### Using make_handler with ThreadingHTTPServer Source: https://github.com/allebee/jevk5 Shows how to create a ThreadingHTTPServer with the handler returned by make_handler and serve forever. The model is loaded from 'alibiserikbay/JevK5' and the server listens on 0.0.0.0:8090. ```python from http.server import ThreadingHTTPServer from jevk5 import JevK5 from jevk5.server import make_handler model = JevK5("alibiserikbay/JevK5") server = ThreadingHTTPServer(("0.0.0.0", 8090), make_handler(model, "alibiserikbay/JevK5")) server.serve_forever() ``` -------------------------------- ### normalized usage example with error handling Source: https://github.com/allebee/jevk5 Shows how to call normalized with a valid choice question and how to catch the ValueError for an unknown type. The valid call returns a dict with criteria as a dict mapping each option to None. The error message prints "unknown question type 'vote'". ```python from jevk5.server import normalized q = normalized({"type": "choice", "instructions": "What happened?", "criteria": ["delivered", "misdelivered"]}) assert q["criteria"] == {"delivered": None, "misdelivered": None} try: normalized({"type": "vote", "instructions": "x"}) except ValueError as e: print(e) # "unknown question type 'vote'" ``` -------------------------------- ### JevK5GGUF constructor Source: https://github.com/allebee/jevk5 Creates a read-only client for a running llama-server serving a JevK5 GGUF. Configures the server URL, calibration temperature, top-k, timeout, and wide-question readout method. ```APIDOC ## JevK5GGUF constructor ### Description Creates a read-only client for a running llama-server serving a JevK5 GGUF. Configures the server URL, calibration temperature, top-k, timeout, and wide-question readout method. ### Method Constructor ### Endpoint `JevK5GGUF(url, temperature, top_k, timeout_s, config, method, knockout_temperature)` ### Parameters #### Constructor Parameters - **url** (str) - Optional - Base URL of the running `llama-server` (default port). Trailing slashes are stripped. Default: `"http://127.0.0.1:8080"` - **temperature** (float | None) - Optional - Calibration temperature. `None` → `temperature` from the `config` file, else `1.532` (JevK5 v0.2's value). Per-file values: 1.367 for v0.3 4B, 1.089 for JevK5-9B, 1.42 for JevK5-2B. Default: `None` - **top_k** (int) - Optional - How many token log-probabilities to request at the answer position; must cover the 16 letters. Default: `40` - **timeout_s** (float) - Optional - HTTP timeout for each request to `llama-server`. Default: `600.0` - **config** (str | None) - Optional - Path to a local `jevk5_config.json` holding `temperature` / `knockout_temperature`. Without one, `temperature` falls back to `1.532`. Default: `None` - **method** (str) - Optional - Wide-question readout: `"knockout"` or `"tree"`, exactly as the CUDA runtime. Must be in `METHODS`, else `ValueError`. Default: `"knockout"` - **knockout_temperature** (float | None) - Optional - Sharpening temperature for wide questions. `None` → config's `knockout_temperature`, else `prompt.TEMPERATURES` applies at read time. Default: `None` ### Response #### Success Response Returns a `JevK5GGUF` instance. ### Public Instance Attributes - **method** (str) - `"knockout"` or `"tree"`. - **url** (str) - Server base URL with trailing slash stripped. - **top_k** (int) - Requested log-probability count. - **timeout_s** (float) - HTTP timeout. - **temperature** (float) - Calibration temperature in effect. - **knockout_temperature** (float | None) - Second temperature for wide questions, or `None`. - **missing** (int) - Counter of decisions where at least one option letter fell outside the returned top-k. - **last_pass_tokens** (int) - Set by `probabilities()`: longest single-pass token count. - **last_seconds** (float) - Set by `probabilities()`: summed `prompt_ms + predicted_ms` over all passes from the server's `timings`. ``` -------------------------------- ### JevK5 constructor Source: https://github.com/allebee/jevk5 Initializes the JevK5 runtime, loading the model, tokenizer, and optionally capturing CUDA graphs. It validates the method and encodes answer letters. ```APIDOC ## JevK5.__init__ ### Description Initializes the JevK5 runtime, loading the model, tokenizer, and optionally capturing CUDA graphs. It validates the method and encodes answer letters. ### Method Constructor ### Signature ```python JevK5( source: str = "alibiserikbay/JevK5", device: str = "cuda", dtype=torch.bfloat16, graphs: bool = True, temperature: float | None = None, method: str = "knockout", knockout_temperature: float | None = None, ) -> None ``` ### Parameters - `source` (str) - Optional - Model identifier: a Hugging Face repo id (e.g. `alibiserikbay/JevK5`, `alibiserikbay/JevK5-9B`) or a local folder. A local copy of a Hub tag (e.g. `snapshot_download("alibiserikbay/JevK5", revision="v0.2")`) keeps the old weights available. - `device` (str) - Optional - Torch device string for the `device_map`. - `dtype` (torch.dtype) - Optional - Model dtype (used as `dtype=dtype` in `from_pretrained`). - `graphs` (bool) - Optional - Whether to capture CUDA graphs at construction (also honors env `JEVK5_GRAPHS`). - `temperature` (float | None) - Optional - Calibration temperature for the letter logits. `None` → `temperature` from `jevk5_config.json` next to the weights, else `1.0`. - `method` (str) - Optional - How questions with more than 16 options are read: `"knockout"` or `"tree"`. Up to 16 options take one pass either way. - `knockout_temperature` (float | None) - Optional - Sharpening temperature for the combined distribution of wide questions. `None` → `knockout_temperature` from `jevk5_config.json`, else `prompt.TEMPERATURES` applies at read time. ### Behavior 1. `method` must be in `METHODS` (`("knockout", "tree")`), else `ValueError`. 2. Loads `AutoConfig`, `AutoTokenizer`, and the causal LM; for `model_type` in `{"qwen3_5", "qwen3_5_text"}` it switches to `transformers.Qwen3_5ForCausalLM` and the text config. 3. Encodes each letter of `LETTERS`; every letter must be exactly one token, else `ValueError` ("Every answer letter must be one token"). The resulting token ids are stored in `self.slots` and the matching `lm_head.weight` rows in `self.slot_weight`. 4. Resolves `temperature` and `knockout_temperature`. 5. If `graphs` is truthy and `JEVK5_GRAPHS` env is not `"0"`, calls `self.capture()`. ### Public Instance Attributes - `method` (str) - `"knockout"` or `"tree"`. - `tok` (tokenizer) - The loaded `AutoTokenizer`. - `model` (nn.Module) - The loaded causal LM in eval mode. - `device` (str) - Device string passed to the constructor. - `slots` (list[int]) - Token id of each answer letter (`LETTERS[i]` → token id). - `slot_weight` (torch.Tensor) - `self.model.lm_head.weight[self.slots]`, detached and contiguous. - `temperature` (float) - Calibration temperature in effect. - `knockout_temperature` (float | None) - Second-temperature for wide questions, or `None` (falls back to `prompt.TEMPERATURES`). - `graphs` (dict[int, tuple]) - `{length: (graph, static_ids, last, out)}` populated by `capture()`. Empty when graphs are off or CUDA is unavailable. - `last_pass_tokens` (int) - Set by `probabilities()`: the longest single pass's token count (constructor sets it only implicitly via `probabilities`). ``` -------------------------------- ### Using decide with JevK5GGUF Source: https://github.com/allebee/jevk5 Shows how to call decide on a JevK5GGUF instance with temperature 1.22 and knockout_temperature 0.93. The question is a noul type asking for a yes/no decision. ```python from jevk5 import JevK5GGUF model = JevK5GGUF(temperature=1.22, knockout_temperature=0.93) out = model.decide( "I was billed twice for order #12.", {"type": "noul", "instructions": "Does the customer ask for money back?"}, ) print(out) ``` -------------------------------- ### spread(read: Reader, texts: list[str], method: str = "knockout", temperature: float | None = None) -> list[float] Source: https://github.com/allebee/jevk5 Computes a probability distribution over all options using a reader that handles at most 16 options per pass. Supports knockout and tree methods for scaling beyond 16 options. ```APIDOC ## spread(read: Reader, texts: list[str], method: str = "knockout", temperature: float | None = None) -> list[float] ### Description A probability for every option, from a reader that answers at most 16 lettered options. ### Parameters - `read` (Reader) - Required - One-pass reader: `list[str]` (≤16 texts) → `Sequence[float]` distribution. - `texts` (list[str]) - Required - All option texts, in order. - `method` (str) - Optional - `"knockout"` or `"tree"`; must be in `METHODS`, else `ValueError`. Default: `"knockout"`. - `temperature` (float | None) - Optional - Sharpening exponent `q^(1/t)` over the combined distribution; `None` → `TEMPERATURES[method]`. `1.0` = no sharpening. Default: `None`. ### Returns `list[float]` of length `len(texts)`, summing to 1.0, in the input order. ### Example ```python from jevk5.prompt import spread def read(texts: list[str]) -> list[float]: logits = [strength[t] for t in texts] # any one-pass scorer return [x / sum(logits) for x in logits] probs = spread(read, [f"intent {i}" for i in range(77)], method="knockout") assert len(probs) == 77 and abs(sum(probs) - 1.0) < 1e-12 ``` ### Error Handling Example ```python from jevk5.prompt import spread texts = [f"intent {i}" for i in range(20)] strength = {t: 1.0 for t in texts} def read(given: list[str]) -> list[float]: w = [strength[t] for t in given] return [x / sum(w) for x in w] try: spread(read, texts, method="vote") except ValueError as e: print(e) # "unknown method 'vote'; use one of ('knockout', 'tree')" tree = spread(read, texts, method="tree", temperature=1.0) # unsharpened tree comparison ``` ``` -------------------------------- ### JevK5GGUF class constructor Source: https://github.com/allebee/jevk5 Constructor for the read-only llama.cpp client. Parameters include url, temperature, top_k, timeout_s, config, method, and knockout_temperature. method must be in METHODS, else ValueError. ```python class JevK5GGUF: def __init__( self, url: str = "http://127.0.0.1:8080", temperature: float | None = None, top_k: int = 40, timeout_s: float = 600.0, config: str | None = None, method: str = "knockout", knockout_temperature: float | None = None, ) -> None: ``` -------------------------------- ### Constants for prompt building Source: https://github.com/allebee/jevk5 Defines the constants used across the prompt layer: answer letters, valid methods, default temperatures, the fixed system message, and the pinned chat template. The chat template is verified to be token-identical to the transformers one. ```python LETTERS = "ABCDEFGHIJKLMNOP" METHODS = ("knockout", "tree") TEMPERATURES = {"knockout": 0.77, "tree": 1.0} SYSTEM = ( "Apply the supplied criterion to the supplied evidence. Choose exactly one listed option. " "Respond with only its uppercase letter, with no explanation or reasoning." ) CHAT_TEMPLATE = ( "<|im_start|>system\n{system}<|im_end|>\n" "<|im_start|>user\n{user}<|im_end|>\n" "<|im_start|>assistant\n thinking\n\n response\n\n" ) ``` -------------------------------- ### jevk5-serve CLI command Source: https://github.com/allebee/jevk5 Command-line invocation of the server, equivalent to running main() with flags. Overrides default model, host, and port. ```bash jevk5-serve --model alibiserikbay/JevK5 --host 0.0.0.0 --port 8090 ``` -------------------------------- ### Basic usage of JevK5Lite.from_pretrained Source: https://github.com/allebee/jevk5 Loads the JevK5Lite model from the Hub with 16 threads and prints configuration values. ```python from jevk5 import JevK5Lite lite = JevK5Lite.from_pretrained("alibiserikbay/JevK5-Lite", threads=16) print(lite.max_len, lite.temperature_single, lite.temperature_multi) ```