Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable automatic CACHE_DIR for GPU inference only #520

Merged
merged 2 commits into from
Jan 23, 2024

Conversation

helena-intel
Copy link
Collaborator

@helena-intel helena-intel commented Jan 17, 2024

Setting CACHE_DIR used to speed up model loading on both CPU and GPU, but recent model loading improvements in OpenVINO mean that on CPU it is now faster to load the model without setting CACHE_DIR. I tested this with several kinds of models, on Core and Xeon. Loading without cache can be about three times faster. On GPU loading from cache is still about three times faster (tested with ARC770). This PR enables automatic CACHE_DIR only when device is explicitly set to GPU.

For seq2seq models the ov_config was set on init, but because models can also be moved to GPU with .to() the setting of CACHE_DIR should now be done on compiling the model. The OVDecoder and OVEncoder had no concept of a model_save_dir. I added a parent_model to the constructor to get access to this.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @helena-intel !

for device in ("AUTO", "AUTO:CPU"):
model = OVModelForCausalLM.from_pretrained(model_id, export=True, use_cache=True, device=device)
OV_MODEL_ID = "echarlaix/distilbert-base-uncased-finetuned-sst-2-english-openvino"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be moved outside loop

optimum/intel/openvino/modeling_seq2seq.py Show resolved Hide resolved
@echarlaix echarlaix merged commit 672c022 into main Jan 23, 2024
12 of 14 checks passed
@echarlaix echarlaix deleted the helena/disable-cpu-cachedir branch January 23, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants