feat(gemini): migrate to google-genai SDK, keep gemini_api alias#1382
Open
Luodian wants to merge 3 commits into
Open
feat(gemini): migrate to google-genai SDK, keep gemini_api alias#1382Luodian wants to merge 3 commits into
Luodian wants to merge 3 commits into
Conversation
…ve concurrency), keep gemini_api alias
…udio mime type from extension
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.
Gemini: migrate to the google-genai SDK
Public shipped the deprecated
google-generativeaibackend (gemini_api.py). This PR modernizes the Gemini integration to the currentgoogle-genaiSDK.What changed
lmms_eval/models/simple/gemini.py(Gemini, registered asgemini): usesgoogle.genai, with thread-safe video/audio file upload + cache, adaptive concurrency (viamodel_utils.concurrency_control), prefix-aware request queue, safety-block salvage, and token/usage accounting (model_utils.usage_metrics).lmms_eval/models/chat/gemini.py(Gemini(GeminiSimple),is_simple=False): converts theChatMessagesprotocol to Gemini-native contents and extracts system messages intosystem_instruction.lmms_eval/models/__init__.py):geminiregistered as both a simple and a chat model;gemini_apikept as an alias ofgemini(MODEL_ALIASES["gemini"] = ("gemini_api",)) so existing--model gemini_apicommands keep working.lmms_eval/models/simple/gemini_api.py(the CLI name survives via the alias).pyproject.toml:geminiextragoogle-generativeai->google-genai>=1.0.0.lmms_eval/models/model_utils/parallel.py: small genericParallelPlan/resolve_local_rank_devicelauncher-parallelism helper (stdlib + lazy torch).Compatibility
--model geminiand legacy--model gemini_apiboth resolve to the newGeminiclass (verified via the registry manifest + alias resolution).geminiis now registered as a chat model too,--model gemini/--model gemini_apidefault to the chat backend (same convention asopenai); pass--force_simplefor the simple path. Theinterleavemodel_arg applies to the simple path only.model_versiondefaults togemini-3.5-flash(the old backend defaulted to the now-deprecatedgemini-1.5-pro); pinmodel_version=...in--model_argsif you need a specific model.num_concurrent=32with linear backoff (the old backend was serial). On low-quota keys, lower it or setadaptive_concurrency=True.Notes
pip install -e ".[gemini]"now pullsgoogle-genai>=1.0.0instead of the deprecatedgoogle-generativeai.parallel.pyhas no in-tree consumer yet; it is included as a reusable helper (feat(models): add diffusers-based world-model generation backends (Wan 2.1/2.2, Cosmos, LTX-Video, MAGI-1, fal.ai) #1389 inlines a minimal copy — dedupe at merge, whichever lands second).generate_contentonly), so long video uploads serialize; upload-in-worker is a natural next step.Review pass (2026-07-06)
Two self-review commits:
str(FileState.ACTIVE)("FILESTATE.ACTIVE") against"ACTIVE"— it never matched, so every unique video/audio upload burned the full poll budget (~120s) and FAILED uploads were never surfaced. The loop now normalizes the enum via itsnameand raises on FAILED.mime_type="audio/wav". Both backends now map extensions to Gemini-canonical MIME types (.mp3 -> audio/mp3,.flac -> audio/flac, ..., fallbackmimetypes.guess_typethenaudio/wav).