No module named 'transformers_modules.moondream2.fourier_features'

#45
by Hangover3832 - opened

Hi
I get a ModuleNotFoundError: No module named 'transformers_modules.moondream2.fourier_features' when I try to use the latest (2024-08-26) model if it is loaded from a local path. The files (fourier_features.py etc) are there. Any clues?

Unfortunately not... would recommend opening an issue with HF transformers

Hi,

Based on the logs, it seems the fourier_features module is being imported from transformers_modules.moondream2 rather than directly from the directory containing the local model files. This happens because Hugging Face uses a cached directory for dynamic imports when trust_remote_code=True.
To resolve this issue, you can bypass AutoModelForCausalLM and directly import the custom model class from your local directory. Here's how you can do it:

import sys
sys.path.append("local_model_directory")
from hf_moondream import HfMoondream

model = HfMoondream.from_pretrained("local_model_directory")

This approach skips the AutoModelForCausalLM mechanism, which attempts to use dynamic imports, and directly loads the model class from your local files.

Let me know if this works for you!

@karszyma Thank you
I get the following error:

  File "C:\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-Hangover-Moondream\ho_moondream.py", line 148, in interrogate
    from hf_moondream import HfMoondream
  File "C:\ComfyUI_windows_portable\ComfyUI\models\moondream2\hf_moondream.py", line 3, in <module>
    from .config import MoondreamConfig
ImportError: attempted relative import with no known parent package

Sorry, my bad. Please change the code to:

import sys
sys.path.append("C:\\ComfyUI_windows_portable\\ComfyUI\\models")
from moondream2.hf_moondream import HfMoondream

model = HfMoondream.from_pretrained("C:\\ComfyUI_windows_portable\\ComfyUI\\models\\moondream2")

Let me know if this works!

Sign up or log in to comment