nikivdev commited on
Commit
64e3aa3
·
verified ·
1 Parent(s): 2fa307b

Fix relative imports in modeling_laguna.py that break trust_remote_code loading

Browse files

Fixes the `trust_remote_code` loading failure reported in discussion #3.

`modeling_laguna.py` keeps two function-local in-tree relative imports inside `LagunaModel.forward`:

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

Inside the transformers source tree these resolve to the package root, but as Hub custom code transformers' dynamic-module scanner (`dynamic_module_utils.get_relative_imports`) collects them as sibling snapshot files to fetch, and loading dies before the model class is even built:

```
FileNotFoundError: [Errno 2] No such file or directory: '.../snapshots/.../..cache_utils.py'
```

Repro: `AutoModelForCausalLM.from_pretrained("poolside/Laguna-XS-2.1", trust_remote_code=True)` on transformers 5.12.1. (vLLM is unaffected — it never runs the scanner.)

This PR rewrites the two lines to the absolute imports they resolved to in-tree; both modules are public transformers API, so behavior is identical. Verified locally: with this change the model loads and runs forward/backward (transformers 5.12.1, torch 2.12.1, bf16).

Files changed (1) hide show
  1. modeling_laguna.py +2 -2
modeling_laguna.py CHANGED
@@ -633,8 +633,8 @@ class LagunaModel(LagunaPreTrainedModel):
633
  use_cache: bool | None = None,
634
  **kwargs: Unpack[TransformersKwargs],
635
  ) -> MoeModelOutputWithPast:
636
- from ...cache_utils import DynamicCache
637
- from ...masking_utils import create_causal_mask, create_sliding_window_causal_mask
638
 
639
  if (input_ids is None) ^ (inputs_embeds is not None):
640
  raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
 
633
  use_cache: bool | None = None,
634
  **kwargs: Unpack[TransformersKwargs],
635
  ) -> MoeModelOutputWithPast:
636
+ from transformers.cache_utils import DynamicCache
637
+ from transformers.masking_utils import create_causal_mask, create_sliding_window_causal_mask
638
 
639
  if (input_ids is None) ^ (inputs_embeds is not None):
640
  raise ValueError("You must specify exactly one of input_ids or inputs_embeds")