FileNotFoundError: chord_spelling_sheetsage2.py when loading from a local directory (since e8b16e3e44)

#5
by Dea4dj0e - opened

Hi, and thanks for SheetSage2!

Since commit e8b16e3e44 ("Correct chord spelling with local keys…"), loading the model from a local directory fails on a fresh dynamic-module cache:

FileNotFoundError: [Errno 2] No such file or directory:
'.../modules/transformers_modules/SheetSage2/chord_spelling_sheetsage2.py'

A downstream user hit this on Windows. I reproduced it on macOS with the pinned transformers==4.45.2 from requirements.txt. Loading by hub id ("m-a-p/SheetSage2") still works, so the default usage in the README isn't affected.

Reproduce

hf download m-a-p/SheetSage2 --local-dir ./SheetSage2
HF_MODULES_CACHE=$(mktemp -d) python -c "
from transformers import AutoModel
AutoModel.from_pretrained('./SheetSage2', trust_remote_code=True)"

Cause

When transformers 4.45 loads remote code from a local directory, it copies only the files that the entry module imports directly into the module cache (dynamic_module_utils.get_cached_module_file). It then hashes the recursive set of relative imports (get_class_in_module → get_relative_import_files), and that reads files the copy step never placed there. The new chord_spelling_sheetsage2.py is imported only by tokenization_sheetsage2.py and exports_sheetsage2.py, not by modeling_sheetsage2.py, so it never gets copied.

_hf_relative_dependencies() in modeling_sheetsage2.py already works around exactly this. The new module just isn't listed there. I checked the rest of the import graph, and it's the only module that's missing.

Workaround until then: copy chord_spelling_sheetsage2.py from the local model directory into /modules/transformers_modules/SheetSage2/.

Sign up or log in to comment