-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[tmva][sofie] Add TopK operator #15886
base: master
Are you sure you want to change the base?
Conversation
//std::cout << "Reduce operator - axis = " << fAttrAxes[0] << " shape x " << ConvertShapeToString(fShapeX) | ||
// << " output shape " << ConvertShapeToString(fShapeY) << std::endl; |
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.
maybe we can remove this commented code?
// if(fK>fShapeX[fAttrAxis]){ | ||
// throw | ||
// std::runtime_error("TMVA::SOFIE ONNX TopK op k = "+ std::to_string(fK) +" value exeeds value of tensor " +fNX+" of size "+fShapeX.size()+" at axis= "+std::to_string(fAttrAxis)+"."); | ||
// } | ||
// fShapeX = model.GetTensorShape(fNX); // [ m x n x o x p ... ] | ||
// if(k[0]>=fShapeX.size()){ | ||
// throw | ||
// std::runtime_error("TMVA::SOFIE ONNX TopK op k = "+ std::to_string(k[0]) +"value exeeds size of tensor " +fNX+" of size "+fShapeX.size()+" ."); | ||
// } | ||
// fShapeY.push_back(2); | ||
// for (auto i : fShapeX) | ||
// fShapeY.push_back(i); // [ 2 x m x n x o x p ... ] | ||
// size_t axis = fAttrAxis < 0 ? fShapeX.size() + fAttrAxis : fAttrAxis; | ||
// fShapeY[axis] = k[0]; // [ 2 x m x n x K x p ... ] |
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.
same with the commented code here
tmva/sofie/src/RModel.cxx
Outdated
@@ -797,7 +833,7 @@ long RModel::WriteInitializedTensorsToFile(std::string filename) { | |||
void RModel::PrintRequiredInputTensors() { | |||
std::cout << "Model requires following inputs:\n"; | |||
for (auto& inputInfo: fInputTensorInfos) { | |||
std::cout << "Parameterised Tensor name: " << inputInfo.first << "\t"; | |||
std::cout << "Parametraised Tensor name: " << inputInfo.first << "\t"; |
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.
std::cout << "Parametraised Tensor name: " << inputInfo.first << "\t"; | |
std::cout << "Parameterised Tensor name: " << inputInfo.first << "\t"; |
Test Results 13 files 13 suites 2d 13h 35m 1s ⏱️ For more details on these failures, see this check. Results for commit 449baf1. ♻️ This comment has been updated with latest results. |
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.
Thanks for this PR. The code seems to do what it's supposed to, i.e. add an operator. However the code seems to need some refactoring, for example avoiding to pass by value potentially large objects, by not having commented code, unclear functions.
tmva/sofie/inc/TMVA/RModel.hxx
Outdated
@@ -60,6 +60,9 @@ public: | |||
} | |||
void AddInitializedTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape, | |||
std::shared_ptr<void> data); | |||
void AddConstantTensor(std::string tensor_name, ETensorType type, std::vector<std::size_t> shape, |
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.
perhaps strings have to be passed by const ref?
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 is a comment valid for all signatures featuring string.
public: | ||
ROperator_Constant(){} | ||
|
||
ROperator_Constant(const std::string & type, const std::vector<T> & values, const std::vector<size_t> & shape, std::string nameX, std::string nameY): |
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.
here vectors are passed properly, but not strings. see above.
fAttrType(type) | ||
{ } | ||
|
||
std::vector<ETensorType> TypeInference(std::vector<ETensorType> input){ |
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 ref?
return input; | ||
} | ||
|
||
std::vector<std::vector<size_t>> ShapeInference(std::vector<std::vector<size_t>> input){ |
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.
Is the goal of this function to make a copy of the input? The implementation also is strange, right? Why not just making a copy instead of calling it?
}//TMVA | ||
|
||
|
||
#endif //TMVA_SOFIE_ROPERATOR_Constant |
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.
missing trailing carriage return.
@@ -56,102 +58,120 @@ public: | |||
// shape of output tensors given input tensors | |||
std::vector<std::vector<size_t>> ShapeInference(std::vector<std::vector<size_t>> input){ |
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.
again, this syntax is misleading. Why not passing a const ref?
|
||
std::string Generate(std::string OpName){ | ||
std::string Generate(std::string OpName){ |
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 ref?
fNVal(UTILITY::Clean_name(nameVal)), | ||
fNInd(UTILITY::Clean_name(nameInd)){} | ||
|
||
std::vector<ETensorType> TypeInference(std::vector<ETensorType> input) { |
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.
again const ref.
tmva/sofie/src/RModel.cxx
Outdated
size_t length = ConvertShapeToLength(i.second.shape()); | ||
// in case we are not using weight files or for tensor created from Constant operator | ||
if (!fUseWeightFile || i.second.IsConstantTensor() ) { | ||
//std::cout << "write tensor " << i.first << std::endl; |
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.
These changes contain commented code, should it be removed?
tmva/sofie/src/RModel.cxx
Outdated
strs << "float tensor_" << i.first << "[" << length << "] = {"; | ||
float const *data = i.second.data<float>(); | ||
for (size_t idx = 0; idx < length; idx++) { | ||
strs << std::setprecision(std::numeric_limits<float>::max_digits10) << data[idx]; |
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.
a general comment: should the fp numbers be written in hex format not to loose any precision?
Implement TopK operator (work from GSOC student Vedant Mehra)
Fix the output type when parsing TopK Clean up the code in TopK impelmentation and in the generated code. Fix also the compilation warnings
3d54e72
to
449baf1
Compare
This Pull request adds the support for TopK operator in SOFIE
Implementation provided by GSOC student from Vedant Mehra.
This PR is based on #15837 and should be merged after that one and eventually rebased