Spaces:
Sleeping
Sleeping
Kyryll Kochkin commited on
Commit ·
efc975c
1
Parent(s): 4e203da
AI tries to fix tests v4
Browse files51 unmodified lines525354555657233 unmodified lines29129229329429529629729829930030151 unmodified linesreturn {key: value for key, value in kwargs.items() if key in supported_kwargs}def _install_tie_weights_compat_patch(model,*,233 unmodified linesmodeling_utils.PreTrainedModel._load_pretrained_model = classmethod(_patched_load_pretrained_func)try:model = AutoModelForCausalLM.from_pretrained(spec.hf_repo,device_map=device_map,**model_kwargs,)finally:modeling_utils.PreTrainedModel._load_pretrained_model = _restore_loader_attrlogger.info("Model ready in %.2fs", time.perf_counter() - t1)51 unmodified lines525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104233 unmodified lines33833934034134234334434534634734834935035135235335435535635735835936036136236336436536651 unmodified linesreturn {key: value for key, value in kwargs.items() if key in supported_kwargs}def _is_tie_weights_unexpected_kwarg_error(exc: Exception) -> bool:message = str(exc)return "tie_weights" in message and "unexpected keyword argument" in messagedef _iter_subclasses(cls: type) -> Generator[type, None, None]:for sub in cls.__subclasses__():yield subyield from _iter_subclasses(sub)def _install_global_tie_weights_compat_patch() -> Callable[[], None]:"""Patch loaded PreTrainedModel subclasses to absorb unsupported kwargs."""from transformers import modeling_utilsbase_cls = modeling_utils.PreTrainedModelclasses = [base_cls, *_iter_subclasses(base_cls)]restore_stack: list[tuple[type, object]] = []for cls in classes:if "tie_weights" not in cls.__dict__:continueoriginal_attr = cls.__dict__["tie_weights"]original_callable = _unwrap_bound_callable(getattr(cls, "tie_weights"))def _make_compat(callable_impl):def _compat_tie_weights(self, *args, **kwargs):filtered_kwargs = _filter_supported_kwargs(callable_impl, kwargs)try:return callable_impl(self, *args, **filtered_kwargs)except TypeError as error:if kwargs and "unexpected keyword argument" in str(error):return callable_impl(self, *args)raisereturn _compat_tie_weightssetattr(cls, "tie_weights", _make_compat(original_callable))restore_stack.append((cls, original_attr))def _restore() -> None:for cls, original_attr in reversed(restore_stack):setattr(cls, "tie_weights", original_attr)return _restoredef _install_tie_weights_compat_patch(model,*,233 unmodified linesmodeling_utils.PreTrainedModel._load_pretrained_model = classmethod(_patched_load_pretrained_func)try:try:model = AutoModelForCausalLM.from_pretrained(spec.hf_repo,device_map=device_map,**model_kwargs,)except TypeError as exc:if not _is_tie_weights_unexpected_kwarg_error(exc):raiselogger.warning("Retrying model load for %s after tie_weights kwarg mismatch: %s",spec.hf_repo,exc,)restore_global_tie_weights = _install_global_tie_weights_compat_patch()try:model = AutoModelForCausalLM.from_pretrained(spec.hf_repo,device_map=device_map,**model_kwargs,)finally:restore_global_tie_weights()finally:modeling_utils.PreTrainedModel._load_pretrained_model = _restore_loader_attrlogger.info("Model ready in %.2fs", time.perf_counter() - t1)
app/core/engine.py+70-5