-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: prevent LM Studio context overflow by limiting maxTokens to 20% of context window #7389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,13 +38,18 @@ export const parseLMStudioModel = (rawModel: LLMInstanceInfo | LLMInfo): ModelIn | |||||||||||||||
| // Handle both LLMInstanceInfo (from loaded models) and LLMInfo (from downloaded models) | ||||||||||||||||
| const contextLength = "contextLength" in rawModel ? rawModel.contextLength : rawModel.maxContextLength | ||||||||||||||||
|
|
||||||||||||||||
| // Calculate maxTokens as 20% of context window to prevent context overflow | ||||||||||||||||
| // This ensures there's always room for input tokens and prevents crashes | ||||||||||||||||
| // when approaching the context limit | ||||||||||||||||
| const maxOutputTokens = Math.ceil(contextLength * 0.2) | ||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we consider making this ratio configurable? While 20% is a reasonable default that matches other providers, some users might want to adjust this based on their specific use cases. Perhaps a setting like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For models with very small context windows (e.g., < 1000 tokens), this 20% calculation might result in very limited output capacity. Should we consider adding a minimum threshold? Something like:
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| const modelInfo: ModelInfo = Object.assign({}, lMStudioDefaultModelInfo, { | ||||||||||||||||
| description: `${rawModel.displayName} - ${rawModel.path}`, | ||||||||||||||||
| contextWindow: contextLength, | ||||||||||||||||
| supportsPromptCache: true, | ||||||||||||||||
| supportsImages: rawModel.vision, | ||||||||||||||||
| supportsComputerUse: false, | ||||||||||||||||
| maxTokens: contextLength, | ||||||||||||||||
| maxTokens: maxOutputTokens, | ||||||||||||||||
| }) | ||||||||||||||||
|
|
||||||||||||||||
| return modelInfo | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test coverage! The test cases cover a good range of context sizes. Consider also adding a test case for very small context windows (e.g., 512 tokens) to ensure the calculation works correctly at the lower bounds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when to expect this to be merged in next update?