modeling_laguna.py: in-tree relative imports break trust_remote_code loading on transformers v5 (OSError: ..cache_utils.py not found)

#3
by nikivdev - opened

Loading the model with remote code fails on transformers 5.x (verified on 5.12.1):

from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("poolside/Laguna-XS-2.1", trust_remote_code=True)
OSError: poolside/Laguna-XS-2.1 does not appear to have a file named ..cache_utils.py.
Checkout 'https://huggingface.co/poolside/Laguna-XS-2.1/tree/main' for available files.

It fails while resolving the remote module, before any weights are fetched. Loading from a local snapshot directory fails the same way (there as FileNotFoundError: ..cache_utils.py).

Cause

modeling_laguna.py has two function-local, in-tree-style relative imports at the top of LagunaModel.forward (lines 636–637):

from ...cache_utils import DynamicCache
from ...masking_utils import create_causal_mask, create_sliding_window_causal_mask

They look like leftovers from the in-tree transformers/models/laguna/ layout. transformers' dynamic-module machinery (get_relative_imports in dynamic_module_utils.py) scans a remote-code file for every from .<module> import … and tries to fetch <module>.py as a sibling file from the repo — for these two lines that means ..cache_utils.py / ..masking_utils.py, which don't exist, so from_pretrained aborts.

Suggested fix

All three names are already imported absolutely at the top of the same file (lines 32, 35, 42):

from transformers.cache_utils import DynamicCache
from transformers.masking_utils import create_causal_mask
from transformers.masking_utils import create_sliding_window_causal_mask

so the two function-local import lines can simply be deleted (or replaced with those absolute forms). from .configuration_laguna import LagunaConfig is the only other relative import in the file and is fine (the sibling file exists).

Until this is fixed, every trust_remote_code=True consumer has to patch the downloaded snapshot by hand before the model will load.

Sign up or log in to comment