Skip to content

GLM-DSA: Fix token corruption due to incorrect RoPE type#2099

Merged
ikawrakow merged 1 commit into
ikawrakow:mainfrom
usrlocalben:fix-glm-output-errors
Jul 9, 2026
Merged

GLM-DSA: Fix token corruption due to incorrect RoPE type#2099
ikawrakow merged 1 commit into
ikawrakow:mainfrom
usrlocalben:fix-glm-output-errors

Conversation

@usrlocalben

Copy link
Copy Markdown
Contributor

The DSA lightning indexer hardcoded LLAMA_ROPE_TYPE_NEOX for indexer Q/K positional encoding, but the GLM-5.2 model config.json explicitly sets "indexer_rope_interleave": true, meaning the indexer uses interleaved RoPE (LLAMA_ROPE_TYPE_NORM).

GLM-5.1 config.json also sets "rope_interleave": true.

The mismatch caused incorrect indexer scores, wrong top-k key selection, giving single-character/token errors and other corruption that could grow worse with context length.

Here the setup is changed to use the model's given rope_type instead of hardcoding NEOX. This fixes GLM-5.2, GLM-5.1, and should be less brittle for future GLM variants.

Closes #2083

The DSA lightning indexer hardcoded LLAMA_ROPE_TYPE_NEOX for indexer Q/K
positional encoding, but the GLM-5.2 model config.json explicitly sets
"indexer_rope_interleave": true, meaning the indexer uses interleaved
RoPE (LLAMA_ROPE_TYPE_NORM).

GLM-5.1 config.json also sets "rope_interleave": true.

The mismatch caused incorrect indexer scores, wrong top-k key selection,
and single-character token errors and other corruption that could grow
worse with context length.

Here the setup is changed to use the model's given rope_type instead of
hardcoding NEOX. This fixes GLM-5.2, GLM-5.1, and should be less brittle
for future GLM variants.
@usrlocalben usrlocalben changed the title GLM-DSA: Fix token "corruption" due to incorrect RoPE type GLM-DSA: Fix token corruption due to incorrect RoPE type Jul 8, 2026
@Skelectric

Copy link
Copy Markdown

This fixed it for me, thanks!

@sayap sayap mentioned this pull request Jul 9, 2026
@sayap

sayap commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This fixed it for me as well, thanks!

The model is now fully coherent until the context limit is reached (I can only fit 100k), and with -dsa the TG speed goes from 12 t/s at the beginning, to 11 t/s at the end. Amazing

@ikawrakow ikawrakow left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you for finding this. The original PR had it hard-coded, so I assumed it needs to be different from the model RoPE type.

@ikawrakow ikawrakow merged commit 9647246 into ikawrakow:main Jul 9, 2026
@chrislawso

Copy link
Copy Markdown

This fixed it for me, thanks!

This fixed it for me as well, thanks!

The model is now fully coherent until the context limit is reached (I can only fit 100k), and with -dsa the TG speed goes from 12 t/s at the beginning, to 11 t/s at the end. Amazing

I compiled these newest PR bits and ik_llama continues crashing same as before.

What cli settings is everyone running for ik_llama and glm5.2 successfully?

@usrlocalben usrlocalben deleted the fix-glm-output-errors branch July 11, 2026 04:52
@usrlocalben

usrlocalben commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

What cli settings is everyone running for ik_llama and glm5.2 successfully?

@chrislawso

Here's my invocation / runscript with the three quants I've been using. gpu is r6kp, cpu is epyc 9b14 x2 nps4.
not shown: drop_caches if the gguf could already be in page cache with different numa distribution.

#!/bin/bash

MEMORY_CONCURRENCY_IN_NUMA_NODES=8
N_BATCH=4096

# COMPUTE_POWER_IN_THREADS_PER_NUMA=17
# M=/model/GLM-5.2/sokann/IQ2_KT/GLM-5.2-GGUF-2.244bpw-q8indexer.gguf

# COMPUTE_POWER_IN_THREADS_PER_NUMA=8
# M=/model/GLM-5.2/SixVolts/GLM-5.2-Q3_K_M-00001-of-00008.gguf

COMPUTE_POWER_IN_THREADS_PER_NUMA=6
M=/model/GLM-5.2/usrlocalben/HQ4_K/GLM-5.2-HQ4_K.gguf

N_THREADS=$[ $MEMORY_CONCURRENCY_IN_NUMA_NODES * $COMPUTE_POWER_IN_THREADS_PER_NUMA ]

GGML_CUDA_NO_PINNED=1 \
exec ./ik_llama.cpp/build/bin/llama-server \
  --host 0.0.0.0 --port 4972 --webui llamacpp \
  --numa distribute \
  -t $N_THREADS \
  --cache-ram 200000 \
  -b $N_BATCH -ub $N_BATCH -amb 1024 \
  -mla 3 -dsa -fidx \
  -ngl 999 \
  -ot exps=CPU \
  --jinja --parallel-tool-calls \
  --chat-template-kwargs '{"enable_thinking": true, "reasoning_effort": "high"}' \
  -ctk q8_0 \
  -c $[ 2**18 ] \
  --alias GLM-5.2 \
  --metrics \
  -m "$M"

  # -ot "blk\.([3-9])\.ffn_.*_exps=CUDA0" \
  # -ot "blk\.(1[0-4])\.ffn_.*_exps=CUDA0" \

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants