Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions unsloth/chat_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2682,16 +2682,15 @@ def test_hf_gguf_equivalence(tokenizer, gguf_model = "./model-unsloth.F16.gguf")

if tokenizer.chat_template is not None:
prompt = tokenizer.apply_chat_template(messages, tokenize = False, add_generation_prompt = True)
prompt = prompt.replace("'", "") # Subprocess does not like ''
prompt = remove_special_tokens(tokenizer, prompt)
Comment on lines 2684 to 2685
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore apostrophe normalization for GGUF comparison

This change stops removing ' from chat-template prompts, but test_hf_gguf_equivalence still parses llama-cli output with re.findall(r"([\d]{1,}) \-\> \'([^\']{1,})\'", gguf_tokens), which cannot capture tokens that contain apostrophes. With the current default messages (e.g., It's, I'm), those GGUF tokens are skipped, gguf_tokenized becomes misaligned, and the HF vs GGUF check can fail even when tokenization is actually correct.

Useful? React with 👍 / 👎.

prompts.append(prompt)

for prompt in prompts:
command = f"./llama.cpp/llama-cli -m {gguf_model} -n 0 --temp 0.0 --verbose-prompt "\
f"--check-tensors -p '{prompt}'"
command = ["./llama.cpp/llama-cli", "-m", gguf_model, "-n", "0", "--temp", "0.0", "--verbose-prompt",
"--check-tensors", "-p", prompt]

datas = []
with subprocess.Popen(command, shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, bufsize = 1) as sp:
with subprocess.Popen(command, shell = False, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, bufsize = 1) as sp:
for line in sp.stdout:
datas.append(line.decode("utf-8", errors = "replace"))
gguf_tokens = "".join(datas)
Expand Down