fix: forward cache_dir to ONNX and OpenVINO model loading#3691
Open
AtharvaJaiswal005 wants to merge 1 commit intohuggingface:mainfrom
Open
fix: forward cache_dir to ONNX and OpenVINO model loading#3691AtharvaJaiswal005 wants to merge 1 commit intohuggingface:mainfrom
AtharvaJaiswal005 wants to merge 1 commit intohuggingface:mainfrom
Conversation
When cache_folder is specified with backend="onnx" or backend="openvino", the cache_dir was not forwarded to load_onnx_model/load_openvino_model or to the underlying from_pretrained call. This caused a ValueError when loading cached models with local_files_only=True because the model files could not be found without the cache directory path. Fixes huggingface#3562
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cache_dirfromTransformer._load_model()toload_onnx_model()andload_openvino_model()cache_dirto the underlyingmodel_cls.from_pretrained()calls in both functionsValueErrorwhencache_folderis specified alongsidelocal_files_only=TrueRoot Cause
When using
backend="onnx"(or"openvino") with a customcache_folder, thecache_dirparameter was not forwarded through the loading chain:Transformer._load_model()receivescache_dirbut did not pass it toload_onnx_model()/load_openvino_model()(unlike the torch backend which passescache_dirtoAutoModel.from_pretrained())load_onnx_model()/load_openvino_model()did not accept or forwardcache_dirtomodel_cls.from_pretrained()This meant the ONNX/OpenVINO model loader had no knowledge of where cached files were stored, causing it to fail when
local_files_only=True.Reproduction
Changes
sentence_transformers/backend/load.py: Addedcache_dirparameter toload_onnx_model()andload_openvino_model(), forwarded tofrom_pretrained()sentence_transformers/models/Transformer.py: Passcache_dirwhen callingload_onnx_model()andload_openvino_model()in_load_model()Fixes #3562