-
Notifications
You must be signed in to change notification settings - Fork 124
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
Do not automatically cache models in temp dirs #462
Conversation
The documentation is not available anymore as the PR was closed or merged. |
Path.is_relative_to() was added in Python 3.9
Speedup is small on the Github Actions runner hardware so this test regularly fails even with a speedup threshold of only 1.1
The tests failed at: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the fix @helena-intel
@@ -339,11 +339,11 @@ def compile(self): | |||
if self.request is None: | |||
logger.info(f"Compiling the model to {self._device} ...") | |||
ov_config = {**self.ov_config} | |||
if "CACHE_DIR" not in self.ov_config.keys(): | |||
# Set default CACHE_DIR only if it is not set. | |||
if "CACHE_DIR" not in self.ov_config.keys() and not str(self.model_save_dir).startswith(gettempdir()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about :
if "CACHE_DIR" not in self.ov_config.keys() and not str(self.model_save_dir).startswith(gettempdir()): | |
if "CACHE_DIR" not in self.ov_config.keys() and not isinstance(self.model_save_dir, TemporaryDirectory): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tested this, this evaluated to False, model_save_dir was a PosixPath, not a TemporaryDirectory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you share an example so that I can try to reproduce it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from tempfile import TemporaryDirectory
from optimum.intel.openvino import OVModelForSequenceClassification
model = OVModelForSequenceClassification.from_pretrained("hf-internal-testing/tiny-random-distilbert", export=True)
print(type(model.model_save_dir))
print(isinstance(model.model_save_dir, TemporaryDirectory))
(you can also add these prints to modeling_base.py)
@@ -466,7 +484,6 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): | |||
"pegasus", | |||
) | |||
GENERATION_LENGTH = 100 | |||
SPEEDUP_CACHE = 1.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer we keep the test and set SPEEDUP_CACHE
to 1 (as inference when leveraging the pkv should not be slower than without )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, doesn't it mean that there is a serious issue for model inference with use_cache=True
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Github Actions runner (Skylake with 2 cores) that is probably. But I don't expect that that's common for inference in production. On more recent Xeon I don't see this issue, use_cache is faster than without.
if "CACHE_DIR" in self.ov_config.keys() | ||
else {**self.ov_config, "CACHE_DIR": str(encoder_cache_dir)} | ||
) | ||
ov_encoder_config = self.ov_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't want to modify self.ov_config
by adding a cache path specific to the encoder / decoder component so I think we should create a copy that we can modify instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will fix that!
Currently, CACHE_DIR for exported models is set to a temporary directory unique to the model export. This is not useful, the cache will never be used. It also can cause issues with large exported models on GPU (model loading crashes).
This PR disables automatic model caching if the model save directory is a temporary directory. That doesn't just affect exported models, automatic model caching is now also disabled if users manually save models in /tmp (or Windows equivalent) - but I do not think that that is an issue. Users can always enable model caching manually by setting CACHE_DIR.
I also aligned the cache dir for diffusion models with other models, so now all cache dirs are in a specific _cache directory (previously for stable diffusion the cache dir was the model dir).