Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cyril Moineau
aidge_core
Commits
19a41f8e
Commit
19a41f8e
authored
1 year ago
by
vincent lorrain
Browse files
Options
Downloads
Patches
Plain Diff
removeFlatten recipies and fix pybind
parent
c3b0ad25
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/aidge/utils/Recipies.hpp
+5
-1
5 additions, 1 deletion
include/aidge/utils/Recipies.hpp
python_binding/recipies/pybind_Recipies.cpp
+24
-20
24 additions, 20 deletions
python_binding/recipies/pybind_Recipies.cpp
src/recipies/RemoveFlatten.cpp
+45
-19
45 additions, 19 deletions
src/recipies/RemoveFlatten.cpp
with
74 additions
and
40 deletions
include/aidge/utils/Recipies.hpp
+
5
−
1
View file @
19a41f8e
...
...
@@ -50,7 +50,11 @@ void fuseMulAdd(std::shared_ptr<GraphView> graphView);
*
* @param nodes Strict set of Node to merge.
*/
void
removeFlatten
(
std
::
set
<
std
::
shared_ptr
<
Node
>>
nodes
);
void
removeFlatten
(
std
::
shared_ptr
<
Node
>
flatten
);
void
removeFlatten
(
std
::
shared_ptr
<
MatchSolution
>
solution
);
/**
* @brief Remove ``Flatten`` before :cpp:function:`Aidge::FC` Node.
*
...
...
This diff is collapsed.
Click to expand it.
python_binding/recipies/pybind_Recipies.cpp
+
24
−
20
View file @
19a41f8e
...
...
@@ -28,12 +28,13 @@ void init_Recipies(py::module &m) {
:param graph_view: Graph view on which we want to apply the recipie
:type graph_view: :py:class:`aidge_core.GraphView`
)mydelimiter"
);
m
.
def
(
"fuse_mul_add"
,
static_cast
<
void
(
*
)(
std
::
set
<
std
::
shared_ptr
<
Node
>>
)
>
(
fuseMulAdd
),
py
::
arg
(
"nodes"
),
R"mydelimiter(
Recipie to Fuse MatMul and Add operators into an :py:class:`aidge_core.FC` operator.
// m.def("fuse_mul_add", static_cast<void(*)(std::set<std::shared_ptr<Node>>)>(fuseMulAdd), py::arg("nodes"), R"mydelimiter(
// Recipie to Fuse MatMul and Add operators into an :py:class:`aidge_core.FC` operator.
:param nodes: The MatMul and Add nodes to fuse.
:type nodes: list of :py:class:`aidge_core.Node`
)mydelimiter"
);
//
:param nodes: The MatMul and Add nodes to fuse.
//
:type nodes: list of :py:class:`aidge_core.Node`
//
)mydelimiter");
m
.
def
(
"remove_flatten"
,
static_cast
<
void
(
*
)(
std
::
shared_ptr
<
GraphView
>
)
>
(
removeFlatten
),
py
::
arg
(
"graph_view"
),
R"mydelimiter(
Recipie to remove a flatten operator.
...
...
@@ -41,18 +42,20 @@ void init_Recipies(py::module &m) {
:param graph_view: Graph view on which we want to apply the recipie
:type graph_view: :py:class:`aidge_core.GraphView`
)mydelimiter"
);
m
.
def
(
"remove_flatten"
,
static_cast
<
void
(
*
)(
std
::
set
<
std
::
shared_ptr
<
Node
>>
)
>
(
removeFlatten
),
py
::
arg
(
"nodes"
),
R"mydelimiter(
Recipie to remove a flatten operator.
:param nodes: The flatten operator to remove.
:type nodes: list of :py:class:`aidge_core.Node`
)mydelimiter"
);
m
.
def
(
"fuse_mul_add"
,
static_cast
<
void
(
*
)(
std
::
set
<
std
::
shared_ptr
<
Node
>>
)
>
(
fuseMulAdd
),
py
::
arg
(
"nodes"
),
R"mydelimiter(
Recipie to Fuse MatMul and Add operators into an :py:class:`aidge_core.FC` operator.
// m.def("remove_flatten", static_cast<void(*)(std::set<std::shared_ptr<Node>>)>(removeFlatten), py::arg("nodes"), R"mydelimiter(
// Recipie to remove a flatten operator.
:param nodes: The MatMul and Add nodes to fuse.
:type nodes: list of :py:class:`aidge_core.Node`
)mydelimiter"
);
// :param nodes: The flatten operator to remove.
// :type nodes: list of :py:class:`aidge_core.Node`
// )mydelimiter");
// m.def("fuse_mul_add", static_cast<void(*)(std::set<std::shared_ptr<Node>>)>(fuseMulAdd), py::arg("nodes"), R"mydelimiter(
// Recipie to Fuse MatMul and Add operators into an :py:class:`aidge_core.FC` operator.
// :param nodes: The MatMul and Add nodes to fuse.
// :type nodes: list of :py:class:`aidge_core.Node`
// )mydelimiter");
m
.
def
(
"fuse_batchnorm"
,
static_cast
<
void
(
*
)(
std
::
shared_ptr
<
GraphView
>
)
>
(
fuseBatchNorm
),
py
::
arg
(
"graph_view"
),
R"mydelimiter(
Recipie to remove a flatten operator.
...
...
@@ -60,11 +63,12 @@ void init_Recipies(py::module &m) {
:param graph_view: Graph view on which we want to apply the recipie
:type graph_view: :py:class:`aidge_core.GraphView`
)mydelimiter"
);
m
.
def
(
"fuse_batchnorm"
,
static_cast
<
void
(
*
)(
std
::
set
<
std
::
shared_ptr
<
Node
>>
)
>
(
fuseBatchNorm
),
py
::
arg
(
"nodes"
),
R"mydelimiter(
Recipie to remove a flatten operator.
// m.def("fuse_batchnorm", static_cast<void(*)(std::set<std::shared_ptr<Node>>)>(fuseBatchNorm), py::arg("nodes"), R"mydelimiter(
// Recipie to remove a flatten operator.
:param nodes: The flatten operator to remove.
:type nodes: list of :py:class:`aidge_core.Node`
)mydelimiter"
);
//
:param nodes: The flatten operator to remove.
//
:type nodes: list of :py:class:`aidge_core.Node`
//
)mydelimiter");
}
}
// namespace Aidge
This diff is collapsed.
Click to expand it.
src/recipies/RemoveFlatten.cpp
+
45
−
19
View file @
19a41f8e
...
...
@@ -18,33 +18,59 @@
// Graph Regex
#include
"aidge/graphmatching/GRegex.hpp"
#include
"aidge/graphmatching/NodeRegex.hpp"
//Graph Regex
#include
"aidge/graphRegex/GraphRegex.hpp"
namespace
Aidge
{
void
removeFlatten
(
std
::
set
<
std
::
shared_ptr
<
Node
>
>
nodes
)
{
assert
(
nodes
.
size
()
==
2
&&
"Wrong number of nodes to replace
\n
"
);
std
::
shared_ptr
<
Node
>
flatten
;
for
(
const
auto
&
element
:
nodes
)
{
assert
((
element
->
type
()
==
"FC"
||
element
->
type
()
==
"Flatten"
)
&&
"Wrong type for the nodes to replace"
);
if
(
element
->
type
()
==
"Flatten"
){
flatten
=
element
;
}
}
void
removeFlatten
(
std
::
shared_ptr
<
Node
>
flatten
)
{
//
assert(nodes.size() == 2 && "Wrong number of nodes to replace\n");
//
std::shared_ptr<Node> flatten;
//
for (const auto& element : nodes) {
//
assert((element->type() == "FC" || element->type() == "Flatten") && "Wrong type for the nodes to replace");
//
if (element->type() == "Flatten"){
//
flatten = element;
//
}
//
}
GraphView
::
replace
({
flatten
},
{});
}
void
removeFlatten
(
std
::
shared_ptr
<
MatchSolution
>
solution
){
assert
(
solution
->
at
(
"FC"
).
size
()
==
1
&&
"Wrong number of nodes FC to replace
\n
"
);
assert
(
solution
->
at
(
"Flatten"
).
size
()
==
1
&&
"Wrong number of nodes Flatten to replace
\n
"
);
for
(
const
auto
&
flatten
:
solution
->
at
(
"Flatten"
))
{
removeFlatten
(
flatten
);
}
}
void
removeFlatten
(
std
::
shared_ptr
<
GraphView
>
graphView
){
std
::
map
<
std
::
string
,
NodeRegex
*>
nodesRegex
;
nodesRegex
[
"Flatten"
]
=
new
NodeRegex
(
"Flatten"
);
nodesRegex
[
"FC"
]
=
new
NodeRegex
(
"FC"
);
std
::
vector
<
std
::
string
>
seqRegex
;
seqRegex
.
push_back
(
"Flatten->FC;"
);
GRegex
GReg
(
nodesRegex
,
seqRegex
);
Match
matches
=
GReg
.
match
(
graphView
);
std
::
vector
<
std
::
set
<
std
::
shared_ptr
<
Node
>>>
matchNodes
=
matches
.
getMatchNodes
();
for
(
size_t
i
=
0
;
i
<
matches
.
getNbMatch
();
++
i
)
{
removeFlatten
(
matchNodes
[
i
]);
// std::map<std::string,NodeRegex*> nodesRegex ;
// nodesRegex["Flatten"] = new NodeRegex("Flatten");
// nodesRegex["FC"] = new NodeRegex("FC");
// std::vector<std::string> seqRegex;
// seqRegex.push_back("Flatten->FC;");
// GRegex GReg(nodesRegex, seqRegex);
// Match matches = GReg.match(graphView);
// std::vector<std::set<std::shared_ptr<Node>>> matchNodes = matches.getMatchNodes();
// for (size_t i = 0; i < matches.getNbMatch(); ++i) {
// removeFlatten(matchNodes[i]);
// }
std
::
shared_ptr
<
GraphRegex
>
regex
=
std
::
make_shared
<
GraphRegex
>
();
regex
->
setNodeKey
(
"Flatten"
,
"getType($) =='Flatten'"
);
regex
->
setNodeKey
(
"FC"
,
"getType($) =='FC'"
);
regex
->
addQuery
(
"Flatten->FC"
);
for
(
const
auto
&
solution
:
regex
->
match
(
graphView
))
{
removeFlatten
(
solution
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment