Fix mutable default argument and unreachable exception handler#3775
Open
Mr-Neutr0n wants to merge 1 commit intolm-sys:mainfrom
Open
Fix mutable default argument and unreachable exception handler#3775Mr-Neutr0n wants to merge 1 commit intolm-sys:mainfrom
Mr-Neutr0n wants to merge 1 commit intolm-sys:mainfrom
Conversation
- Replace mutable default list `sampling_boost_models=[]` with `None` in `get_sample_weight()` to avoid the well-known mutable default argument pitfall (gradio_block_arena_anony.py). - Reorder exception handlers in `chat_completion_openai_azure()` so `InvalidRequestError` is caught before its parent `OpenAIError`. The previous ordering made the `InvalidRequestError` handler unreachable dead code (llm_judge/common.py).
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
fastchat/serve/gradio_block_arena_anony.py: Replace mutable default argumentsampling_boost_models=[]withNoneinget_sample_weight(). Mutable defaults are shared across all calls and can lead to subtle, hard-to-diagnose bugs when the list is mutated.fastchat/llm_judge/common.py: Reorder exception handlers inchat_completion_openai_azure()so thatopenai.error.InvalidRequestErroris caught before its parent classopenai.error.OpenAIError. The previous ordering made theInvalidRequestErrorhandler unreachable dead code, meaning invalid request errors were retried instead of breaking immediately.Test plan
get_sample_weight()still works correctly with and withoutsampling_boost_modelsargumentInvalidRequestErrorbefore the genericOpenAIError