model in closed network
Hi there
is it possible to download the model and run it in a closed, offline network? and if it is, how?
Thanks
Hey @iamwhoiamm - Transformers uses a "cache" mechanism, meaning the model weights are saved to disk the first time you load them. If you subsequently load the weights again in offline mode, the weights will simply be loaded from the cached file.
As an example, run the following in online mode:
from transformers import WhisperForConditionalGeneration
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny")
You'll see that the weights are downloaded to the default cache dir, which is:
~/.cache/huggingface/hub/models--openai--whisper-tiny/snapshots/167c219b21f11ef214220b8fdb7536b8a88c2475
If you inspect this folder, you'll see the model weights present (model.safetensors
):
ls ~/.cache/huggingface/hub/models--openai--whisper-tiny/snapshots/167c219b21f11ef214220b8fdb7536b8a88c2475
Gives:
added_tokens.json merges.txt preprocessor_config.json tokenizer_config.json
config.json model.safetensors special_tokens_map.json vocab.json
generation_config.json normalizer.json tokenizer.json
Now, if we re-run the code-snippet again in offline mode, Transformers will load the model weights from this cached folder. There are no code changes required to do this. If in offline mode, Transformers will loaded the model weights from the latest cache dir. If in online mode, Transformers will check that the cache dir is up to date with the weights on the Hub, and only re-download them if there have been any changes. So the command for running offline is simply:
from transformers import WhisperForConditionalGeneration
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-tiny")
You can also "force" offline mode by following this guide, as well as update your default cache dir: https://huggingface.co/docs/transformers/v4.37.2/en/installation#offline-mode
and how do you use this model to actually transcribe an audio file? the example in the model card uses a different class...