From 0e5d3510996b028ec2ce9e00bb8e6c8df834c053 Mon Sep 17 00:00:00 2001 From: CalamitousFelicitousness Date: Thu, 9 Apr 2026 03:21:50 +0100 Subject: [PATCH] add google gemma-4-e2b and gemma-4-e4b support - add to prompt enhance models, img2img, and models_cls - add to vlm/caption models - update _load_gemma class selection for gemma 4 - bump transformers pin to 5.5.0.dev for gemma4 architecture support --- installer.py | 2 +- modules/caption/models_def.py | 2 ++ modules/caption/vqa.py | 6 ++++-- scripts/prompt_enhance.py | 5 +++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/installer.py b/installer.py index 70fc19cb9..bb9aa0349 100644 --- a/installer.py +++ b/installer.py @@ -513,7 +513,7 @@ def check_transformers(): pkg_tokenizers = package_spec('tokenizers') # target_commit = '753d61104116eefc8ffc977327b441ee0c8d599f' # transformers commit hash == 4.57.6 # target_commit = "aad13b87ed59f2afcfaebc985f403301887a35fc" # transformers commit hash == 5.3.0 - target_commit = "2dba8e0495974930af02274d75bd182d22cc1686" # transformers commit hash == 5.3.0.dev-0331 + target_commit = "380e3cc5d59912a48508cb6d4959a31cd460e12e" # transformers commit hash == 5.5.0.dev-0409 if args.use_directml: target_transformers = '4.52.4' target_tokenizers = '0.21.4' diff --git a/modules/caption/models_def.py b/modules/caption/models_def.py index 7e53e2e76..f91b2e5f2 100644 --- a/modules/caption/models_def.py +++ b/modules/caption/models_def.py @@ -5,6 +5,8 @@ vlm_models = { "Google Gemma 3 4B": "google/gemma-3-4b-it", "Google Gemma 3n E2B": "google/gemma-3n-E2B-it", # 1.5GB "Google Gemma 3n E4B": "google/gemma-3n-E4B-it", # 1.5GB + "Google Gemma 4 E2B": "google/gemma-4-E2B-it", + "Google Gemma 4 E4B": "google/gemma-4-E4B-it", "Nidum Gemma 3 4B Uncensored": "nidum/Nidum-Gemma-3-4B-it-Uncensored", "Allura Gemma 3 Glitter 4B": "allura-org/Gemma-3-Glitter-4B", # Qwen3.5 diff --git a/modules/caption/vqa.py b/modules/caption/vqa.py index 807479144..74cc3cdca 100644 --- a/modules/caption/vqa.py +++ b/modules/caption/vqa.py @@ -619,11 +619,13 @@ class VQA: return response def _load_gemma(self, repo: str): - """Load Gemma 3 model and processor.""" + """Load Gemma model and processor.""" if self.model is None or self.loaded != repo: log.debug(f'Caption load: vlm="{repo}"') self._unload_current() - if '3n' in repo: + if 'gemma-4' in repo.lower(): + cls = transformers.Gemma4ForConditionalGeneration + elif '3n' in repo: cls = transformers.Gemma3nForConditionalGeneration # pylint: disable=no-member else: cls = transformers.Gemma3ForConditionalGeneration diff --git a/scripts/prompt_enhance.py b/scripts/prompt_enhance.py index b0d46bac8..e919081f9 100644 --- a/scripts/prompt_enhance.py +++ b/scripts/prompt_enhance.py @@ -109,6 +109,8 @@ class Options: 'google/gemma-3-4b-it', 'google/gemma-3n-E2B-it', 'google/gemma-3n-E4B-it', + 'google/gemma-4-E2B-it', + 'google/gemma-4-E4B-it', # Gemma Finetunes 'nidum/Nidum-Gemma-3-4B-it-Uncensored', 'allura-org/Gemma-3-Glitter-4B', @@ -173,6 +175,8 @@ class Options: 'google/gemma-3-4b-it': {}, 'google/gemma-3n-E2B-it': {}, 'google/gemma-3n-E4B-it': {}, + 'google/gemma-4-E2B-it': {}, + 'google/gemma-4-E4B-it': {}, # Gemma Finetunes 'nidum/Nidum-Gemma-3-4B-it-Uncensored': {}, 'allura-org/Gemma-3-Glitter-4B': {}, @@ -267,6 +271,7 @@ class Options: 'qwen2_5_vl': 'Qwen2_5_VLForConditionalGeneration', 'qwen2_vl': 'Qwen2VLForConditionalGeneration', 'mistral3': 'Mistral3ForConditionalGeneration', + 'gemma4': 'Gemma4ForConditionalGeneration', } # default = list(models)[1] # gemma-3-4b-it