-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Reduce IR Constant Memory Retention #35457
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
Open
barnasm1
wants to merge
53
commits into
openvinotoolkit:master
Choose a base branch
from
barnasm1:separate_buffer_poc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
a17e69d
Implement WeightsProvider and FileWeightsProvider for flexible weight…
barnasm1 a898eb6
Merge branch 'master' into separate_buffer_poc
barnasm1 b1e8e47
fix win build
barnasm1 8b75d6f
fix win buildweight provider + prevend double budder alocatino
barnasm1 cdc4489
code format
barnasm1 a58a3f4
Merge branch 'master' into separate_buffer_poc
barnasm1 bb4e162
Merge branch 'master' into separate_buffer_poc
barnasm1 34c9047
do not use env flag
barnasm1 4d26e5d
weights loading logic if no enable mmap
barnasm1 f64c4e3
Add assertion to check if weights file can be opened in FileWeightsPr…
barnasm1 a313c19
Add FileRegionBuffer class and enhance FileWeightsProvider with sourc…
barnasm1 f1bbb4e
Merge branch 'master' into separate_buffer_poc
barnasm1 434b15f
Fix formatting
barnasm1 0b1bb5a
Remove const qualifier from load_region
barnasm1 8fac1d4
Remove unnecessary null check in BufferWeightsProvider::size()
barnasm1 d48f7d6
Merge branch 'master' into separate_buffer_poc
barnasm1 5edf87c
skip ate flag
barnasm1 22f6492
move WeightsProvider to separate file
barnasm1 3febebc
use ov util to file size
barnasm1 b9374f5
remove assertion for empty weights provider
barnasm1 a0258c8
refactor: remove load_weights_region and get_available_weights_size m…
barnasm1 f9acab0
use simpler hash function
barnasm1 df0ae2a
documentation for WeightsProvider interface
barnasm1 7776a19
refactor: remove FileRegionBuffer class and simplify load_region meth…
barnasm1 8b63fd4
Merge branch 'master' into separate_buffer_poc
barnasm1 1be1fb9
Revert "refactor: remove FileRegionBuffer class and simplify load_reg…
barnasm1 4133e84
Merge branch 'master' into separate_buffer_poc
barnasm1 e89b25d
add assertions for weights provider in XmlDeserializer. fix test: mod…
barnasm1 cb9a012
rename load_region to make_region
barnasm1 36322dd
add comment to m_loaded_weights_regions key
barnasm1 22b5f2a
simplify assert
barnasm1 c94a6f9
rename load_region to make_region - fix build
barnasm1 67b68a2
revert weight size checks
barnasm1 7e06fcc
update weight assertion message and add check for weights size
barnasm1 522ebf3
Merge branch 'master' into separate_buffer_poc
barnasm1 a77e0c0
Fix error message formatting in weight file assertions
barnasm1 ab6624c
use lazy_buffer
barnasm1 5039491
Merge branch 'master' into separate_buffer_poc
mlukasze 979b018
FileWeightsProvider fix CI
barnasm1 d8dc9a2
Merge branch 'master' into separate_buffer_poc
barnasm1 e3af9ec
Merge branch 'master' into separate_buffer_poc
barnasm1 de95e5f
init all or none
barnasm1 ec779b3
avoid double check
barnasm1 afb3465
Refactor XmlDeserializer to use WeightsProvider for weight management
barnasm1 671dc06
Refactor FileWeightsProvider to remove FileRegionBuffer and optimize …
barnasm1 a9f499e
Add weights_provider source and header to xml_util CMakeLists
barnasm1 1ae4bb5
Refactor InputModelIRImpl constructor to initialize weights_provider …
barnasm1 90e5ae7
Refactor InputModelIRImpl to remove weights_path parameter and utiliz…
barnasm1 d8cb394
Merge branch 'master' into separate_buffer_poc
barnasm1 3e5501d
Merge branch 'master' into separate_buffer_poc
barnasm1 d93206a
Refactor XmlDeserializer to use const reference for weights_provider
barnasm1 0190e63
Change loaded_weights_regions from shared_ptr to weak_ptr
barnasm1 6c88331
Refactor parse_pre_process to use shared_ptr for Constant creation
barnasm1 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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
|
|
||
| #pragma once | ||
|
|
||
| #include <cstddef> | ||
| #include <filesystem> | ||
| #include <functional> | ||
| #include <map> | ||
| #include <pugixml.hpp> | ||
|
|
@@ -45,10 +47,46 @@ void str_to_container(const std::string& value, T& res) { | |
| template <> | ||
| void str_to_container<std::vector<std::string>>(const std::string& value, std::vector<std::string>& res); | ||
|
|
||
| class WeightsProvider { | ||
| public: | ||
| virtual ~WeightsProvider() = default; | ||
|
|
||
| virtual std::shared_ptr<ov::AlignedBuffer> load_region(size_t offset, size_t size) const = 0; | ||
|
praasz marked this conversation as resolved.
Outdated
|
||
| virtual size_t size() const = 0; | ||
| }; | ||
|
|
||
| class BufferWeightsProvider : public WeightsProvider { | ||
| public: | ||
| explicit BufferWeightsProvider(std::shared_ptr<ov::AlignedBuffer> weights); | ||
|
|
||
| std::shared_ptr<ov::AlignedBuffer> load_region(size_t offset, size_t size) const override; | ||
| size_t size() const override; | ||
|
|
||
| private: | ||
| std::shared_ptr<ov::AlignedBuffer> m_weights; | ||
| }; | ||
|
|
||
| class FileWeightsProvider : public WeightsProvider { | ||
| public: | ||
| explicit FileWeightsProvider(std::filesystem::path weights_path); | ||
|
|
||
| std::shared_ptr<ov::AlignedBuffer> load_region(size_t offset, size_t size) const override; | ||
| size_t size() const override; | ||
|
|
||
| private: | ||
| using WeightsRegionKey = std::pair<size_t, size_t>; | ||
|
|
||
| std::filesystem::path m_weights_path; | ||
| size_t m_weights_size = 0; | ||
| size_t m_weights_source_id = 0; | ||
| std::shared_ptr<ov::AlignedBuffer> m_weights_source_handle; | ||
|
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. It keeps the data source buffer + buffer in the map. |
||
| mutable std::map<WeightsRegionKey, std::shared_ptr<ov::AlignedBuffer>> m_loaded_weights_regions; | ||
|
barnasm1 marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| class XmlDeserializer : public ov::AttributeVisitor { | ||
| public: | ||
| explicit XmlDeserializer(const pugi::xml_node& node, | ||
| const std::shared_ptr<ov::AlignedBuffer>& weights, | ||
| std::shared_ptr<WeightsProvider> weights_provider, | ||
| const std::unordered_map<std::string, ov::OpSet>& opsets, | ||
| const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions, | ||
| std::unordered_map<std::string, std::shared_ptr<ov::op::util::Variable>>& variables, | ||
|
|
@@ -77,8 +115,8 @@ class XmlDeserializer : public ov::AttributeVisitor { | |
| virtual void set_constant_num_buffer(ov::AttributeAdapter<std::shared_ptr<ov::AlignedBuffer>>& adapter); | ||
|
|
||
| const pugi::xml_node& get_node() const; | ||
| const std::shared_ptr<ov::AlignedBuffer>& get_weights() const { | ||
| return m_weights; | ||
| const std::shared_ptr<WeightsProvider>& get_weights_provider() const { | ||
|
barnasm1 marked this conversation as resolved.
|
||
| return m_weights_provider; | ||
| } | ||
|
|
||
| private: | ||
|
|
@@ -106,10 +144,8 @@ class XmlDeserializer : public ov::AttributeVisitor { | |
|
|
||
| /// \brief Traverses xml node representation in order to create ov function for it. | ||
| /// \param node xml node representation | ||
| /// \param weights weights attached to current node | ||
| /// \return shared pointer to function representing input node | ||
| std::shared_ptr<ov::Model> parse_function(const pugi::xml_node& root, | ||
| const std::shared_ptr<ov::AlignedBuffer>& weights); | ||
| std::shared_ptr<ov::Model> parse_function(const pugi::xml_node& root); | ||
| /// \brief Traverses xml node representation in order to get the purpose attribute of | ||
| /// inputs/outputs in the body of Loop op. \param node xml node representation \return struct | ||
| /// with value of purpuse attribute | ||
|
|
@@ -119,7 +155,6 @@ class XmlDeserializer : public ov::AttributeVisitor { | |
|
|
||
| std::shared_ptr<ov::Node> create_node(const ov::OutputVector& inputs, | ||
| const pugi::xml_node& node, | ||
| const std::shared_ptr<ov::AlignedBuffer>& weights, | ||
| const GenericLayerParams& params); | ||
|
|
||
| void read_meta_data(const std::shared_ptr<ov::Model>& model, const pugi::xml_node& meta_section); | ||
|
|
@@ -130,17 +165,19 @@ class XmlDeserializer : public ov::AttributeVisitor { | |
|
|
||
| virtual std::unique_ptr<XmlDeserializer> make_visitor( | ||
| const pugi::xml_node& node, | ||
| const std::shared_ptr<ov::AlignedBuffer>& weights, | ||
|
praasz marked this conversation as resolved.
|
||
| const std::unordered_map<std::string, ov::OpSet>& opsets, | ||
| const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& extensions, | ||
| std::unordered_map<std::string, std::shared_ptr<ov::op::util::Variable>>& variables, | ||
| size_t version) const { | ||
| return std::make_unique<XmlDeserializer>(node, weights, opsets, extensions, variables, version); | ||
| return std::make_unique<XmlDeserializer>(node, get_weights_provider(), opsets, extensions, variables, version); | ||
| } | ||
|
|
||
| std::shared_ptr<ov::AlignedBuffer> load_weights_region(size_t offset, size_t size) const; | ||
| size_t get_available_weights_size() const; | ||
|
barnasm1 marked this conversation as resolved.
Outdated
|
||
|
|
||
| // -- DATA -- | ||
| const pugi::xml_node m_node; | ||
| const std::shared_ptr<ov::AlignedBuffer>& m_weights; | ||
| const std::shared_ptr<WeightsProvider> m_weights_provider; | ||
| const std::unordered_map<std::string, ov::OpSet>& m_opsets; | ||
| const std::unordered_map<ov::DiscreteTypeInfo, ov::BaseOpExtension::Ptr>& m_extensions; | ||
| std::unordered_map<std::string, std::shared_ptr<ov::op::util::Variable>>& m_variables; | ||
|
|
@@ -150,7 +187,6 @@ class XmlDeserializer : public ov::AttributeVisitor { | |
| /// it will be used during Inputs/Outputs Description creation in SubGraph processing | ||
| /// | ||
| IoMap io_map; | ||
|
|
||
| int64_t m_version; | ||
| }; | ||
|
|
||
|
|
||
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
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.