Fix autothink and thinkdeeper for transformers>=5#320
Merged
codelion merged 2 commits intoJul 18, 2026
Merged
Conversation
jacquerie
force-pushed
the
fix-autothink-and-thinkdeeper
branch
from
July 18, 2026 10:23
1d64c8a to
2b377a5
Compare
…ump 0.3.22 Builds on the transformers>=5 fix: apply_chat_template now returns a BatchEncoding, so the tensor must be unwrapped via .input_ids. Two corrections to the original change: 1. Preserve the device transfer. `tokens.to(device)` was called without assigning the result, but Tensor.to() is not in-place -- it returns a new tensor. As written the tokens stayed on CPU, so on CUDA/MPS the subsequent model(input_ids=tokens, ...) would fail with a device mismatch. A CPU-only repro hides this. Chain it instead: .input_ids.to(self.model.device). 2. Apply the same fix to optillm/deepconf/processor.py, which has the identical apply_chat_template(return_tensors="pt") -> model(input_ids=tokens) pattern and was still passing a BatchEncoding. Also updates the README badges (drop the GitHub stars badge, use the pepy.tech downloads badge which reports actual counts) and bumps the version to 0.3.22. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since version 5 of the
transformerslibrary, methodapply_chat_templatereturns aBatchEncodingobject, which wraps the output tensor in adict-like object: https://github.com/huggingface/transformers/blob/7ea2320c76117e6742364808a666ef6f2fb40a67/MIGRATION_GUIDE_V5.md#4-apply_chat_template-returns-batchencodingThe code in
autothinkandthinkdeeperdid not account for this, which made the following code throw:This PR fixes this issue by noticing that, since OptiLLM explicitly depends on
transformersat version 5 and above (optillm/pyproject.toml
Line 29 in c258858
BatchEncodingobject and query itsinput_idsproperty.