-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[Transformations][GPU] Constant tensor deduplication pass #29052
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
Conversation
src/common/transformations/src/transformations/common_optimizations/constants_reduce.cpp
Outdated
Show resolved
Hide resolved
src/common/transformations/src/transformations/common_optimizations/constants_reduce.cpp
Outdated
Show resolved
Hide resolved
src/common/transformations/src/transformations/common_optimizations/constants_reduce.cpp
Outdated
Show resolved
Hide resolved
src/common/transformations/src/transformations/common_optimizations/constants_reduce.cpp
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,22 @@ | |||
// Copyright (C) 2024 Intel Corporation |
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.
// Copyright (C) 2024 Intel Corporation | |
// Copyright (C) 2025 Intel Corporation |
@@ -0,0 +1,110 @@ | |||
// Copyright (C) 2024 Intel Corporation |
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.
// Copyright (C) 2024 Intel Corporation | |
// Copyright (C) 2025 Intel Corporation |
namespace ov { | ||
namespace pass { | ||
|
||
class TRANSFORMATIONS_API ConstantsReduce : public ov::pass::GraphRewrite { |
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.
usually we use ov::pass::GraphRewrite
as a container for matcher passes to execute them efficiently
it's better to use ModelPass
instead of GraphRewrite
if you do not plan to combine several matchers inside this transformation
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.
also we can change it to MatherPass
and match a constant with a condition (predicate)
e.g. predicate = const_node->get_byte_size() > 256
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.
How so?
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.
|
||
class TRANSFORMATIONS_API ConstantsReduce : public ov::pass::GraphRewrite { | ||
public: | ||
OPENVINO_GRAPH_REWRITE_RTTI("ConstantsReduce"); |
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.
please use OPENVINO_MODEL_PASS_RTTI
or OPENVINO_MATCHER_PASS_RTTI
according to the comment above
#include "openvino/pass/graph_rewrite.hpp" | ||
|
||
namespace ov { | ||
namespace pass { |
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.
minor: we can use c++17 standart here:
namespace ov::pass {
|
||
int copies = 0; | ||
|
||
const std::vector<std::shared_ptr<ov::Node>> ops = m->get_ops(); |
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.
const std::vector<std::shared_ptr<ov::Node>> ops = m->get_ops(); | |
const auto& ops = m->get_ops(); |
auto const_node = ov::as_type_ptr<op::v0::Constant>(op); | ||
|
||
// Limit size of node reading to avoid reading large tensors | ||
if (const_node->get_byte_size() > 256) continue; |
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.
it's better to define a macro variable to make 256 more visible and informative
e.g.
#define LARGE_TENSOR_BYTE_SIZE 256
src/common/transformations/src/transformations/common_optimizations/constants_reduce.cpp
Show resolved
Hide resolved
src/common/transformations/src/transformations/common_optimizations/constants_reduce.cpp
Show resolved
Hide resolved
src/common/transformations/src/transformations/common_optimizations/constants_reduce.cpp
Show resolved
Hide resolved
class TRANSFORMATIONS_API ConstantsReduce : public ov::pass::GraphRewrite { | ||
public: | ||
OPENVINO_GRAPH_REWRITE_RTTI("ConstantsReduce"); | ||
ConstantsReduce(); |
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.
ConstantsReduce(); | |
ConstantsReduce() = default; |
namespace ov { | ||
namespace pass { | ||
|
||
class TRANSFORMATIONS_API ConstantsReduce : public ov::pass::GraphRewrite { |
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 add new unit tests for this transformation?
This PR was closed because it has been stalled for 2 week with no activity. |
Do you have any ticket which describes the background or impact of this change? If so, please add a link, and if not, could you please add description in this PR? It would be great for anyone who is interested in its effect or affected models. |
auto lhs_node = ov::as_type_ptr<op::v0::Constant>(lhs); | ||
auto rhs_node = ov::as_type_ptr<op::v0::Constant>(rhs); | ||
|
||
auto lhs_type = lhs_node->get_output_element_type(0); |
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.
This part of code looks similar to this function
Consider expert these function to tensor_util.hpp (part of dev API ) and re-use it. The Constant node can provide tensor view
}; | ||
|
||
bool ConstantsReduce::run_on_model(const std::shared_ptr<ov::Model>& m) { | ||
RUN_ON_FUNCTION_SCOPE(ConstantsReduce); |
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.
minor: RUN_ON_FUNCTION_SCOPE -> RUN_ON_MODEL_SCOPE
Details:
Tickets: