diff --git a/paddle/parameter/ParameterUpdaterHook.cpp b/paddle/parameter/ParameterUpdaterHook.cpp index 44fac592002341e0edb9466e26037c2fa1c265d2..1cc91b727ad8ecf9b56fc31b644db9f67def53df 100644 --- a/paddle/parameter/ParameterUpdaterHook.cpp +++ b/paddle/parameter/ParameterUpdaterHook.cpp @@ -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()) { diff --git a/proto/ParameterConfig.proto b/proto/ParameterConfig.proto index 360342bac6facf47b91ff1424eecbf3b5b6ae71a..580d66324602df4c655dd2f1e1cd87159b5b346b 100644 --- a/proto/ParameterConfig.proto +++ b/proto/ParameterConfig.proto @@ -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 { diff --git a/python/paddle/trainer_config_helpers/attrs.py b/python/paddle/trainer_config_helpers/attrs.py index 2e4e082efb063846c65139323571a02f79696112..bf12ad644dce1b29ef51d0292675fd8472a0b19f 100644 --- a/python/paddle/trainer_config_helpers/attrs.py +++ b/python/paddle/trainer_config_helpers/attrs.py @@ -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 """