Skip to content

fix(sambanova): correct DeepSeek-V3.2 context window (32k -> 128k) - #32035

Open
bhumikadangayach wants to merge 10 commits into
BerriAI:mainfrom
bhumikadangayach:fix/deepseek-v3.2-context-window-v3
Open

bhumikadangayach wants to merge 10 commits into
BerriAI:mainfrom
bhumikadangayach:fix/deepseek-v3.2-context-window-v3

Conversation

@bhumikadangayach

Copy link
Copy Markdown
Contributor

Follow-up to #30016.

Greptile flagged in that PR that DeepSeek-V3.2's 32k context window might be a repeat of the same copy-paste mistake that was just fixed for DeepSeek-V3.1 (also 32k -> 128k). Confirmed via multiple sources (OpenRouter, Artificial Analysis, DeepSeek's own technical paper) that DeepSeek-V3.2 has a 128k (131,072 token) context window, matching its V3.1 predecessor's architecture lineage.

Fixed max_tokens, max_input_tokens, and max_output_tokens for sambanova/DeepSeek-V3.2 from 32768 → 131072. Pricing and other fields unchanged.

Backup file synced to match primary.

Supersedes #31417 (rebased onto current litellm_oss_staging).

fernando-izar and others added 9 commits July 2, 2026 21:22
…out (BerriAI#31632)

* fix(prometheus): bound per-request budget metric emission with a timeout

Wrap the per-request budget-metric gather in asyncio.wait_for so a slow Redis or DB lookup cannot consume the whole LoggingWorker watchdog and get the success-logging event cancelled. On timeout the emission is skipped in isolation; budget gauges are still refreshed by the periodic cron. The timeout is configurable via PROMETHEUS_BUDGET_METRICS_PER_REQUEST_TIMEOUT and defaults to 5.0 seconds, falling back to the default on an invalid value instead of raising

* fix(prometheus): reject non-finite and non-positive budget-metrics timeout env

float() accepts 0, negatives, nan and inf, which bypass the fallback: a value <= 0 makes asyncio.wait_for time out immediately and skip every per-request emission, and inf reintroduces the unbounded wait the timeout was meant to bound. Validate the parsed value is finite and greater than zero before using it, otherwise fall back to the default
When a guardrail blocks a post-call response, the synthetic violation response
reported hard-coded zero usage, discarding the token usage the upstream call
had already consumed.

Fix the root cause rather than re-counting tokens:
- Add an optional `original_response` field to ModifyResponseException.
- The unified guardrail's post-call success hook attaches the blocked LLM
  response to the exception.
- The /v1/messages and OpenAI-format (/v1/chat/completions, /v1/completions)
  block handlers report `original_response.usage` directly. Pre-call blocks
  never invoked the LLM, so usage is zero.

Mock-based tests cover the helper (returns original usage / zero), the success
hook attaching original_response, and the endpoint reporting it end-to-end.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ock (BerriAI#31389)

Streaming moderation improvements for the unified guardrail post-call
streaming iterator hook:

- streaming_buffer_until_moderated: withhold all chunks until end-of-stream
  moderation passes, then release the original response (clean) or only the
  block message (blocked) -- the original content is never delivered on a
  block. Snapshot chunks with a shallow list() copy (end-of-stream builds a
  separate assembled response; chunks aren't mutated in place).
- Clean Anthropic SSE on block: synthesize a well-formed termination sequence
  instead of a bare data: {"error": ...} blob that truncates the stream.
  Provider-specific synthesis lives in AnthropicMessagesHandler via
  build_block_sse_chunks (format-agnostic routing stays in the hook).
- Mid-stream blocks continue the in-progress message (close open content
  block, append block message, terminate) rather than emitting a second
  message_start, which clients reject. Standalone envelope only when no chunks
  were sent (buffered path).
- ModifyResponseException imported under TYPE_CHECKING + locally at runtime to
  avoid a module-level cyclic import.

Adds regression tests for buffering (content withheld on block) and mid-stream
continuation (single message_start).

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… content-rewriting guardrails

- _standalone_block_chunks and _block_continuation_chunks now read real
  token usage from ModifyResponseException.original_response instead of
  hardcoding zero, matching the non-streaming _blocked_response_usage path.
  Shared helper moved to guardrail_translation/utils.py.
- streaming_buffer_until_moderated is now forced off when the guardrail has
  mask_response_content=True, since buffered replay releases the withheld
  original chunks verbatim -- unsafe for a guardrail that rewrites content
  (e.g. PII masking).
- Fix inverted streaming-flag precedence comment.
…-of-stream detection

_check_streaming_has_ended assumed responses_so_far held ModelResponse
objects with .choices, but for the Responses API the accumulated chunks
are raw SSE event dicts, causing an AttributeError on every call
@greptile-apps

greptile-apps Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes the sambanova/DeepSeek-V3.2 context window from 32 768 → 131 072 tokens in both the primary and backup model pricing files, mirroring an identical correction made for DeepSeek-V3.1 in #30016.

  • model_prices_and_context_window.json: only the three DeepSeek-V3.2 token fields are changed — this part is correct.
  • litellm/model_prices_and_context_window_backup.json: contains ~200+ lines of additional model additions and updates not present in the primary file (new Gemini image models, ZAI/GLM models, OpenAI context window corrections, repositioned darkbloom entries). The repositioning of the darkbloom entries broke the file's JSON structure — the root object is now closed before fallback_generalizations, making the backup an invalid JSON document that will crash litellm whenever the backup path is used.

Confidence Score: 1/5

Not safe to merge — the backup JSON file is malformed and will crash litellm in any scenario that falls back to it.

The backup file's JSON structure is broken: the root object closes before fallback_generalizations, leaving that section and a stray } outside the root. load_local_model_cost_map() has no exception handling around json.loads(), so every code path that touches the backup — forced local mode, remote-fetch failure, and the integrity-check count — will throw a JSONDecodeError at runtime. The primary file's change is correct and isolated, but the backup breakage is a hard blocker.

litellm/model_prices_and_context_window_backup.json needs to be regenerated or hand-corrected so that fallback_generalizations remains inside the root JSON object, and its contents should be reconciled with the primary file.

Important Files Changed

Filename Overview
model_prices_and_context_window.json Correctly updates sambanova/DeepSeek-V3.2 max_tokens, max_input_tokens, and max_output_tokens from 32768 to 131072; no other changes in this file
litellm/model_prices_and_context_window_backup.json Contains the DeepSeek-V3.2 fix plus ~200+ unreferenced model additions/updates; critically, repositioning the darkbloom entries breaks the JSON structure — the root object closes before fallback_generalizations, making the file unparseable

Comments Outside Diff (1)

  1. litellm/model_prices_and_context_window_backup.json, line 1 (link)

    P1 Backup file diverges significantly from the primary file

    The PR description states "Backup file synced to match primary," but the diff shows the backup contains ~200+ lines of additional changes absent from model_prices_and_context_window.json: new model entries (gemini-3-pro-image, gemini-3.1-flash-image for vertex_ai/gemini/bare variants, openrouter/z-ai/glm-5.1, zai/glm-5.1, zai/glm-4.7-flash), updated max_input_tokens values for several OpenAI models, corrected max_output_tokens/max_tokens for o1-pro variants, and repositioned darkbloom entries. The two files are not in sync. Any user relying on the backup will get different model data than a user relying on the primary.

Reviews (1): Last reviewed commit: "fix(sambanova): correct DeepSeek-V3.2 co..." | Re-trigger Greptile

Comment on lines +44015 to +44016
},
"fallback_generalizations": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Broken JSON structure — backup file is now invalid

The relocation of the darkbloom model entries introduced a malformed JSON structure. At line 44015 the root object is closed by } followed by a trailing ,, and "fallback_generalizations" appears on the next line at 0-space indentation — outside the root {}. This makes the file invalid JSON that json.loads() will reject with a JSONDecodeError.

load_local_model_cost_map() in get_model_cost_map.py has no try/except around json.loads(), so this will crash litellm in any scenario where the backup is needed: when LITELLM_LOCAL_MODEL_COST_MAP=True, when the remote fetch fails (the fallback path at lines 295–297 of get_model_cost_map.py), and during integrity validation via _get_backup_model_count(). Compare with the primary file (model_prices_and_context_window.json line 44008–44009) where gpt-oss-20b correctly closes with }, (comma included) and fallback_generalizations remains at 2-space indent inside the root object.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 748ddd3 — regenerated the backup directly from the primary file. Both files are now in sync and valid JSON (verified locally with json.load()). The Greptile review is based on the first commit before the fix — please re-trigger to confirm.

@codecov

codecov Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

@CLAassistant

CLAassistant commented Oct 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
4 out of 5 committers have signed the CLA.

✅ seph-barker
✅ bhumikadangayach
✅ fernando-izar
✅ Sameerlite
❌ cursoragent
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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.

6 participants