Matmul rework
[ADD] support for Multi-dimensional Matrix Multiplication, following numpy MatMul operation specificities.
In the context of Multi-dimensional MatMul, we consider an N-Dim Tensor as a stack of 2-D matrices having as shape the last two dimensions of the Tensor.
From Numpy documentation:
The behavior depends on the arguments in the following way.
- If both arguments are 2-D they are multiplied like conventional matrices.
- If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes and broadcast accordingly.
- If the first argument is 1-D, it is promoted to a matrix by prepending a 1 to its dimensions. After matrix multiplication the prepended 1 is removed.
- If the second argument is 1-D, it is promoted to a matrix by appending a 1 to its dimensions. After matrix multiplication the appended 1 is removed.
Merge request reports
Activity
assigned to @hrouis
requested review from @pineapple
added LanguageC++ StatusReview Ready labels
added Missing Feature label
changed milestone to %aidge_core - v0.2.0
- Resolved by Houssem ROUIS
- Resolved by Houssem ROUIS
41 41 AIDGE_ASSERT(matmulNode->getParent(1), "No weight detected to produce the fuseMulAdd recipe."); 42 42 43 43 std::shared_ptr<Node> weight = matmulNode->getParent(1)->cloneSharedOperators(); 44 const DimSize_t outSize = std::dynamic_pointer_cast<MatMul_Op>(matmulNode->getOperator()) -> getAttr<DimSize_t>("OutChannels"); 44 // TODO: find another way to get OutChannels for FC operator. 45 // This poor fix supposes that one of Add inputs is a const and has the same outChannels as the output 46 DimSize_t outSize = 0; 47 const auto& op = std::dynamic_pointer_cast<OperatorTensor>(addNode->getOperator()); 48 for (size_t i = 0; i < op->nbInputs(); i++) 49 { 50 const auto& inTensor = op->getInput(i); 51 if(inTensor->nbDims() > 0) { 52 outSize = inTensor->dims()[inTensor->nbDims()-1]; 53 break; 54 } 55 } @cmoineau I don't know if you discussed with @pineapple but this is a bad fix and I can't find a proper one to get outChannels because both add and matmul outputs are dynamics so I can't access the shape.
Edited by Houssem ROUIS
added 41 commits
-
248e8175...f0917214 - 40 commits from branch
eclipse/aidge:dev
- 887249ac - Merge branch 'dev' into matmul_rework
-
248e8175...f0917214 - 40 commits from branch
enabled an automatic merge when the pipeline for 887249ac succeeds
added 2 commits