提交 fc9e3e4b 编写于 作者: Z zlx

explain the sparsity ratio

上级 6248e566
......@@ -61,7 +61,7 @@ public:
maskTemp_ = Vector::create(para->getSize(), false);
maskTemp_->zeroMem();
real* dataPtr = maskTemp_->getData();
size_t sparsityNum = para->getSize() * (1 - sparsityRatio_);
size_t nonZeroNum = para->getSize() * (1 - sparsityRatio_);
VectorPtr vecCpu = Vector::create(para->getSize(), false);
vecCpu->copyFrom(*vec);
......@@ -71,10 +71,10 @@ public:
param.push_back(std::make_pair(fabs(vecCpu->getData()[i]), i));
std::partial_sort(param.begin(),
param.begin() + sparsityNum,
param.begin() + nonZeroNum,
param.end(),
sortPairAscend);
for (size_t i = 0; i < sparsityNum; i++) dataPtr[param[i].second] = 1.0;
for (size_t i = 0; i < nonZeroNum; i++) dataPtr[param[i].second] = 1.0;
// Currently just use a mask vector for hack.
if (para->useGpu()) {
......
......@@ -27,7 +27,8 @@ enum ParameterInitStrategy {
message ParameterUpdaterHookConfig {
// hook type such as 'pruning'
required string type = 1;
optional double sparsity_ratio = 2 [default = 0.8];
// this represents the ratio of zero element to be set by the Parameter
optional double sparsity_ratio = 2 [default = 0.6];
}
message ParameterConfig {
......
......@@ -65,7 +65,8 @@ class HookAttribute(object):
:param type: Hook type, eg: 'pruning'
:type type: string
:param sparsity_ratio: Must be specified if hook type is 'pruning'
:param sparsity_ratio: Must be specified if hook type is 'pruning',
it represents the ratio of the zero elements to be set by the Parameter.
:type sparsity_ratio: float or None
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册