From d55bd6acbbc8a479c8d25d13d37b97d8276c1d63 Mon Sep 17 00:00:00 2001 From: Gang Wen Date: Mon, 6 Apr 2026 21:34:45 +0200 Subject: [PATCH] Revert "Fix Florence2 config compatibility with transformers 5.x" This reverts commit 31ab0275de027324b7eeaf5e900b267fcd3cd077. --- florence2_models/configuration_florence2.py | 2 +- py/florence2_ultra.py | 15 --------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/florence2_models/configuration_florence2.py b/florence2_models/configuration_florence2.py index 3b29888..622f749 100644 --- a/florence2_models/configuration_florence2.py +++ b/florence2_models/configuration_florence2.py @@ -262,7 +262,7 @@ class Florence2LanguageConfig(PretrainedConfig): ) # ensure backward compatibility for BART CNN models - if getattr(self, 'forced_bos_token_id', None) is None and kwargs.get("force_bos_token_to_be_generated", False): + if self.forced_bos_token_id is None and kwargs.get("force_bos_token_to_be_generated", False): self.forced_bos_token_id = self.bos_token_id warnings.warn( f"Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. " diff --git a/py/florence2_ultra.py b/py/florence2_ultra.py index ffcd8eb..a6374b3 100644 --- a/py/florence2_ultra.py +++ b/py/florence2_ultra.py @@ -43,19 +43,6 @@ def fixed_get_imports(filename) -> list[str]: pass return imports -def _patch_florence2_config_compat(): - """Patch PretrainedConfig for transformers 5.x compatibility. - - In transformers 5.x, generation-related attributes like forced_bos_token_id - were moved to GenerationConfig and are no longer set by PretrainedConfig. - Florence2's custom config code accesses self.forced_bos_token_id, which - raises AttributeError without this patch. - """ - from transformers.configuration_utils import PretrainedConfig - for attr in ('forced_bos_token_id', 'forced_eos_token_id'): - if not hasattr(PretrainedConfig, attr): - setattr(PretrainedConfig, attr, None) - def load_model(version): florence_path = os.path.join(folder_paths.models_dir, "florence2") os.makedirs(florence_path, exist_ok=True) @@ -69,8 +56,6 @@ def load_model(version): from huggingface_hub import snapshot_download snapshot_download(repo_id=repo_id, local_dir=model_path, ignore_patterns=["*.md", "*.txt"]) - _patch_florence2_config_compat() - try: with patch("transformers.dynamic_module_utils.get_imports", fixed_get_imports): # model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)