Revert "Fix Florence2 config compatibility with transformers 5.x"
This reverts commit 31ab0275de.
This commit is contained in:
@@ -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. "
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user