Repository navigation
basal-export-gguf: GGUF z tokenizerem jak w plikach -GGUF (konwersja i naprawa) - #8
Conversation
…n metadata Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideIntroduces Sequence diagram for native basal decisions in OllamasequenceDiagram
actor Client
participant Ollama
participant BasalEncoder
participant Model
Client->>Ollama: POST /v1/systemone
Ollama->>BasalEncoder: Encode state and questions
BasalEncoder->>BasalEncoder: Render basal prompt
BasalEncoder->>Model: Score first option order
BasalEncoder->>Model: Score reversed option order
BasalEncoder->>BasalEncoder: Average orders and apply calibrated temperature
BasalEncoder-->>Ollama: Typed decision probabilities
Ollama-->>Client: Decision response
Flow diagram for basal GGUF export and tokenizer correctionflowchart LR
Model[Hugging Face basal model] --> Export[basal-export-gguf]
Export --> Converter[llama.cpp convert_hf_to_gguf.py]
Converter --> Raw[Raw GGUF]
Raw --> Fix[fix_gguf]
Tokenizer[tokenizer.json BPE merges and added_tokens] --> Fix
Calibration[CALIBRATION.json] --> Decision{--ollama-decision}
Decision --> Fix
Fix --> GGUF[Corrected GGUF]
GGUF --> Tokenization[HF-compatible tokenization]
GGUF --> OllamaMetadata[Optional basal decision metadata]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 security issue, and 1 other issue
Security issues:
- Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="basal/gguf_export.py" line_range="117" />
<code_context>
+
+ model_dir = Path(a.model) if Path(a.model).exists() else Path(snapshot_download(a.model, revision=a.revision))
+ out = Path(a.outfile)
+ with tempfile.TemporaryDirectory(dir=out.parent) as tmp:
+ raw = Path(tmp) / "converted.gguf"
+ done = subprocess.run([sys.executable, str(converter), str(model_dir), "--outtype", a.outtype, "--outfile", str(raw)])
</code_context>
<issue_to_address>
**nitpick (bug_risk):** `TemporaryDirectory(dir=out.parent)` raises `FileNotFoundError` when the requested output is in a new directory, such as `exports/model.gguf`, because the command never creates `out.parent`. The export therefore fails even though the output path is otherwise valid.
**Triggers:** When the output path contains a directory that does not already exist.
**Suggested fix:** Create `out.parent` with `mkdir(parents=True, exist_ok=True)` before creating the temporary directory, or use a temporary directory elsewhere and create the destination parent before writing.
```suggestion
out.parent.mkdir(parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(dir=out.parent) as tmp:
```
</issue_to_address>
### Comment 2
<location path="basal/gguf_export.py" line_range="119" />
<code_context>
done = subprocess.run([sys.executable, str(converter), str(model_dir), "--outtype", a.outtype, "--outfile", str(raw)])
</code_context>
<issue_to_address>
**security (python.lang.security.audit.dangerous-subprocess-use-audit):** Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.
*Source: opengrep*
</issue_to_address>|
Aktualizacja 9.10: stronę Pierwotny komentarz z 3.10 (basal-1.0, wersja natywna)W duchu Twojego komentarza w #5 wrzuciłem przetestowane i poprawione modele na Ollamę:
To są pliki z Ważne: wersja natywna wymaga Ollamy z enkoderem Jeśli wolisz wydawać basala na Ollamie sam, pod swoim kontem, daj znać. Usunę wtedy swoją stronę i przekażę wszystko, co trzeba. Możesz też po prostu sam przetestować: wystarczy zbudować Ollamę z gałęzi pdurlej/ollama@decision-basal-encoding. Jeszcze raz dzięki, kawał świetnej roboty. basal naprawdę dobrze działa na moich mieszanych polsko-angielskich zadaniach i będę go używał na co dzień. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Dzięki za review (bot): oba punkty przejrzane.
|
|
Jak coś jeszcze będzie szło poprawić dajcie znać :) |
README.md and docs/GGUF.md are taken from basal 1.5.0; the basal-export-gguf documentation is re-added on top of them in a later commit. pyproject.toml keeps the gguf-export extra and the basal-export-gguf script; uv.lock adds only gguf 0.19.0 to upstream's lockfile (uv lock --check passes). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ting file Token scores now follow the convention of the basal-1.5 -GGUF files: minus the 0-based rank of the first BPE merge producing the token, the added tokens of tokenizer.json keep their score, every other token scores 0. Tokenization is unchanged; the tokenizer fields now equal the -GGUF files' on all three 1.5 models, and fixing a -GGUF file leaves it byte-identical. --gguf FILE fixes an existing GGUF (a stock conversion, a llama-quantize output, an older basal GGUF) instead of running the converter; MODEL then only supplies tokenizer.json and CALIBRATION.json, downloaded without the weights. The output must differ from the input, a GGUF whose vocabulary differs from tokenizer.json is refused, and decision metadata of the input is dropped unless --ollama-decision is given. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…F docs docs/GGUF.md "Convert yourself" uses basal-export-gguf for conversions with the tokenizer fix of the -GGUF repositories and shows the --gguf repair of existing files (the basal-1.0 conversions it links carry the stock tokenizer). A new section describes the experimental Ollama /v1/systemone encoding for basal-1.5, its limitations and a table for the 1.5 measurements; the basal-1.0 numbers stay, labelled. PORTS.md and the README point to the tool. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The added tokens of tokenizer.json now get the converter's -1000 instead of keeping the input file's score, so fixing a file written by the earlier convention (every unranked token at -(1 + number of merges), as in the basal-1.0 Ollama files) gives the -GGUF files' scores. Stock conversions and the -GGUF files already carry -1000 there: fixing basal-1.5-mini-Q8_0.gguf still leaves it byte-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…an errors - The temperatures come from CALIBRATION.ollama.json when the model ships it, else CALIBRATION.json, as basal-serve --mode ollama chooses. - A model directory with config.json must describe the GGUF's model (layers, hidden size, vocabulary, the check of basal-serve --mode gguf); otherwise another model's temperatures would be written. The -GGUF folders have no config.json (their .gguf files belong to them), so the tool prints the calibration file, the model (basal.json) and the temperatures it wrote. --gguf now also downloads config.json, basal.json and CALIBRATION.ollama.json. - A model without tokenizer.json (e.g. a third-party GGUF repository), or without its calibration with --ollama-decision, gets a usage error naming the model instead of a traceback with a cache path. - The missing-gguf hint works outside a clone too: uv pip install "gguf>=0.19" (the gguf-export extra; -e ".[gguf-export]" from a clone). "basal" on PyPI is an unrelated package, so the hint does not name it. - --help works under python -OO. Tests: every decision temperature with its own value and the GGUF value types of the rewritten fields; the converter path with a stand-in converter on a local model folder (arguments, temporary file next to the output, no download). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…all from a clone - The endpoint ships in Ollama (since 0.35); only the basal encoding is proposed (ollama/ollama#18760). Ollama releases do not have it (0.40.2 answers "unsupported decision encoding"), and the supported route there is basal-serve --mode ollama with the -GGUF files as shipped. - The empty basal-1.5 table is removed; the basal-1.0 measurement is kept in two sentences (full table: docs/GGUF.md in e21e51a). - Evidence spans need the PyTorch engine, not --mode ollama. - --ollama-decision reads CALIBRATION.ollama.json when shipped. - basal-export-gguf is not in a release yet: install basal from a clone into the converter environment and call ~/gguf-env/bin/basal-export-gguf in every example. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lama schema notes - The --ollama-decision config check compares the model's shape only, and basal-1.0 and basal-1.5 models of one size share it: the message now says "config.json has the GGUF's shape (... layers, ... wide, ... tokens)" and the docstring names the limit; a config.json without num_hidden_layers or hidden_size is refused (as basal-serve --mode gguf does) instead of passing. - A directory as the output file is refused before any download or conversion. - Tests: the vocabulary length guard, a missing --gguf input, a directory as the output, the missing config key, and a conversion from a repo id downloading the whole model (no allow_patterns). - docs/GGUF.md: one bullet on Ollama's request and answer schema (criteria forms, no option_keys, state rendering, entropy-based confidence, noul answers without probabilities) replaces two narrower ones. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@rkinas zaktualizowałem PR pod basal 1.5 (opis wyżej jest nowy). W skrócie: Przy okazji: Twoje pliki 1.5 są też na https://ollama.com/pdurlej/basal do użycia z |
|
Dzięki, to brakujący publiczny element: docs/PORTS.md opisuje te trzy poprawki tokenizera, a narzędzia w repo nie było. Chcę to scalić w 2.0.x. Do zrobienia: (1) merge z main v2.0.0 (konflikty: README, docs/GGUF.md, pyproject.toml, uv.lock); (2) bez części o natywnej Ollamie, bo jak piszesz, nie działa na wydanej Ollamie; (3) sprawdzenie na 2.0: --gguf na plikach basal-2.0--GGUF daje te same bajty, a konwersja z HF odtwarza pola tokenizer.. Jeśli wolisz, rebase zrobię po naszej stronie. |
README.md and docs/GGUF.md are taken from basal 2.0.0; the basal-export-gguf documentation is re-added on top of them in a later commit. pyproject.toml keeps the gguf-export extra and the basal-export-gguf script; uv.lock adds only gguf 0.19.0 to upstream's lockfile (uv lock --check passes). Co-Authored-By: Claude Fable 5.1 <[email protected]>
The --ollama-decision flag and the <arch>.decision.* keys are removed: the encoding they were written for is not in any Ollama release. The tool now only converts (or, with --gguf, fixes) a GGUF so that its tokenizer fields equal the -GGUF repositories'; with --gguf the model supplies tokenizer.json only. Keys written by the earlier draft are still dropped from an input file. Checked on the basal-2.0 -GGUF files: fixing each of the six (mini, 4.5B, max; Q8_0, Q5_K_M) gives the same bytes; the fixed tokenizer fields of a stock conversion equal theirs on all three models (13 of 13 keys; stock: 10-11); a converter-mode Q8_0 of basal-2.0-mini has the same tokenizer fields and the same 515 tensors as the published file. docs/GGUF.md "Convert yourself" uses the tool with basal-2.0; the Ollama /v1/systemone section is gone; INSTALL.md and PORTS.md point to the tool. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
@rkinas zrobione po mojej stronie (opis PR-a jest nowy):
|
|
@rkinas mergujemy zanim main odjedzie jeszcze bardziej 🙏 ? |
|
Dzięki! Wszystko z listy z 14.10 zrobione; testy przechodzą także po scaleniu z obecnym main (519 + 16 testów basal-export-gguf). Scalam, wejdzie w basal 2.2.0 (poniedziałek 19.10) z podziękowaniem w notach wydania. |
|
Ok. I am merging it now. It will be in 2.2. Than you for your contribution. |
…lready locked) uv lock changes only basal's own version line; uv export of the default install and of every existing extra is identical to calib-2.2's lock; gguf-export adds gguf 0.19.0.
…cture models basal-omni (Gemma 4) is converted with llama.cpp's converter alone (Files); the tokenizer fix was checked on basal-1.0 / 1.5 / 2.0 only.
One line per external contributor whose commits are in main or in 2.2, with what they added and the PR: Paweł Kiszczak (#4), Piotr Durlej (#8), Kuba Sołtys (#15), Michał Kardyś (#14); names from their GitHub profiles and commit authors. README and WHATS_NEW 2.2 list basal-export-gguf, --mode tpu and --mode strix; NOTICE names the contributors.
|
Thank you, Piotr! What we added on top:
Your 16 tests pass on 2.2.0 (gguf 0.19.0), next to the full suite. If you'd like, we'd be glad to list you in CODEOWNERS for |
|
Dzięki za merge i za wpis w Contributors. CODEOWNERS: tak, wpisz mnie. Z jasnym zakresem: pilnuję tego od strony użytkownika końcowego Ollamy, czyli czy pliki po zmianie nadal wychodzą bajt w bajt jak Twoje Idąc za tym: biorę na siebie wydania basala na ollama.com. Pliki omni ( |
Narzędzie, które robi trzy poprawki tokenizera opisane w
docs/PORTS.md(„Tokenizer fix”), zaktualizowane pod basal 2.0.0:basal-export-gguf Remek/basal-2.0-4.5B out.gguf --outtype q8_0 --llama-cpp ~/llama.cpp) daje pola tokenizera bit w bit takie jak w plikach-GGUF;--ggufnaprawia istniejący GGUF bez ponownej konwersji: wynik stockowego konwertera,llama-quantizealbo starsze pliki (np. GGUF-y basal-1.0 Pawła, do których linkujedocs/GGUF.md). Z--ggufz repo pobierany jest tylkotokenizer.json.Bez części o natywnej Ollamie, zgodnie z Twoją uwagą.
Co jest w PR-ze
basal/gguf_export.py(CLIbasal-export-gguf, extragguf-export= pakietgguf). Ustawia: score tokenów z rang merge'y BPE w konwencji plików-GGUF(−ranga od 0; dodane tokeny −1000; reszta 0),add_space_prefix = false, dodane tokeny ztokenizer.jsonjako CONTROL / USER_DEFINED.tests/test_gguf_export.py: 16 testów na małym GGUF-ie (konwerter zastąpiony skryptem). Każda z poprawek cofnięta daje czerwony test.docs/GGUF.md„Convert yourself” z narzędziem i przykładem--gguf; po jednym zdaniu wdocs/INSTALL.mdidocs/PORTS.md.uv.lock: tylkogguf0.19.0 dopisane do Twojego locka (uv lock --check --no-configprzechodzi).main2.0.0 zwykłym merge'em.pytest -q tests: 516 passed, 15 skipped (MLX/GPU).Sprawdzenie na basal-2.0 (Apple M1 Max, llama.cpp b11146)
--ggufna Twoich 6 plikach 2.0 (mini, 4.5B, max × Q8_0, Q5_K_M)tokenizer.*basal-export-gguf Remek/basal-2.0-mini … --outtype q8_0vs Twójbasal-2.0-mini-Q8_0.ggufgeneral.*z karty modelu🤖 Generated with Claude Code