Repository navigation
fix(llm): do not take sliding_window as the context length - #6325
Open
David-Wu1119 wants to merge 2 commits into
Open
David-Wu1119 wants to merge 2 commits into
David-Wu1119 wants to merge 2 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
qinxuye
reviewed
Dec 4, 2026
qinxuye
left a comment
Contributor
There was a problem hiding this comment.
The Qwen raw configs now resolve to 32K, and the 179 focused tests and pre-commit passed locally. One issue remains in how the shared helper selects its fallback.
get_context_length_from_config collected sliding_window as a context length candidate (since xorbitsai#4768) and returned the largest one. Qwen2 and Qwen2.5 configs set sliding_window=131072 with use_sliding_window=false next to max_position_embeddings=32768, so Transformers and MLX launches without an explicit context_length used 131072, as did LLM.get_runtime_context_length for multimodal Transformers loaders. Collect the declared length keys first and fall back to sliding_window only when a config declares none of them, through one helper shared by both callers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The declared-length pass took any non-None value, so a config with max_position_embeddings=0 (or a negative or boolean value) and a valid sliding_window=4096 returned 0 on load and None at runtime, where main returned 4096. Both passes and the nested recursion also walked nested_attrs, so an iterator was exhausted after the first pass. Keep only positive integers (normalize_runtime_positive_int) before choosing between declared lengths and the sliding window, make nested_attrs a tuple once, and let get_runtime_context_length use the validated candidates directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
qinxuye
force-pushed
the
fix/context-length-sliding-window
branch
from
December 5, 2026 01:34
03e6aec to
8b8cc58
Compare
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.
Bug
get_context_length_from_configcountssliding_windowas a context length and returns the largest candidate. Qwen2 and Qwen2.5 configs declare a sliding window larger than their context:So a model launched with the Transformers or MLX engine without an explicit
context_lengthgets a context length of 131072 instead of 32768.PytorchModeltakesget_context_length(self._model.config)as its default, and the MLX models useget_context_length_from_config.LLM.get_runtime_context_lengthuses the same candidates for multimodal Transformers loaders.sliding_windowbecame a candidate in #4768. Before that change,get_context_lengthread onlymax_sequence_length,seq_lengthandmax_position_embeddings.Fix
A sliding window is the attention window, not the context length. The declared keys (
max_sequence_length,seq_length,max_position_embeddings, here and intext_config) are collected first, keeping only positive integers (normalize_runtime_positive_int, as the runtime accessor already did).sliding_windowis used only when no valid declared length exists anywhere in the config, somax_position_embeddings=0next tosliding_window=4096still gives 4096, as onmain.nested_attrsis made a tuple once, so an iterator works for both passes. A config whose only length values are invalid now gets the 2048 default instead of the invalid value.get_context_length_from_configandLLM.get_runtime_context_lengthshare this through one helper. Configs whose sliding window is smaller than their context, such as Mistral-7B-v0.1 (4096 vs 32768) or Gemma, give the same result as before. An explicitcontext_lengthstill wins.Tests
test_sliding_window_is_not_a_context_lengthinxinference/model/llm/tests/test_context_length.pycovers 5 configs: Qwen2/2.5, Mistral-7B-v0.1, a top-level sliding window with a nestedtext_configlength, a sliding window only, and an empty config. Newtest_loaded_config_sliding_window_is_not_a_context_lengthintest_runtime_context.pycovers the runtime path. Onmainsource 3 fail (the Qwen2 config, the nested case and the runtime case). With this change all pass.test_invalid_declared_length_falls_back_to_a_valid_window(0,-1,True,Nonenext tosliding_window=4096, load and runtime paths) andtest_nested_window_is_found_with_iterator_nested_attrs(follow-up 03e6aec). They pass onmainand with this change and fail on the first commit of this PR (ba5da9f), except the nested Qwen-style case, which also fails onmain(131072).test_context_length.py,test_runtime_context.pyandtest_utils.py: 437 passed on 03e6aec; the same 12 chat-template tool-history tests intest_utils.pyfail onmainand here.xinference/model/llm/testson ba5da9f: 3076 passed, 75 skipped with this change; onmainsource 3073 passed and the 3 new cases failed. The same 34 tests fail on both: chat-template tests intest_utils.py,test_deepseek_r1_chat_template.pyandtest_deepseek_v3_chat_template.py,test_minicpmv47.py(a missing module) and onetest_llm_family.pycase.pre-commit run --files <changed files>passes.config.jsonfiles.Found by Gemini (through Google Antigravity) while auditing xinference's LLM utilities; Claude Code checked it against the published configs, wrote the fix and the tests.
🤖 Generated with Claude Code