notebooks icon indicating copy to clipboard operation
notebooks copied to clipboard

[BUG] Error on `Kaggle-Qwen3_(32B)_A100-Reasoning-Conversational.ipynb`

Open steveepreston opened this issue 2 months ago • 4 comments

Running Kaggle-Qwen3_(32B)_A100-Reasoning-Conversational.ipynb

While running this cell:

reasoning_conversations = tokenizer.apply_chat_template(
    reasoning_dataset.map(generate_conversation, batched = True)["conversations"],
    tokenize = False,
)

It throws this error:

---------------------------------------------------------------------------
UndefinedError                            Traceback (most recent call last)
Cell In[8], [line 1](vscode-notebook-cell:?execution_count=8&line=1)
----> [1](vscode-notebook-cell:?execution_count=8&line=1) reasoning_conversations = tokenizer.apply_chat_template(
      2     reasoning_dataset.map(generate_conversation, batched = True)["conversations"],
      3     tokenize = False,
      4 )

File ~/project/.venv/lib/python3.12/site-packages/transformers/tokenization_utils_base.py:1640, in PreTrainedTokenizerBase.apply_chat_template(self, conversation, tools, documents, chat_template, add_generation_prompt, continue_final_message, tokenize, padding, truncation, max_length, return_tensors, return_dict, return_assistant_tokens_mask, tokenizer_kwargs, **kwargs)
   1637         raise ValueError("continue_final_message is not compatible with return_assistant_tokens_mask.")
   1639 template_kwargs = {**self.special_tokens_map, **kwargs}  # kwargs overwrite special tokens if both are present
-> [1640](https://vscode-remote+ssh-002.vscode-resource.vscode-cdn.net/home/user/project/unsloth-notebooks/~/project/.venv/lib/python3.12/site-packages/transformers/tokenization_utils_base.py:1640) rendered_chat, generation_indices = render_jinja_template(
   1641     conversations=conversations,
   1642     tools=tools,
   1643     documents=documents,
   1644     chat_template=chat_template,
   1645     return_assistant_tokens_mask=return_assistant_tokens_mask,
   1646     continue_final_message=continue_final_message,
   1647     add_generation_prompt=add_generation_prompt,
   1648     **template_kwargs,
   1649 )
   1651 if not is_batched:
   1652     rendered_chat = rendered_chat[0]

File ~/project/.venv/lib/python3.12/site-packages/transformers/utils/chat_template_utils.py:521, in render_jinja_template(conversations, tools, documents, chat_template, return_assistant_tokens_mask, continue_final_message, add_generation_prompt, **kwargs)
    519     all_generation_indices.append(generation_indices)
    520 else:
--> [521](https://vscode-remote+ssh-002.vscode-resource.vscode-cdn.net/home/user/project/unsloth-notebooks/~/project/.venv/lib/python3.12/site-packages/transformers/utils/chat_template_utils.py:521)     rendered_chat = compiled_template.render(
    522         messages=chat,
    523         tools=tool_schemas,
    524         documents=documents,
    525         add_generation_prompt=add_generation_prompt,
    526         **kwargs,
    527     )
    528 if continue_final_message:
    529     final_message = chat[-1]["content"]

File ~/project/.venv/lib/python3.12/site-packages/jinja2/environment.py:1295, in Template.render(self, *args, **kwargs)
   1293     return self.environment.concat(self.root_render_func(ctx))  # type: ignore
   1294 except Exception:
-> [1295](https://vscode-remote+ssh-002.vscode-resource.vscode-cdn.net/home/user/project/unsloth-notebooks/~/project/.venv/lib/python3.12/site-packages/jinja2/environment.py:1295)     self.environment.handle_exception()

File ~/project/.venv/lib/python3.12/site-packages/jinja2/environment.py:942, in Environment.handle_exception(self, source)
    937 """Exception handling helper.  This is used internally to either raise
    938 rewritten exceptions or return a rendered traceback for the template.
    939 """
    940 from .debug import rewrite_traceback_stack
--> [942](https://vscode-remote+ssh-002.vscode-resource.vscode-cdn.net/home/user/project/unsloth-notebooks/~/project/.venv/lib/python3.12/site-packages/jinja2/environment.py:942) raise rewrite_traceback_stack(source=source)

File <template>:23, in top-level template code()

UndefinedError: 'list object' has no attribute 'content'

steveepreston avatar Oct 16 '25 20:10 steveepreston

Fixed by:

mapped_dataset = reasoning_dataset.map(generate_conversation, batched=True)
reasoning_conversations = [
    tokenizer.apply_chat_template(conv, tokenize=False)
    for conv in mapped_dataset["conversations"]
]

steveepreston avatar Oct 16 '25 22:10 steveepreston

Hi @steveepreston thank you, we recently did an update and fix to unsloth. I know you already fixed it but let us know if our update managed to solve the issue

shimmyshimmer avatar Oct 18 '25 08:10 shimmyshimmer

Can you mention it? I cant see any in https://github.com/unslothai/notebooks/commits/main/nb/Kaggle-Qwen3_(32B)_A100-Reasoning-Conversational.ipynb

steveepreston avatar Oct 18 '25 19:10 steveepreston

Can you mention it? I cant see any in https://github.com/unslothai/notebooks/commits/main/nb/Kaggle-Qwen3_(32B)_A100-Reasoning-Conversational.ipynb

Please see our latest github release: https://github.com/unslothai/unsloth/releases/tag/October-2025

shimmyshimmer avatar Nov 04 '25 07:11 shimmyshimmer