-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[IE][VPU]: Enables Extract Dynamic Batch Transformation #3715
[IE][VPU]: Enables Extract Dynamic Batch Transformation #3715
Conversation
void printTo(std::ostream& stream, const ngraph::NodeTypeInfo& object); | ||
template<> | ||
inline void printTo(std::ostream& stream, const ngraph::NodeTypeInfo& object) { | ||
stream << object.name << " ver. " << object.version; | ||
} |
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.
I still not sure why I had to make this change, but otherwise compiler picks up wrong printTo
definition and prints empty string for ngraph::NodeTypeInfo
- default printTo
implementation
// constant's shape has to be scalar (not empty) since if this constant has empty shape, so Gather will | ||
// have empty shape as well (Gather produces scalar). When this Gather will become ScatterElementsUpdate | ||
// argument ScatterElementsUpdate shape inference function will fail, since it requires indices and updates | ||
// to have exactly the same shape (indices rank must be the same as rank of data input which is 1D vector, | ||
// so its rank = 1 != 0) | ||
const auto constant = std::make_shared<ngraph::opset5::Constant>(ngraph::element::i64, ngraph::Shape{1}, 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.
@@ -44,7 +44,13 @@ namespace ngraph | |||
/// (Informal notation examples: `{1,2,3,4}`, `{6}`, `{}`) | |||
class NGRAPH_API PartialShape | |||
{ | |||
using Dimensions = std::vector<Dimension>; |
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.
@ilyachur please take a look
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.
nGraph part LGTM
@@ -223,6 +230,18 @@ namespace ngraph | |||
const PartialShape& src, | |||
const op::AutoBroadcastSpec& autob); | |||
|
|||
iterator begin() noexcept { return m_dimensions.begin(); } |
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.
Just one comment: Please add doxygen documentation for new methods.
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.
Done
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.
@ilyachur, should we change m_shape_type
as is done in operator[]
?
IMHO begin
, end
and operator[]
should return some wrapper which on each write should update m_shape_type
.
inference-engine/src/vpu/common/include/vpu/ngraph/utilities.hpp
Outdated
Show resolved
Hide resolved
...nce-engine/src/vpu/common/src/ngraph/transformations/extract_dynamic_batch/slice_mat_mul.cpp
Outdated
Show resolved
Hide resolved
...ne/src/vpu/common/src/ngraph/transformations/extract_dynamic_batch/extract_dynamic_batch.cpp
Outdated
Show resolved
Hide resolved
...u/common/src/ngraph/transformations/extract_dynamic_batch/batch_extraction_configuration.cpp
Outdated
Show resolved
Hide resolved
...ne/src/vpu/common/src/ngraph/transformations/extract_dynamic_batch/extract_dynamic_batch.cpp
Outdated
Show resolved
Hide resolved
...ne/src/vpu/common/src/ngraph/transformations/extract_dynamic_batch/extract_dynamic_batch.cpp
Outdated
Show resolved
Hide resolved
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.
LGTM. Good job 👍
It's convenient to be able to use STL algorithms on PartialShape since semantically PartialShape is a sequence of Dimensions. Signed-off-by: Gladilov, Gleb <[email protected]>
Introduces Depth-First-Search and Breadth-First-Search utilities for tree traversal. Templated arguments makes them extensible for different use-case scenarios. BFS is designed in way to make it possible to guarantee node will be visited only after all its predecessors have been visited: a / \ b c | | d | \ / e There with accordingly provided functors (NumEntries) it's guaranteed node "e" will be visited after "d" and "c". Such a property is important for nodes depth evaluation. Signed-off-by: Gladilov, Gleb <[email protected]>
For some reason if printTo for nGraph type is usual function it's not picked up by VPU_THROW_UNLESS triggered inside DynamicToStaticShape transformations. Making it template specialization does the job. Signed-off-by: Gladilov, Gleb <[email protected]>
SliceConfiguration is a class that's intended to express the result of operation slicing by batch. The result of slicing is configuration that specifies what to do with each data object associated with operation. There are two options defined: Slice and Unchanged. Typical slice scenario is Slice, when operation has the same batch for all inputs and outputs, so all corresponding data object will be "sliced" (replaced with copy where batch equal to 1). At some cases, data object should not sliced (ex. if operation has constant input which is the same for all input data batches and so, does not have batch - Add of 2 tensors with shapes [10, 1000] and [1000]). To represent such cases there is option "Unchanged". At cases when operation should not be sliced at all (ex. does not have batch, have different batch for inputs and outputs, has static batch and so on) SliceConfiguration object will return false for "hasSlice" method call. In these cases inputs and outputs methods calls will throw an exception. Signed-off-by: Gladilov, Gleb <[email protected]>
In case of static batch, operation is not going to be sliced, since for handling such cases other transformation is used. Such approach allows both passes to co-exist while one is being replaced with another. If data input has other dynamic dimension than batch error will be thrown since Myriad-X plugin does not support convolutions (HW accelerated operations) with dynamism in spatial dimensions. Signed-off-by: Gladilov, Gleb <[email protected]>
In case of static batch, operation is not going to be sliced, since for handling such cases other transformation is used. Such approach allows both passes to co-exist while one is being replaced with another. If data input has other dynamic dimension than batch error will be thrown since Myriad-X plugin does not support convolutions (HW accelerated operations) with dynamism in spatial dimensions. Signed-off-by: Gladilov, Gleb <[email protected]>
Since extract dynamic batch transformation will handle dynamism only by batch (so requires body loop to be static) operations with dynamism in dimension other than batch should not be covered by loop. In case of dynamism in dimension other than batch eltwise will be considered unsupported for sub-graph extraction. Signed-off-by: Gladilov, Gleb <[email protected]>
Since extract dynamic batch transformation will handle dynamism only by batch (so requires body loop to be static) operations with dynamism in dimension other than batch should not be covered by loop. In case of dynamism in dimension other than batch eltwise will be considered unsupported for sub-graph extraction. It's template function since different binary eltwise operations have the same broadcasting rules. Signed-off-by: Gladilov, Gleb <[email protected]>
General approach is following: 1. Extracted sub-graphs should have exactly one input and output operation. Otherwise, it's possible that memory consumption of model will be increased since loops implementation on Myriad-X requires to keep all inputs and outputs of loop to be alive along with memory used by loop body. In layout consolidation scenario it reflects intention to use minimized amount of permutations. 2. Extracted sub-graph should not have external connections ( the only nodes that allowed to have predecessor or successor outside of sub-graph are input and output). Otherwise, it's possible that memory consumption of model will be increased for the same reason as in previous point. To make sure this restriction is met transformation looks for leaves in both directions, finds corresponding LCA (Lowest Common Ancestor) and checks if such sub-graph has external connections. If so, it repeats leaves search procedure stopping if it approaches leaves from previous iteration and finds LCA again. It is repeated until sub-graph without external connections is found (it exists, at least source itself forms it). Leaf in current context is a node which satisfies one of the following conditions (depending on direction): Top: 1. It has no predecessors which are neither Parameter, nor Constant 2. It's unknown how to slice this operation 3. It could not be sliced (different batch for inputs and outputs) Bottom: 1. It has no successors which are not Result 2. It's unknown how to slice this operation 3. It could not be sliced (different batch for inputs and outputs) Signed-off-by: Gladilov, Gleb <[email protected]>
...ne/src/vpu/common/src/ngraph/transformations/extract_dynamic_batch/extract_dynamic_batch.cpp
Show resolved
Hide resolved
...nce-engine/src/vpu/common/src/ngraph/transformations/extract_dynamic_batch/slice_mat_mul.cpp
Show resolved
Hide resolved
…kit#3715) * [IE][nGraph]: Enables begin/end iterators for PartialShape It's convenient to be able to use STL algorithms on PartialShape since semantically PartialShape is a sequence of Dimensions. * [IE][VPU][nGraph]: Introduces tree utilities Introduces Depth-First-Search and Breadth-First-Search utilities for tree traversal. Templated arguments makes them extensible for different use-case scenarios. BFS is designed in way to make it possible to guarantee node will be visited only after all its predecessors have been visited: a / \ b c | | d | \ / e There with accordingly provided functors (NumEntries) it's guaranteed node "e" will be visited after "d" and "c". Such a property is important for nodes depth evaluation. * [IE][VPU][nGraph]: Fixes printTo for nGraph type For some reason if printTo for nGraph type is usual function it's not picked up by VPU_THROW_UNLESS triggered inside DynamicToStaticShape transformations. Making it template specialization does the job. * [IE][VPU]: Introduces SliceConfiguration class SliceConfiguration is a class that's intended to express the result of operation slicing by batch. The result of slicing is configuration that specifies what to do with each data object associated with operation. There are two options defined: Slice and Unchanged. Typical slice scenario is Slice, when operation has the same batch for all inputs and outputs, so all corresponding data object will be "sliced" (replaced with copy where batch equal to 1). At some cases, data object should not sliced (ex. if operation has constant input which is the same for all input data batches and so, does not have batch - Add of 2 tensors with shapes [10, 1000] and [1000]). To represent such cases there is option "Unchanged". At cases when operation should not be sliced at all (ex. does not have batch, have different batch for inputs and outputs, has static batch and so on) SliceConfiguration object will return false for "hasSlice" method call. In these cases inputs and outputs methods calls will throw an exception. * [IE][VPU][nGraph]: Enables MatMul operation slice In case of static batch, operation is not going to be sliced, since for handling such cases other transformation is used. Such approach allows both passes to co-exist while one is being replaced with another. If data input has other dynamic dimension than batch error will be thrown since Myriad-X plugin does not support convolutions (HW accelerated operations) with dynamism in spatial dimensions. * [IE][VPU][nGraph]: Enables Convolution operations slice In case of static batch, operation is not going to be sliced, since for handling such cases other transformation is used. Such approach allows both passes to co-exist while one is being replaced with another. If data input has other dynamic dimension than batch error will be thrown since Myriad-X plugin does not support convolutions (HW accelerated operations) with dynamism in spatial dimensions. * [IE][VPU][nGraph]: Enables unary eltwise slice Since extract dynamic batch transformation will handle dynamism only by batch (so requires body loop to be static) operations with dynamism in dimension other than batch should not be covered by loop. In case of dynamism in dimension other than batch eltwise will be considered unsupported for sub-graph extraction. * [IE][VPU][nGraph]: Enables binary eltwise slice Since extract dynamic batch transformation will handle dynamism only by batch (so requires body loop to be static) operations with dynamism in dimension other than batch should not be covered by loop. In case of dynamism in dimension other than batch eltwise will be considered unsupported for sub-graph extraction. It's template function since different binary eltwise operations have the same broadcasting rules. * [IE][VPU][nGraph]: Enables extract dynamic batch transformation General approach is following: 1. Extracted sub-graphs should have exactly one input and output operation. Otherwise, it's possible that memory consumption of model will be increased since loops implementation on Myriad-X requires to keep all inputs and outputs of loop to be alive along with memory used by loop body. In layout consolidation scenario it reflects intention to use minimized amount of permutations. 2. Extracted sub-graph should not have external connections ( the only nodes that allowed to have predecessor or successor outside of sub-graph are input and output). Otherwise, it's possible that memory consumption of model will be increased for the same reason as in previous point. To make sure this restriction is met transformation looks for leaves in both directions, finds corresponding LCA (Lowest Common Ancestor) and checks if such sub-graph has external connections. If so, it repeats leaves search procedure stopping if it approaches leaves from previous iteration and finds LCA again. It is repeated until sub-graph without external connections is found (it exists, at least source itself forms it). Leaf in current context is a node which satisfies one of the following conditions (depending on direction): Top: 1. It has no predecessors which are neither Parameter, nor Constant 2. It's unknown how to slice this operation 3. It could not be sliced (different batch for inputs and outputs) Bottom: 1. It has no successors which are not Result 2. It's unknown how to slice this operation 3. It could not be sliced (different batch for inputs and outputs) Signed-off-by: Gladilov, Gleb <[email protected]>
Description
General approach is following:
Extracted sub-graphs should have exactly one input and output operation. Otherwise, it's possible that memory consumption of model will be increased since loops implementation on Myriad-X requires to keep all inputs and outputs of loop to be alive along with memory used by loop body. In layout consolidation scenario it reflects intention to use minimized amount of permutations.
Extracted sub-graph should not have external connections (the only nodes that allowed to have predecessor or successor outside of sub-graph are input and output). Otherwise, it's possible that memory consumption of model will be increased for the same reason as in previous point.
To make sure this restriction is met transformation looks for leaves in both directions, finds corresponding LCA (Lowest Common Ancestor) and checks if such sub-graph has external connections. If so, it repeats leaves search procedure stopping if it approaches leaves from previous iteration and finds LCA again. It is repeated until sub-graph without external connections is found (it exists, at least source itself forms it).
Leaf in current context is a node which satisfies one of the following conditions (depending on direction):
Top:
1. It has no predecessors which are neither Parameter, nor Constant
2. It's unknown how to slice this operation
3. It could not be sliced (different batch for inputs and outputs)
Bottom:
1. It has no successors which are not Result
2. It's unknown how to slice this operation
3. It could not be sliced (different batch for inputs and outputs)
Tests are going to be added later once
ngraph::opset5::Loop
will be supported in Myriad-X plugin.Task
#-43586