# Loading a safetensors format model using Hugging Face Transformers

**URL:** <https://discuss.huggingface.co/t/loading-a-safetensors-format-model-using-hugging-face-transformers/42974>\
**Category:** 🤗Transformers\
**Created:** [June 12, 2023, 8:27pm UTC](https://discuss.huggingface.co/t/loading-a-safetensors-format-model-using-hugging-face-transformers/42974 "2023-06-12T20:27:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yachty66](https://avatars.discourse-cdn.com/v4/letter/y/ac8455/32.png) [@yachty66](https://discuss.huggingface.co/u/yachty66)\
**Post date:** [June 12, 2023, 8:27pm UTC](https://discuss.huggingface.co/t/loading-a-safetensors-format-model-using-hugging-face-transformers/42974/1 "2023-06-12T20:27:23Z")

</div>

I try to load the ‘notstoic/pygmalion-13b-4bit-128g’ model using Hugging Face’s Transformers library. I am encountering an issue when trying to load the model, which is saved in the new safetensors format.

Here’s the code I’m using:

```python
from transformers import LlamaForCausalLM, LlamaTokenizer

tokenizer = LlamaTokenizer.from_pretrained("path/to/model")
model = LlamaForCausalLM.from_pretrained("path/to/model", use_safetensors=True)

```

However, this code results in the following error:

```auto
Traceback (most recent call last):
  File "/Users/maxhager/Projects2023/nsfw/model_run.py", line 4, in <module>
    model = LlamaForCausalLM.from_pretrained("path/to/model", use_safetensors=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maxhager/.virtualenvs/nsfw/lib/python3.11/site-packages/transformers/modeling_utils.py", line 2449, in from_pretrained
    raise EnvironmentError(
OSError: Error no file named pytorch_model.bin, tf_model.h5, model.ckpt.index or flax_model.msgpack found in directory path/to/model.

```

I’m confused by this error because I’ve set use\_safetensors=True, as the model is stored in safetensors format. In the model directory (path/to/model), I have the following files:

- 4bit-128g.safetensors
- config.json
- generation\_config.json
- pytorch\_model.bin.index.json
- special\_tokens\_map.json
- tokenizer.json
- tokenizer.model
- tokenizer\_config.json

It seems like the from\_pretrained() function is not recognizing the safetensors format and instead is looking for the typical file formats (pytorch\_model.bin, tf\_model.h5, etc).

I would appreciate if anyone could provide guidance on why this is happening and how I can successfully load this model.

---

<div class="post-metadata">

**Author:** ![SantoshScienceIO](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@SantoshScienceIO](https://discuss.huggingface.co/u/SantoshScienceIO)\
**Post date:** [July 2, 2023, 4:23am UTC](https://discuss.huggingface.co/t/loading-a-safetensors-format-model-using-hugging-face-transformers/42974/2 "2023-07-02T04:23:22Z")

</div>

Any luck? I am considering using this format

---

<div class="post-metadata">

**Author:** ![yachty66](https://avatars.discourse-cdn.com/v4/letter/y/ac8455/32.png) [@yachty66](https://discuss.huggingface.co/u/yachty66)\
**Post date:** [September 13, 2023, 8:14pm UTC](https://discuss.huggingface.co/t/loading-a-safetensors-format-model-using-hugging-face-transformers/42974/3 "2023-09-13T20:14:32Z")

</div>

send me a DM on twitter if that is something you are still caring about @MaxHager66
