You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] RuntimeError: Unsloth: The tokenizer unsloth/DeepSeek-R1-0528-Qwen3-8B-unsloth-bnb-4bit #2663
Unrecognized keys in rope_scaling for 'rope_type'='yarn': {'attn_factor'}
==((====))== Unsloth 2025.5.10: Fast Qwen3 patching. Transformers: 4.52.4.
\ /| NVIDIA A10G. Num GPUs = 1. Max memory: 21.975 GB. Platform: Linux.
O^O/ _/ \ Torch: 2.5.0+cu118. CUDA: 8.6. CUDA Toolkit: 11.8. Triton: 3.1.0
\ / Bfloat16 = TRUE. FA [Xformers = 0.0.27.post2+cu118. FA2 = False]
"-____-" Free license: http://github.com/unslothai/unsloth
Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!
Unrecognized keys in rope_scaling for 'rope_type'='yarn': {'attn_factor'}
Unrecognized keys in rope_scaling for 'rope_type'='yarn': {'attn_factor'}
Loading checkpoint shards: 100%
2/2 [00:01<00:00, 1.53it/s]
RuntimeError Traceback (most recent call last)
Cell In[15], line 1
----> 1 model, tokenizer = FastLanguageModel.from_pretrained(
2 model_name = model_name,
3 max_seq_length = 3000, # Choose any for long context!
4 load_in_4bit = True, # 4 bit quantization to reduce memory
5 load_in_8bit = False, # [NEW!] A bit more accurate, uses 2x memory
6 full_finetuning = False, # [NEW!] We have full finetuning now!
7 # token = "hf_...", # use one if using gated models
8 )
File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/unsloth/tokenizer_utils.py:586, in load_correct_tokenizer(tokenizer_name, model_max_length, padding_side, token, trust_remote_code, cache_dir, fix_tokenizer)
583 chat_template = old_chat_template
585 else:
--> 586 chat_template = fix_chat_template(tokenizer)
587 if old_chat_template is not None and chat_template is None:
588 raise RuntimeError(
589 "Unsloth: Fixing chat template failed - please file a report immediately!"
590 )
File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/unsloth/tokenizer_utils.py:686, in fix_chat_template(tokenizer)
683 new_chat_template = _fix_chat_template(chat_template)
684 if "{% if add_generation_prompt %}" not in new_chat_template and
685 "{%- if add_generation_prompt %}" not in new_chat_template:
--> 686 raise RuntimeError(
687 f"Unsloth: The tokenizer {tokenizer.name_or_path}\n"
688 "does not have a {% if add_generation_prompt %} for generation purposes.\n"
689 f"Please file a bug report to the maintainers of {tokenizer.name_or_path} - thanks!"
690 )
691 else:
692 logger.warning_once(
693 "Unsloth: We successfully patched the tokenizer to add a {% if add_generation_prompt %} to the chat_template.\n"
694 f"This is not a bug, but please notify the maintainers of {tokenizer.name_or_path} - thanks!"
695 )
RuntimeError: Unsloth: The tokenizer unsloth/DeepSeek-R1-0528-Qwen3-8B-unsloth-bnb-4bit
does not have a {% if add_generation_prompt %} for generation purposes.
Please file a bug report to the maintainers of unsloth/DeepSeek-R1-0528-Qwen3-8B-unsloth-bnb-4bit - thanks!
{%- if message["role"] == "assistant" -%}
{%- if "</think>" in content -%}
{%- set content = content.split("</think>")[-1] -%}
{%- endif -%}
{%- endif -%}
{%- if message["role"] == "assistant" and message["tool_calls"] is defined and message["tool_calls"] is not none -%}
{%- set ns.is_last_user = false -%}
{%- if ns.is_tool -%}
{{- "<|tool▁outputs▁end|>" -}}
{%- endif -%}
{%- set ns.is_first = false -%}
{%- set ns.is_tool = false -%}
{%- set ns.is_output_first = true -%}
{%- for tool in message["tool_calls"] -%}
{%- if not ns.is_first -%}
{%- if content is none -%}
{{- "<|tool▁calls▁begin|><|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "\n" + "```json" + "\n" + tool["function"]["arguments"] + "\n" + "```" + "<|tool▁call▁end|>" -}}
{%- else -%}
{{- content + "<|tool▁calls▁begin|><|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "\n" + "```json" + "\n" + tool["function"]["arguments"] + "\n" + "```" + "<|tool▁call▁end|>" -}}
{%- endif -%}
{%- set ns.is_first = true -%}
{%- else -%}
{{- "\n" + "<|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "\n" + "```json" + "\n" + tool["function"]["arguments"] + "\n" + "```" + "<|tool▁call▁end|>" -}}
{%- endif -%}
{%- endfor -%}
{{- "<|tool▁calls▁end|><|end▁of▁sentence|>" -}}
{%- endif -%}
{%- if message["role"] == "assistant" and (message["tool_calls"] is not defined or message["tool_calls"] is none) -%}
{%- set ns.is_last_user = false -%}
{%- if ns.is_tool -%}
{{- "<|tool▁outputs▁end|>" + content + "<|end▁of▁sentence|>" -}}
{%- set ns.is_tool = false -%}
{%- else -%}
{{- content + "<|end▁of▁sentence|>" -}}
{%- endif -%}
{%- endif -%}
{%- if message["role"] == "tool" -%}
{%- set ns.is_last_user = false -%}
{%- set ns.is_tool = true -%}
{%- if ns.is_output_first -%}
{{- "<|tool▁outputs▁begin|><|tool▁output▁begin|>" + content + "<|tool▁output▁end|>" -}}
{%- set ns.is_output_first = false -%}
{%- else -%}
{{- "\n<|tool▁output▁begin|>" + content + "<|tool▁output▁end|>" -}}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- if ns.is_tool -%}
{{- "<|tool▁outputs▁end|>" -}}
{%- endif -%}
And then here at the end, I don't think this occurs (because ns.is_last_user is going to be true). And if it did occur, you'd wind up with two < | Assistant | >s in the add_generation_prompt
{%- if add_generation_prompt and not ns.is_last_user and not ns.is_tool -%}
{{- "<|Assistant|>" -}}
{%- endif -%}
So you wind up with this bit of fix_chat_template failing.
I'm not sure what the "correct" way to handle this is (does the chat template need to change? should the template be assumed correct and logic be added to handle this? etc.) BUT if you need to get past this you can readily patch unsloth.tokenizer_utils.fix_chat_template for yourself on the fly (and either modify the chat template directly or just allow this specific model to pass by the checks).
I insert following code before loading model.
It's not a 'correct' way, but It allows me to execute fintuning prosess.
import unsloth.tokenizer_utils
original_fix_chat_template = unsloth.tokenizer_utils.fix_chat_template
def new_fix_chat_template(tokenizer):
chat_template = getattr(tokenizer, "chat_template", None)
return chat_template
try:
unsloth.tokenizer_utils.fix_chat_template = new_fix_chat_template
print("Successfully overrode 'unsloth.tokenizer_utils.fix_chat_template'.")
print("The tokenizer's chat_template will now be used as-is without Unsloth's default modifications or error checks for add_generation_prompt.")
except AttributeError as e:
print(f"Error overriding function: {e}")
print("Please ensure 'unsloth.tokenizer_utils' is the correct module path.")
print("You might need to inspect the Unsloth library structure if this path is incorrect.")
You cannot use the officially published deepseek-ai/DeepSeek-R1-0528-Qwen3-8B from DeepSeek for training; you must use the modified version unsloth/DeepSeek-R1-0528-Qwen3-8B by Unsloth. After comparing the model weight files, I found significant differences and hope that the Unsloth official team can explain what changes have been made. I have also encountered issues with Unsloth loading the official model weights:
Error content:
RuntimeError: Unsloth: The tokenizer /root/autodl-tmp/models/deepseek-ai/DeepSeek-R1-0528-Qwen3-8B does not have a {% if add_generation_prompt %} for generation purposes. Please file a bug report to the maintainers of /root/autodl-tmp/models/deepseek-ai/DeepSeek-R1-0528-Qwen3-8B - thanks!
After updating to Unsloth version 6.1, loading the original official DeepSeek model still results in issues.
Do I have to use the Unsloth-modified unsloth/DeepSeek-R1-0528-Qwen3-8B to load the model?
How about the error Unrecognized keys in rope_scaling for 'rope_type'='yarn': {'attn_factor'}, which was also raised in this issue page deepseek-ai/DeepSeek-R1#684
Activity
joshib123 commentedon May 31, 2025
Unrecognized keys in
rope_scalingfor 'rope_type'='yarn': {'attn_factor'}==((====))== Unsloth 2025.5.10: Fast Qwen3 patching. Transformers: 4.52.4.
\ /| NVIDIA A10G. Num GPUs = 1. Max memory: 21.975 GB. Platform: Linux.
O^O/ _/ \ Torch: 2.5.0+cu118. CUDA: 8.6. CUDA Toolkit: 11.8. Triton: 3.1.0
\ / Bfloat16 = TRUE. FA [Xformers = 0.0.27.post2+cu118. FA2 = False]
"-____-" Free license: http://github.com/unslothai/unsloth
Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!
Unrecognized keys in
rope_scalingfor 'rope_type'='yarn': {'attn_factor'}Unrecognized keys in
rope_scalingfor 'rope_type'='yarn': {'attn_factor'}Loading checkpoint shards: 100%
2/2 [00:01<00:00, 1.53it/s]
RuntimeError Traceback (most recent call last)
Cell In[15], line 1
----> 1 model, tokenizer = FastLanguageModel.from_pretrained(
2 model_name = model_name,
3 max_seq_length = 3000, # Choose any for long context!
4 load_in_4bit = True, # 4 bit quantization to reduce memory
5 load_in_8bit = False, # [NEW!] A bit more accurate, uses 2x memory
6 full_finetuning = False, # [NEW!] We have full finetuning now!
7 # token = "hf_...", # use one if using gated models
8 )
File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/unsloth/models/loader.py:376, in FastLanguageModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, load_in_8bit, full_finetuning, token, device_map, rope_scaling, fix_tokenizer, trust_remote_code, use_gradient_checkpointing, resize_model_vocab, revision, use_exact_model_name, fast_inference, gpu_memory_utilization, float8_kv_cache, random_state, max_lora_rank, disable_log_stats, *args, **kwargs)
373 pass
374 pass
--> 376 model, tokenizer = dispatch_model.from_pretrained(
377 model_name = model_name,
378 max_seq_length = max_seq_length,
379 dtype = _get_dtype(dtype),
380 load_in_4bit = load_in_4bit,
381 token = token,
382 device_map = device_map,
383 rope_scaling = rope_scaling,
384 fix_tokenizer = fix_tokenizer,
385 model_patcher = dispatch_model,
386 tokenizer_name = tokenizer_name,
387 trust_remote_code = trust_remote_code,
388 revision = revision if not is_peft else None,
389
390 fast_inference = fast_inference,
391 gpu_memory_utilization = gpu_memory_utilization,
392 float8_kv_cache = float8_kv_cache,
393 random_state = random_state,
394 max_lora_rank = max_lora_rank,
395 disable_log_stats = disable_log_stats,
396 *args, **kwargs,
397 )
399 if resize_model_vocab is not None:
400 model.resize_token_embeddings(resize_model_vocab)
File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/unsloth/models/qwen3.py:419, in FastQwen3Model.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, token, device_map, rope_scaling, fix_tokenizer, model_patcher, tokenizer_name, trust_remote_code, **kwargs)
404 @staticmethod
405 def from_pretrained( #TODO: Change after release
406 model_name = "Qwen/Qwen3-7B",
(...)
417 **kwargs,
418 ):
--> 419 return FastLlamaModel.from_pretrained(
420 model_name = model_name,
421 max_seq_length = max_seq_length,
422 dtype = dtype,
423 load_in_4bit = load_in_4bit,
424 token = token,
425 device_map = device_map,
426 rope_scaling = rope_scaling,
427 fix_tokenizer = fix_tokenizer,
428 model_patcher = FastQwen3Model,
429 tokenizer_name = tokenizer_name,
430 trust_remote_code = trust_remote_code,
431 **kwargs,
432 )
File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/unsloth/models/llama.py:1840, in FastLlamaModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, token, device_map, rope_scaling, fix_tokenizer, model_patcher, tokenizer_name, trust_remote_code, fast_inference, gpu_memory_utilization, float8_kv_cache, random_state, max_lora_rank, disable_log_stats, **kwargs)
1838 # Counteract saved tokenizers
1839 tokenizer_name = model_name if tokenizer_name is None else tokenizer_name
-> 1840 tokenizer = load_correct_tokenizer(
1841 tokenizer_name = tokenizer_name,
1842 model_max_length = max_position_embeddings,
1843 padding_side = "right",
1844 token = token,
1845 trust_remote_code = trust_remote_code,
1846 fix_tokenizer = fix_tokenizer,
1847 )
1849 model, tokenizer = patch_tokenizer(model, tokenizer)
1850 model, tokenizer = model_patcher.post_patch(model, tokenizer)
File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/unsloth/tokenizer_utils.py:586, in load_correct_tokenizer(tokenizer_name, model_max_length, padding_side, token, trust_remote_code, cache_dir, fix_tokenizer)
583 chat_template = old_chat_template
585 else:
--> 586 chat_template = fix_chat_template(tokenizer)
587 if old_chat_template is not None and chat_template is None:
588 raise RuntimeError(
589 "Unsloth: Fixing chat template failed - please file a report immediately!"
590 )
File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/unsloth/tokenizer_utils.py:686, in fix_chat_template(tokenizer)
683 new_chat_template = _fix_chat_template(chat_template)
684 if "{% if add_generation_prompt %}" not in new_chat_template and
685 "{%- if add_generation_prompt %}" not in new_chat_template:
--> 686 raise RuntimeError(
687 f"Unsloth: The tokenizer
{tokenizer.name_or_path}\n"688 "does not have a {% if add_generation_prompt %} for generation purposes.\n"
689 f"Please file a bug report to the maintainers of
{tokenizer.name_or_path}- thanks!"690 )
691 else:
692 logger.warning_once(
693 "Unsloth: We successfully patched the tokenizer to add a {% if add_generation_prompt %} to the chat_template.\n"
694 f"This is not a bug, but please notify the maintainers of
{tokenizer.name_or_path}- thanks!"695 )
RuntimeError: Unsloth: The tokenizer
unsloth/DeepSeek-R1-0528-Qwen3-8B-unsloth-bnb-4bitdoes not have a {% if add_generation_prompt %} for generation purposes.
Please file a bug report to the maintainers of
unsloth/DeepSeek-R1-0528-Qwen3-8B-unsloth-bnb-4bit- thanks!x4080 commentedon Jun 1, 2025
Hi, I also got problem :
It wont even load the model, maybe DeepSeek-R1-0528-Qwen3-8B is not supported yet ?
morimori00 commentedon Jun 2, 2025
Same problem here
hitzelc commentedon Jun 3, 2025
This appears to be more of an issue with the chat template for the model.
The chat template:
Right here is one issue, note that every turn here is going to end with < | Assistant | >.
And then here at the end, I don't think this occurs (because ns.is_last_user is going to be true). And if it did occur, you'd wind up with two < | Assistant | >s in the add_generation_prompt
So you wind up with this bit of fix_chat_template failing.
I'm not sure what the "correct" way to handle this is (does the chat template need to change? should the template be assumed correct and logic be added to handle this? etc.) BUT if you need to get past this you can readily patch unsloth.tokenizer_utils.fix_chat_template for yourself on the fly (and either modify the chat template directly or just allow this specific model to pass by the checks).
morimori00 commentedon Jun 3, 2025
I insert following code before loading model.
It's not a 'correct' way, but It allows me to execute fintuning prosess.
x4080 commentedon Jun 5, 2025
@morimori00 Cool, did you use
to make it run ?
morimori00 commentedon Jun 5, 2025
No I just
on runpod.io H200 pod
x4080 commentedon Jun 5, 2025
@morimori00 thanks
shimmyshimmer commentedon Jun 6, 2025
Hi guys apologies for the issue! We just updated unsloth to fix the issue. Please update and we also released new GRPO notebook for DeepSeek R1 distill qwen3: https://x.com/UnslothAI/status/1931008531299545339
Has a new reward function too
CC: @hitzelc @joshib123 @morimori00 @x4080
If any issues still persist, feel free to make a new issue :)
hixulei commentedon Jun 9, 2025
You cannot use the officially published deepseek-ai/DeepSeek-R1-0528-Qwen3-8B from DeepSeek for training; you must use the modified version unsloth/DeepSeek-R1-0528-Qwen3-8B by Unsloth. After comparing the model weight files, I found significant differences and hope that the Unsloth official team can explain what changes have been made. I have also encountered issues with Unsloth loading the official model weights:
Error content:
RuntimeError: Unsloth: The tokenizer /root/autodl-tmp/models/deepseek-ai/DeepSeek-R1-0528-Qwen3-8B does not have a {% if add_generation_prompt %} for generation purposes. Please file a bug report to the maintainers of /root/autodl-tmp/models/deepseek-ai/DeepSeek-R1-0528-Qwen3-8B - thanks!
After updating to Unsloth version 6.1, loading the original official DeepSeek model still results in issues.
Do I have to use the Unsloth-modified unsloth/DeepSeek-R1-0528-Qwen3-8B to load the model?
yangysc commentedon Aug 11, 2025
How about the error
Unrecognized keys in rope_scaling for 'rope_type'='yarn': {'attn_factor'}, which was also raised in this issue page deepseek-ai/DeepSeek-R1#684PrefixGrouper on ROCm: static flex compile for calls whose backward r…
PrefixGrouper: run the strict compile check per padded length on ROCm (…