Repository navigation
Conversation
…o the engine json.dumps defaults to ensure_ascii=True, which rewrites every non-ASCII character as \uXXXX. The engine's messages/chat-template path does not decode these escapes, so the model receives literal escape text: ~3 tokens per character and semantic noise. Accented Latin degrades, Japanese/Korean become unusable. With ensure_ascii=False, prompt_tokens exceed the HF tokenizer by a constant template offset in all tested languages (en/fr/ja/ko), and an 808-row multilingual tool-calling eval returns to the bf16 reference. Fixes cactus-compute#803 Signed-off-by: Rasaboun <40967731+Rasaboun@users.noreply.github.com>
Rasaboun
force-pushed
the
fix/python-binding-ensure-ascii
branch
from
September 2, 2026 08:27
45bc96d to
c1b4550
Compare
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.
Fixes #803.
What
One-line change in
python/cactus/bindings/cactus.py::_to_json:json.dumps(obj, ensure_ascii=False).Why
json.dumpsdefaults toensure_ascii=True, rewriting every non-ASCII character as\uXXXX. The engine's messages/chat-template path does not decode those escapes, so the model literally receives escape text (~3 tokens per character, semantic noise). Accented Latin degrades; Japanese/Korean become unusable. Full evidence in #803.Verification (Python-side change only, no C++ touched)
usage.prompt_tokensvs the HF tokenizer for identical messages+tools, before → after:en +42 → +42, fr +58 → +42, ko +87 → +42, ja +124 → +44 (the constant +42 is template overhead).
rememberaccuracy 17% → 94%; en/de unchanged..encode()unchanged);ensure_ascii=Falseonly stops the escaping.Complementary hardening (not in this PR, kept lean per CONTRIBUTING): have the C++ messages JSON reader decode
\uXXXXso non-Python bindings that escape are also safe —utils.halready has a correct decoder used elsewhere.