"""Shared transformers 5.13 compatibility shims for custom-code vision towers.""" from __future__ import annotations from transformers.modeling_utils import PreTrainedModel _SHIM_APPLIED = False def apply_pretrained_shims() -> None: """Patch PreTrainedModel loading for remote-code models missing all_tied_weights_keys.""" global _SHIM_APPLIED if _SHIM_APPLIED: return _orig_finalize = PreTrainedModel._finalize_model_loading def _patched_finalize(model, load_config, loading_info): if not hasattr(model, "all_tied_weights_keys"): model.all_tied_weights_keys = {} return _orig_finalize(model, load_config, loading_info) PreTrainedModel._finalize_model_loading = _patched_finalize _SHIM_APPLIED = True