fix(types): set optimal default top_p threshold for nucleus sampling - #2956
Open
adri22235 wants to merge 4 commits into
Open
fix(types): set optimal default top_p threshold for nucleus sampling#2956adri22235 wants to merge 4 commits into
adri22235 wants to merge 4 commits into
Conversation
…dri22235/python-genai into fix/multimodal-thinking-budget
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.
Summary of Changes
This pull request restores and explicitly defines the optimal default
top_pthreshold (default=0.95) across key configuration classes ingoogle/genai/types.py(GenerateContentConfig,GenerationConfig,Model, andLiveConnectConfig).Motivation & Problem Statement
In recent updates, the omission of explicit default
top_pnucleus sampling thresholds coupled with defaulttemperature: 1.0causes notable sampling entropy, particularly when using thinking models on lower/medium reasoning budgets (ThinkingLevel.MEDIUM).Empirical testing on real-world multimodal benchmarks (fine-grained OCR under motion blur, complex regulatory logic, and noisy audio processing) demonstrated that:
top_pis left unbounded attemperature: 1.0, the model occasionally samples low-probability tokens in initial reasoning steps, causing cascading hallucinations (e.g., misreading ambiguous digits or misinterpreting domain-specific rules).top_p=0.95by default restores the deterministic stability previously experienced in earlier stable releases (such as the workflow prior to recent upstream schema changes), while still preserving creative exploration when explicitly requested by developers.Classes Updated
GenerateContentConfig:top_p: Optional[float] = Field(default=0.95, ...)GenerationConfig:top_p: Optional[float] = Field(default=0.95, ...)Model:top_p: Optional[float] = Field(default=0.95, ...)LiveConnectConfig:top_p: Optional[float] = Field(default=0.95, ...)Verification & Testing
types.pyserialization and schema compatibility withgoogle/genai/models.py.