Offline use not working
I cloned moondream2 files from huggingface and copied it to a pc that doesn't connect to internet. When trying to load as shown in 'usage' section here
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained(
"/root/moondream2",
revision="2025-01-09",
trust_remote_code=True,
# Uncomment to run on GPU.
# device_map={"": "cuda"}
)
I keep getting load error such as the one below for one module or the other.
FileNotFoundError: [Errno 2] No such file or directory: '/root/.cache/huggingface/modules/transformers_modules/layers.py'
I copied the entire contents of the downloaded folder to cache
cp /root/moondream2/*.* /root/.cache/huggingface/modules/transformers_modules/
And then I have this error
File "/root/.cache/huggingface/modules/transformers_modules/hf_moondream.py", line 3, in <module>
from .config import MoondreamConfig
ModuleNotFoundError: No module named 'transformers_modules.config'
At wits end trying to make this work. Not a python pro. But all other models i tried from hf like qwen2 3B,qwen2.5 3B, microsoft phi, deep-seek vl, etc all work fine. Can someone help?
Same problem(sad
This is the hacky way I got it working:
- Download model data from https://huggingface.co/vikhyatk/moondream2/tree/main
- Copy all files from "DOWNLOADED/MODEL/PATH/" into "DOWNLOADED/MODEL/PATH/transformers_modules/moondream_data/"
- Instantiate the model with the following code:
import os
MOONDREAM_MODEL_DATA_DIR = "DOWNLOADED/MODEL/PATH"
# Set the hugging face cache directory before importing transformers
os.environ["HF_MODULES_CACHE"] = MOONDREAM_MODEL_DATA_DIR
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
pretrained_model_name_or_path=MOONDREAM_MODEL_DATA_DIR,
cache_dir=MOONDREAM_MODEL_DATA_DIR,
trust_remote_code=True,
local_files_only=True,
)
A bit hacky, I know. If anyone finds a better way to get it working, let me know!
Or you can copy the default folder structure and content to the target machine: if the machine allows, downloading it on the PC with Internet by calling the transformers etc. and then copy the cache folders as they are by default:
"$HF_HOME/hub" (e.g. "~/.cache/huggingface/hub" by default). ... etc.
(or on Windows:
C:\Users\mooner\.cache\huggingface\hub\models--vikhyatk--moondream2\ ...
blobs, refs, snapshots ...
I had similar errors these days, fast Internet, but I wanted to avoid using the default cache directory in the system disk and save to another drive. My solution was to set the Huggingface cache environment variable to the folder where I wanted the models to be, and let it download the files there once, and then it used the cached files.
https://huggingface.co/docs/huggingface_hub/en/package_reference/environment_variables https://huggingface.co/docs/huggingface_hub/v0.25.1/en/guides/manage-cache
Sort of:
os.environ['HF_HUB_CACHE']="D:\\...\\hug\\cache\\"
(or set HF_HUB_CACHE=D:\... or ... export ... Win/Linux)
or HF_HOME.
Defaults to "~/.cache/huggingface" unless [XDG_CACHE_HOME](https://huggingface.co/docs/huggingface_hub/en/package_reference/environment_variables#xdgcachehome) is set.