Skip to content

fix(local): read an MLX model's context window from its config.json - #159

Closed
Blvckjs96 wants to merge 1 commit into
tinyhumansai:mainfrom
Blvckjs96:fix/mlx-context-window-from-model-config
Closed

Blvckjs96 wants to merge 1 commit into
tinyhumansai:mainfrom
Blvckjs96:fix/mlx-context-window-from-model-config

Conversation

@Blvckjs96

Copy link
Copy Markdown

Summary

MLX servers (mlx_lm, mlx_vlm) report no model limits, so the local profile falls back to 4096 tokens. A host system prompt alone can exceed that (about 7k tokens in OpenHuman), and the host then trims the user's turn out of the request; the model answers a placeholder prompt, loops and calls tools nobody asked for.

The model id of an MLX server is the directory the weights were loaded from. For Mlx/Omlx, context_window_with_local_fallback now reads max_position_embeddings from that directory's config.json (top level or text_config) when no explicit window is given. Unreadable or missing values fall back to the profile default; other runtimes are unchanged.

The value is the model's trained maximum, not what the host's memory can hold. A host that knows better passes an explicit window.

Verification

  • cargo test -p tinyinference-local --lib profile: 9 passed (2 new)
  • cargo fmt --all -- --check, cargo clippy -p tinyinference-local --all-targets -- -D warnings: clean
  • Observed in OpenHuman with a 262144-token Qwen on mlx_vlm: with a 65536 window the turn takes 1 model call instead of 11-13.

MLX servers report no limits and the profile default is 4096 tokens, which a host system prompt alone can exceed, so hosts trim the user's turn out of the request. The model id of an MLX server is the directory the weights were loaded from; read max_position_embeddings (top level or text_config) from its config.json. An explicit window still wins, and anything unreadable falls back to the profile default.
@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a0bdd490-c493-407e-af76-4c24d8bd750c
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@Blvckjs96

Copy link
Copy Markdown
Author

Closing: the host will handle this on its side. Thanks.

@Blvckjs96 Blvckjs96 closed this Nov 19, 2026
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.

1 participant