-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Verify blob version for cached model #32940
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f8ac5e1
Add ov version parcer. Add ov version comparison to verify cache
olpipi ad246ce
Apply comments
olpipi 3edabcd
Add tests. Fixes
olpipi 51f0658
Fix
olpipi 27ae3ed
Update regex pattern. Fix comparison policy
olpipi d724f94
Update blob version compatibility rules
olpipi f577392
Fix
olpipi cedc2b5
Revert "Fix"
olpipi 9d3e055
Fix tests and clang-format
olpipi c604a4f
Add doxygen
olpipi 45c8d6f
Fix copyright
olpipi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| // Copyright (C) 2018-2026 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| #pragma once | ||
|
|
||
| #include <limits> | ||
| #include <regex> | ||
| #include <sstream> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| #include "openvino/core/except.hpp" | ||
|
|
||
| namespace ov::util { | ||
| /** | ||
| * @brief Represents OpenVINO version with major, minor, patch, tweak, and build numbers. | ||
| * | ||
| * This structure parses and stores version information following the pattern: | ||
| * MAJOR.MINOR.PATCH[.TWEAK]-BUILD-... | ||
| * or a standalone build number. | ||
| * | ||
| * The version components can be compared using standard comparison operators. | ||
| */ | ||
| struct Version { | ||
| size_t major = 0; | ||
| size_t minor = 0; | ||
| size_t patch = 0; | ||
| size_t tweak = 0; | ||
| size_t build = 0; | ||
|
|
||
| explicit Version(const char* version_str) { | ||
| // Pattern: MAJOR.MINOR.PATCH[.TWEAK]-BUILD-... | ||
| std::regex full_pattern(R"(^([0-9]+)\.([0-9]+)\.([0-9]+)(?:\.([0-9]+))?\-([0-9]+)\-.*)"); | ||
| std::regex build_only_pattern(R"(^[0-9]+$)"); | ||
| std::cmatch match; | ||
|
|
||
| if (std::regex_match(version_str, match, full_pattern)) { | ||
| major = std::stoi(match[1].str()); | ||
| minor = std::stoi(match[2].str()); | ||
| patch = std::stoi(match[3].str()); | ||
|
|
||
| // match[4] is the entire optional group (\.TWEAK), match[5] is TWEAK | ||
| // the 4th version number is not used in OpenVINO, but used in OpenVINO extensions | ||
| if (match[4].matched) { | ||
| tweak = std::stoi(match[4].str()); | ||
| } | ||
|
|
||
| build = std::stoi(match[5].str()); | ||
| } else if (std::regex_match(version_str, build_only_pattern)) { | ||
| // Parse as just a build number | ||
| build = std::stoi(version_str); | ||
| } else { | ||
| OPENVINO_THROW("Failed to parse version: ", version_str); | ||
t-jankowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| explicit Version(std::string_view version_str) : Version(version_str.data()) {} | ||
|
|
||
| // Comparison operators | ||
| bool operator==(const Version& other) const { | ||
| return std::tie(major, minor, patch, tweak, build) == | ||
| std::tie(other.major, other.minor, other.patch, other.tweak, other.build); | ||
| } | ||
|
|
||
| bool operator!=(const Version& other) const { | ||
| return !(*this == other); | ||
| } | ||
|
|
||
| bool operator<(const Version& other) const { | ||
| return std::tie(major, minor, patch, tweak, build) < | ||
| std::tie(other.major, other.minor, other.patch, other.tweak, other.build); | ||
| } | ||
|
|
||
| bool operator>(const Version& other) const { | ||
| return other < *this; | ||
| } | ||
|
|
||
| bool operator<=(const Version& other) const { | ||
| return !(other < *this); | ||
| } | ||
|
|
||
| bool operator>=(const Version& other) const { | ||
| return !(*this < other); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Policy for determining version compatibility between two versions. | ||
| * | ||
| * This structure defines the maximum allowed difference for each version component. | ||
| * By default, all differences are allowed. | ||
| */ | ||
| struct VersionCompatibilityPolicy { | ||
| size_t max_major_diff = std::numeric_limits<size_t>::max(); | ||
| size_t max_minor_diff = std::numeric_limits<size_t>::max(); | ||
| size_t max_patch_diff = std::numeric_limits<size_t>::max(); | ||
| size_t max_tweak_diff = std::numeric_limits<size_t>::max(); | ||
| size_t max_build_diff = std::numeric_limits<size_t>::max(); | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Checks if two versions are compatible based on the given policy. | ||
| * | ||
| * This function determines whether an older version is compatible with a newer version | ||
| * by checking if the difference in each version component (major, minor, patch, tweak, build) | ||
| * is within the limits specified by the compatibility policy. | ||
| * | ||
| * @param older_version The older version to check compatibility for. | ||
| * @param newer_version The newer version to compare against. | ||
| * @param policy The compatibility policy defining maximum allowed differences for each version component. | ||
| * Default policy allows all differences. | ||
| * @return true if the versions are compatible according to the policy, false otherwise. | ||
| * Returns false if older_version is actually greater than newer_version. | ||
| */ | ||
| inline bool is_version_compatible(const Version& older_version, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can some doxy for this utils be added? Is there a test where e.g OV version 27.0 introduce compatibility brake, all caches before 2027 are not compatible. Is possible to apply such change in code? |
||
| const Version& newer_version, | ||
| const VersionCompatibilityPolicy& policy = {}) { | ||
| if (older_version > newer_version) { | ||
| return false; | ||
| } | ||
|
|
||
| // Check each version component against policy | ||
| if (newer_version.major - older_version.major > policy.max_major_diff) { | ||
| return false; | ||
| } | ||
|
|
||
| if (newer_version.minor - older_version.minor > policy.max_minor_diff) { | ||
| return false; | ||
| } | ||
|
|
||
| if (newer_version.patch - older_version.patch > policy.max_patch_diff) { | ||
| return false; | ||
| } | ||
|
|
||
| if (newer_version.tweak - older_version.tweak > policy.max_tweak_diff) { | ||
| return false; | ||
| } | ||
|
|
||
| if (newer_version.build - older_version.build > policy.max_build_diff) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } // namespace ov::util | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.