Getting RuntimeError: unable to open file </root/.cache/huggingface/hub/models--sentence-transformers--all-MiniLM-L6-v2/snapshots/8b3219a92973c328a8e22fadcfa821b5dc75636a/model.safetensors> in read-only mode: No such file or directory (2)
Author: praveshkumar1988
Pull request: no
Labels: name: bug

### System Info

aiohttp==3.9.3
aiosignal==1.3.1
annotated-types==0.6.0
antlr4-python3-runtime==4.9.3
anyio==4.3.0
async-timeout==4.0.3
asyncio==3.4.3
attrs==23.2.0
backoff==2.2.1
beautifulsoup4==4.12.3
boto3==1.34.140
botocore==1.34.140
cachetools==5.3.3
certifi==2024.2.2
cffi==1.16.0
chardet==5.2.0
charset-normalizer==3.3.2
click==8.1.7
coloredlogs==15.0.1
contourpy==1.2.0
cryptography==42.0.2
cycler==0.12.1
dataclasses-json==0.6.4
dataclasses-json-speakeasy==0.5.11
Deprecated==1.2.14
distro==1.9.0
docstring_parser==0.16
effdet==0.4.1
emoji==2.10.1
exceptiongroup==1.2.0
fastapi==0.111.0
fastapi-health==0.4.0
filelock==3.13.1
filetype==1.2.0
flatbuffers==23.5.26
fonttools==4.49.0
frozenlist==1.4.1
fsspec==2024.2.0
google-api-core==2.18.0
google-auth==2.29.0
google_auth_oauthlib==1.2.0
google-cloud-aiplatform==1.58.0
google-cloud-bigquery==3.19.0
google-cloud-core==2.4.1
google-cloud-resource-manager==1.12.3
google-cloud-storage==2.17.0
google-crc32c==1.5.0
google-resumable-media==2.7.0
googleapis-common-protos==1.63.0
greenlet==3.0.3
grpc-google-iam-v1==0.13.0
grpcio==1.62.1
google-ai-generativelanguage==0.6.6
grpcio-status==1.62.1
h11==0.14.0
httpcore==1.0.4
httpx==0.27.0
huggingface-hub==0.24.3
humanfriendly==10.0
idna==3.6
importlib-resources==6.1.1
pip-install==1.3.5
iopath==0.1.10
Jinja2==3.1.3
jmespath==1.0.1
joblib==1.3.2
jsonpatch==1.33
jsonpath-python==1.0.6
jsonpointer==2.4
json-repair==0.25.2
kiwisolver==1.4.5
langchain==0.2.8
langchain-aws==0.1.9
langchain-anthropic==0.1.19
langchain-fireworks==0.1.4
langchain-google-genai==1.0.7
langchain-community==0.2.7
langchain-core==0.2.19
langchain-experimental==0.0.62
langchain-google-vertexai==1.0.6
langchain-groq==0.1.6
langchain-openai==0.1.14
langchain-text-splitters==0.2.2
langdetect==1.0.9
langsmith==0.1.83
layoutparser==0.3.4
langserve==0.2.2
#langchain-cli==0.0.25
lxml==5.1.0
MarkupSafe==2.1.5
marshmallow==3.20.2
matplotlib==3.7.2
mpmath==1.3.0
multidict==6.0.5
mypy-extensions==1.0.0
neo4j-rust-ext
networkx==3.2.1
nltk==3.8.1
numpy==1.26.4
omegaconf==2.3.0
onnx==1.16.1
onnxruntime==1.18.1
openai==1.35.10
opencv-python==4.8.0.76
orjson==3.9.15
packaging==23.2
pandas==2.2.0
pdf2image==1.17.0
pdfminer.six==20221105
pdfplumber==0.10.4
pikepdf==8.11.0
pillow==10.2.0
pillow_heif==0.15.0
portalocker==2.8.2
proto-plus==1.23.0
protobuf==4.23.4
psutil==6.0.0
pyasn1==0.6.0
pyasn1_modules==0.4.0
pycocotools==2.0.7
pycparser==2.21
pydantic==2.8.2
pydantic_core==2.20.1
pyparsing==3.0.9
pypdf==4.0.1
PyPDF2==3.0.1
pypdfium2==4.27.0
pytesseract==0.3.10
python-dateutil==2.8.2
python-dotenv==1.0.1
python-iso639==2024.2.7
python-magic==0.4.27
python-multipart==0.0.9
pytube==15.0.0
pytz==2024.1
PyYAML==6.0.1
rapidfuzz==3.6.1
regex==2023.12.25
requests==2.32.3
rsa==4.9
s3transfer==0.10.1
safetensors==0.4.1
scipy==1.10.1
shapely==2.0.3
six==1.16.0
sniffio==1.3.1
soupsieve==2.5
SQLAlchemy==2.0.28
starlette==0.37.2
sse-starlette==2.1.2
starlette-session==0.4.3
sympy==1.12
tabulate==0.9.0
tenacity==8.2.3
tiktoken==0.7.0
timm==0.9.12
tokenizers==0.19
tqdm==4.66.2
transformers==4.42.3
types-protobuf
types-requests
typing-inspect==0.9.0
typing_extensions==4.9.0
tzdata==2024.1
unstructured==0.14.9
unstructured-client==0.23.8
unstructured-inference==0.7.36
unstructured.pytesseract==0.3.12
unstructured[all-docs]==0.14.9
urllib3==2.2.2
uvicorn==0.30.1
gunicorn==22.0.0
wikipedia==1.4.0
wrapt==1.16.0
yarl==1.9.4
youtube-transcript-api==0.6.2
zipp==3.17.0
sentence-transformers==3.0.1
google-cloud-logging==3.10.0
PyMuPDF==1.24.5
pypandoc==1.13
Python===3.10.13

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

I'm creating container using docker compose up --build
Everything works fine 2 weeks ago, I'm able to replicate which API depricated from hugging face.
Can you please debug and know me knowhow to fix this.

### Expected behavior

Docker images should be created using mentioned above library version
Using below code to generate embedding 

embeddings = SentenceTransformerEmbeddings(
            model_name="all-MiniLM-L6-v2"
        )
embeddings_arr = embeddings.embed_query(row['doc'].page_content)

Comments:
cc @tomaarsen maybe, is there a `force_download` option to force the redownload of the file? I feel like there's a good chance there's a corrupted file/directory in your cache

I agree with @LysandreJik, I think your `model.safetensors` file got corrupted. I'm guessing that you're using langchain here. The Langchain implementation has a `model_kwargs` option for initializing the underlying [`SentenceTransformer`](https://sbert.net/docs/package_reference/sentence_transformer/SentenceTransformer.html#sentence_transformers.SentenceTransformer). This class also has a `model_kwargs` option for initializing the underlying `AutoModel`, which is what's failing in your setup.

So, I think this snippet should work:
```python
embeddings = SentenceTransformerEmbeddings(
    model_name="all-MiniLM-L6-v2",
    model_kwargs={ # <- For Langchain
        "model_kwargs": { # <- For Sentence Transformers
            "force_download": True # <- For Transformers
        },
    },
)
embeddings_arr = embeddings.embed_query(row['doc'].page_content)
```
Once you ran that once and you verified that it works, you can start using your original script without the `model_kwargs` again, as we only have to override the corrupt `model.safetensors` once.

- Tom Aarsen

Thanks for your help and giving options to fix this. I added --preload in docker while starting server. I think that issue is coming due to workers because all workers are in race to download sentenceTransformer.

CMD ["gunicorn", "score:app", "--workers", "8","--preload","--threads", "8", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--timeout", "300"]