@@ -777,7 +777,11 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
777777    if  (cacheManager && device_supports_model_caching (plugin, parsed._config ) && !is_proxy_device (plugin)) {
778778        CacheContent cacheContent{cacheManager, parsed._core_config .get_enable_mmap ()};
779779        cacheContent.blobId  = ov::ModelCache::compute_hash (model, create_compile_config (plugin, parsed._config ));
780-         cacheContent.model  = std::const_pointer_cast<ov::Model>(model);
780+         if  (auto  mode_it = parsed._config .find (ov::cache_mode.name ()); mode_it != parsed._config .end ()) {
781+             if  (mode_it->second .as <ov::CacheMode>() == ov::CacheMode::OPTIMIZE_SIZE) {
782+                 cacheContent.model  = std::const_pointer_cast<ov::Model>(model);
783+             }
784+         }
781785        std::unique_ptr<CacheGuardEntry> lock = cacheGuard.get_hash_lock (cacheContent.blobId );
782786        res = load_model_from_cache (cacheContent, plugin, parsed._config , ov::SoPtr<ov::IRemoteContext>{}, [&]() {
783787            return  compile_model_and_cache (plugin,
@@ -813,7 +817,11 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
813817        CacheContent cacheContent{cacheManager, parsed._core_config .get_enable_mmap ()};
814818        cacheContent.blobId  = ov::ModelCache::compute_hash (model, create_compile_config (plugin, parsed._config ));
815819        std::unique_ptr<CacheGuardEntry> lock = cacheGuard.get_hash_lock (cacheContent.blobId );
816-         cacheContent.model  = std::const_pointer_cast<ov::Model>(model);
820+         if  (auto  mode_it = parsed._config .find (ov::cache_mode.name ()); mode_it != parsed._config .end ()) {
821+             if  (mode_it->second .as <ov::CacheMode>() == ov::CacheMode::OPTIMIZE_SIZE) {
822+                 cacheContent.model  = std::const_pointer_cast<ov::Model>(model);
823+             }
824+         }
817825        res = load_model_from_cache (cacheContent, plugin, parsed._config , context, [&]() {
818826            return  compile_model_and_cache (plugin, model, parsed._config , context, cacheContent);
819827        });
0 commit comments