-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Matrix::MUL operators using and test Daoyuan's Paddle Function, SparseMatrixArg and Function Test #1147
Matrix::MUL operators using and test Daoyuan's Paddle Function, SparseMatrixArg and Function Test #1147
Conversation
90a0f3f
to
3f09139
Compare
5020971
to
2074603
Compare
2074603
to
02f5647
Compare
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.
主要先看了一下MulFunc的实现。
|
||
/** | ||
* mul operator | ||
* out = scaleT * out + scaleAB*(in1 * in2) |
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.
注释还得在加强,要写明白MulFunc支持哪些参数类型,比如Dense,CSR/CSC Sparse等。
另外,calc实现中的几个if逻辑也需要在这里写清楚。
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
public: | ||
void init(const FuncConfig& config) override { | ||
alpha_ = config.get<real>("scaleAB"); | ||
beta_ = config.get<real>("scaleT"); |
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.
alpha_, beta_这两个不一定需要。目前Paddle中对于Matrix::mul()
的调用只有C = A * B和C = A * B + C两种,分别可以通过设置C参数的ASSIGN_TO/ADD_TO属性来实现。
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
* mul operator | ||
* out = scaleT * out + scaleAB*(in1 * in2) | ||
* | ||
* \param outputs[0] output matrix, M * N |
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.
output matrix, M * N
这样的注释也并不好,并没有哪个地方解释M和N分别是什么。
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
alpha_, | ||
beta_); | ||
return; | ||
} |
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.
还需要增加一个CHECK检查上面几个if都没有走到的逻辑。
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
@@ -269,8 +265,8 @@ class SparseMatrixArg : public BufferArg { | |||
const BufferArg& row, | |||
const BufferArg& col, | |||
size_t nnz, | |||
SparseDataFormat format, | |||
SparseDataType type, | |||
SparseFormat format, |
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.
SparseFormat和SparseValueType放在Matrix.h里面并不合适;Matrix.h和SparseMatrix.h里面的数据结构最终是不准备用的,所以可以考虑把这两个TensorType.h里面去。
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
@@ -179,6 +174,7 @@ class BufferArg { | |||
TensorShape shape_; | |||
BufferType bufferType_{TENSOR_UNKNOWN}; | |||
ArgType argType_{UNSPECIFIED}; | |||
bool trans_{false}; |
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.
BufferArg可以表示一个高维的data,trans_
属性对3维或者4维的BufferArg无法很好的解释。
Mul Function里面的transa/transb实际是Function的属性,而不是BufferArg的属性(cblas_sgemm/cublasSgemm也一样)。
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.
trans_ 是数据的属性,matrix, sparse matrix里面是转置矩阵,对于更高order的Tensor,其实是有对应于矩阵转置的generalization的。https://arxiv.org/pdf/1411.1503v1.pdf
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
const CpuMatrix& b, | ||
real scaleAB, | ||
real scaleT) { | ||
CHECK(!out.isTransposed()) << "Not supported"; |
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.
这里,包括后面几个API中的一些参数CHECK,实际应该是在Function里面检查。如果运行时参数错误,也需要在Function里面就能报出。
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.
Approve FunctionTest
void run() { | ||
// prepare cpu/gpu arguments | ||
initInputs(); | ||
|
||
initOutputs(); |
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.
FunctionCompare可能得加个钩子,uniform(0.001, 1)
可能支持不了所有Function的参数初始化。
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.
Good idea. Will do it later for the future unit test cases.
bd54d72
to
6dd017f
Compare
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.
另外,我在#1216 (comment)
里面FunctionBase增加ops和check两个接口,在乘法接口里面也可以实现一下。
@hedaoyuan , 好的,我看一下你的PR,然后再开个PR,在MUL里面添加一下这两个接口。
我这个PR比较大一点,已经address了一下你的comments。如果你觉得没什么问题的话,要不先Approve一下?
real beta_; | ||
bool aTrans_; | ||
bool bTrans_; | ||
bool cTrans_; |
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.
cTrans_不需要吧。cblas_sgemm/cublasSgemm里面也有没有cTrans这个参数的。
另外,alpha_/beta_我觉得还是去掉吧,从目前Paddle的实现来看NeuralNetwork Computation里面并不会需要这样两个参数,去掉也可以稍微简化一点接口的用法。
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
} | ||
|
||
void calc(const BufferArgs& inputs, const BufferArgs& outputs) override { | ||
CHECK(!cTrans_) << "output matrix should not be transposed"; |
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.
以后估计也不会支持cTrans_ == ture,所以直接去掉cTrans_更好。
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
…::mul(CpuMatrix, CpuMatrix)
and GpuMatrix::mul(CpuMatrix, GpuSparseMatrix)
SparseGpuMatrix::mul(GpuMatrix, GpuMatrix), CpuMatrix::mul(CpuSparseMatrix, CpuMatrix), and GpuMatrix::mul(GpuSparseMatrix, GpuMatrix)
e6f0840
to
5b1a5c1
Compare
Add the following Matrix::Mul operators: (#977)
Use and test Daoyuan's SparseMatrixArg, Function Test.
Write new sparse/dense matrix unit test using Function test.