Repository navigation
Studio: say a chat is too long on safetensors models - #15616
Conversation
Review + reproduction evidencePinned review: I reproduced an over-length chat on a safetensors model (SmolLM2-135M-Instruct, Context Length 256, a 2177-token prompt) on the merge base
Conclusion: real and fixed for text chats on safetensors models; fitting prompts are unchanged. Image and audio-input chats still need the same guard in a follow-up. |
Review + reproduction evidence (updated for 5b92241)Pinned review: Finding (fixed): the first version refused every prompt longer than the loaded Context Length, but only the fast Llama path (Llama, Mistral, Qwen2/Qwen3, Gemma/Gemma 2, Granite, Cohere, Falcon H1) actually breaks there, because its forward cuts the input at Same prompt (about 2.2k tokens), Context Length 256, merge base
Conclusion: real and fixed for text chats on safetensors models that crash past the window, with no change for models that already handled long prompts. Two pre-existing gaps are left for a follow-up: image and audio-input chats still miss this check, and |
|
@codex review |
1 similar comment
|
@codex review |
Codex Review SummaryThis 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. |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…helper (#15679) ## Summary `Repo tests (CPU, gloo)` has failed twice with every rank dying before the test starts: ``` torch.distributed.DistNetworkError: The server socket has failed to listen on any local network address. port: 45095, useIpv6: false, code: -98, name: EADDRINUSE AssertionError: rank exit codes [1, 1] ``` - #15616: `tests/test_tp_native_gloo.py::test_sharded_loading_matches_full_load[phi3-2-None]` - #15632: `test_tp_x_fsdp2_refuses_trainable_head_norms`, port 42541, also in `tests/test_tp_native_gloo.py` #14334 fixed this race by adding `tests/_rendezvous_port.free_port()`: - It draws MASTER_PORT from below the kernel's ephemeral range (32768-60999 on Linux), in a slice per xdist worker. - So neither another worker nor an outgoing gloo connection can take the port between the test releasing it and rank 0 listening on it. That PR moved 21 tests onto the helper, but 15 distributed tests still pick their port with `bind(("127.0.0.1", 0))`, `tests/test_tp_native_gloo.py` among them. Both failing ports above are inside the ephemeral range. ## Change - **14 test files:** their local `_free_port()` now delegates to `tests._rendezvous_port.free_port()`, the same three lines the other 21 files use, and their now-unused `socket` imports are dropped: - `test_tp_native_gloo.py`, `test_pp_native_gloo.py`, `test_pp_fsdp2_gloo.py`, `test_parallel_general_gloo.py` - `test_moe_dw_accumulate.py`, `test_ddp_find_unused_default.py`, `test_ddp_comm_defaults.py` - `test_fast_inference_torchrun_agreement.py`, `test_cudnn_sdpa_grad_layout_dtensor.py` - five under `tests/python/`: block compile DDP, GRPO DDP sync, plain trainer DDP, sentence transformer DDP and FSDP2 save - **`tests/test_token_budget_batches.py`:** the inline `bind(0)` before `MASTER_PORT` now uses the helper. - **`tests/test_rendezvous_port_everywhere.py`** (new): any test outside `tests/studio` that sets up a torch rendezvous (`MASTER_PORT`, `master_port`, `init_process_group` or `TCPStore`) must either define `_free_port` through the helper or not bind port 0 at all. - Studio tests are out of scope: their ports are for HTTP servers they start themselves. - It includes self-tests for both shapes of the mistake, and a check that the helper stays below the ephemeral range for several worker ids. ## Testing - **`tests/test_rendezvous_port_everywhere.py`:** 6 passed. - **Sabotage:** with `tests/test_tp_native_gloo.py` and `tests/test_token_budget_batches.py` restored from main, the guard fails and names both files. - The 14 converted files plus `tests/test_token_budget_batches.py` and the new guard, under `-n 4`: 243 passed, 2 skipped. On main the same 14 files plus `test_token_budget_batches.py` (without the guard): 237 passed, 2 skipped.


On a safetensors model, a prompt longer than the Context Length was sent to the model anyway. Generation crashed with a tensor size mismatch, and every client only saw "An internal error occurred": the Studio chat, the OpenAI-compatible API, and the Anthropic-compatible API. A coding agent that compacts its conversation on "Prompt is too long" got an api_error instead, so it retried the same request and never compacted.
Such a prompt is now refused before generation with the same context refusal MLX and GGUF models give. The Studio chat shows "Message too long: N tokens exceeds the M-token context window" with the usual advice, the OpenAI-compatible API returns a 400 context_length_exceeded, and /v1/messages streams report "Prompt is too long". Prompts that fit run exactly as before.