Skip to content

Reduce IR Constant Memory Retention#35457

Open
barnasm1 wants to merge 25 commits into
openvinotoolkit:masterfrom
barnasm1:separate_buffer_poc
Open

Reduce IR Constant Memory Retention#35457
barnasm1 wants to merge 25 commits into
openvinotoolkit:masterfrom
barnasm1:separate_buffer_poc

Conversation

@barnasm1
Copy link
Copy Markdown
Contributor

@barnasm1 barnasm1 commented Apr 22, 2026

Details:

Tickets:

AI Assistance:

  • AI assistance used: yes
  • If yes, summarize how AI was used and what human validation was performed (build/tests/manual checks).

@barnasm1 barnasm1 requested review from a team as code owners April 22, 2026 07:49
@barnasm1 barnasm1 self-assigned this Apr 22, 2026
@github-actions github-actions Bot added category: Core OpenVINO Core (aka ngraph) category: IR FE OpenVINO IR v10 / v11 FrontEnd labels Apr 22, 2026
@barnasm1 barnasm1 added do_not_merge and removed category: Core OpenVINO Core (aka ngraph) category: IR FE OpenVINO IR v10 / v11 FrontEnd labels Apr 22, 2026
@github-actions github-actions Bot added category: Core OpenVINO Core (aka ngraph) category: IR FE OpenVINO IR v10 / v11 FrontEnd labels Apr 22, 2026

const auto separate_const_weights_loading = use_separate_const_weights_loading() && !weights;
if (separate_const_weights_loading) {
weights_provider = std::make_shared<ov::util::FileWeightsProvider>(weights_path);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same use should be if input is stream not only for path

@barnasm1 barnasm1 requested review from a team as code owners May 6, 2026 11:58
@github-actions github-actions Bot added the category: CPU OpenVINO CPU plugin label May 6, 2026
@t-jankowski t-jankowski self-assigned this May 15, 2026
Comment thread src/frontends/ir/src/input_model.cpp Outdated
input_type.size());
}
if (const_offset + const_size > weights->size()) {
OPENVINO_ASSERT(weights_provider, "Empty weights data in bin file or bin file cannot be found!");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This assertion should be moved level up - it's local function which should operate in valid context.
I suppose InputModelIRImpl ctor should assert valid m_weights_provider, or even it's creator (since it's Impl)

Comment thread src/frontends/ir/src/frontend.cpp Outdated

namespace {

class FileRegionBuffer : public ov::AlignedBuffer {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this buffer is required what is different from shared buffer?

Comment thread src/core/xml_util/include/openvino/xml_util/xml_deserialize_util.hpp Outdated
public:
virtual ~WeightsProvider() = default;

virtual std::shared_ptr<ov::AlignedBuffer> load_region(size_t offset, size_t size) const = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
virtual std::shared_ptr<ov::AlignedBuffer> load_region(size_t offset, size_t size) const = 0;
virtual void load(size_t offset, size_t size) = 0;

It suggest to load data and modify the instance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

why should it return void?

Comment thread src/core/xml_util/src/xml_deserialize_util.cpp Outdated
std::shared_ptr<ov::util::WeightsProvider> make_buffer_weights_provider(
const std::shared_ptr<ov::AlignedBuffer>& weights) {
if (!weights) {
return nullptr;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why null should be provided if there is not weights. Is possible to read such model?

Comment thread src/core/xml_util/src/xml_deserialize_util.cpp Outdated
Comment thread src/core/xml_util/src/xml_deserialize_util.cpp Outdated
weights_stream.seekg(static_cast<std::streamoff>(offset), std::ios::beg);
OPENVINO_ASSERT(weights_stream.good(), "Failed to seek weights file ", m_weights_path, " to offset ", offset);

auto buffer = std::make_shared<FileRegionBuffer>(size, m_weights_source_id, offset, m_weights_source_handle);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

emplace it in map?

Copy link
Copy Markdown
Contributor Author

@barnasm1 barnasm1 May 28, 2026

Choose a reason for hiding this comment

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

return found->second;
}

std::ifstream weights_stream(m_weights_path, std::ios::binary);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it required to open each time?
Can be opened during the while de-serialization process and closed when de-serializer removed with weight provider.
Consider bloc write during read to ensure file do not mutate on read?

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It keeps the data source buffer + buffer in the map.
Is there no data duplication?
Will this provider will not live too long that data buffers set in Constant node will be not blocked to be removed if Constant node removed?

@praasz praasz self-assigned this May 18, 2026
@praasz praasz added this to the 2026.3 milestone May 18, 2026
@barnasm1 barnasm1 changed the title [WIP]Reduce IR Constant Memory Retention Reduce IR Constant Memory Retention May 28, 2026
Comment thread src/core/xml_util/include/openvino/xml_util/weights_provider.hpp
Comment thread src/core/xml_util/src/weights_provider.cpp Outdated
Comment thread src/core/xml_util/src/weights_provider.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: Core OpenVINO Core (aka ngraph) category: CPU OpenVINO CPU plugin category: IR FE OpenVINO IR v10 / v11 FrontEnd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants