Skip to content

Fix UltraChat chat-template handling for Transformers v5#1941

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/adapt-to-v5-chat-template
Draft

Fix UltraChat chat-template handling for Transformers v5#1941
Copilot wants to merge 4 commits into
mainfrom
copilot/adapt-to-v5-chat-template

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Description

Transformers v5 changed apply_chat_template to return a BatchEncoding by default instead of legacy input_ids-like output. In AutoRound, the UltraChat calibration path was probing chat-template support in a way that no longer matched v5 behavior, and then unconditionally disabled chat templating even for instruct tokenizers.

  • Compatibility fix

    • Switch the UltraChat instruct-tokenizer probe to tokenize=False, so capability detection is based on rendered text instead of tokenized return types.
    • Keep the probe resilient across tokenizer implementations that now return BatchEncoding.
  • Behavior fix

    • Remove the unconditional fallback that forced apply_chat_template=False.
    • Only disable chat templating when the tokenizer probe actually shows that chat templates are unsupported.
  • Regression coverage

    • Add focused unit coverage for:
      • a v5-style tokenizer returning BatchEncoding
      • a plain tokenizer that does not support chat templates
out = tokenizer.apply_chat_template(
    [{"role": "user", "content": "Hi"}],
    tokenize=False,
)

Type of Change

Bug fix

Related Issues

Checklist Before Submitting

  • My code has been tested locally.
  • Documentation has been updated as needed.
  • New or updated tests are included where applicable.
  • The CUDA CI has passed. You can trigger it by commenting /azp run Unit-Test-CUDA-AutoRound.

Copilot AI changed the title [WIP] Fix bug to adapt to V5 apply chat template Fix UltraChat chat-template handling for Transformers v5 Jun 22, 2026
Copilot AI requested a review from xin3he June 22, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants