Skip to content

Commit 9c25431

Browse files
committed
evquantize patch: softmax input_scale added.
1 parent 0e17458 commit 9c25431

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

include/caffe/layers/softmax_layer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class SoftmaxLayer : public Layer<Dtype> {
4343
Blob<Dtype> sum_multiplier_;
4444
/// scale is an intermediate Blob to hold temporary results.
4545
Blob<Dtype> scale_;
46+
Dtype input_scale_; //CUSTOMIZATION
4647
};
4748

4849
} // namespace caffe

src/caffe/layers/softmax_layer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void SoftmaxLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
2121
vector<int> scale_dims = bottom[0]->shape();
2222
scale_dims[softmax_axis_] = 1;
2323
scale_.Reshape(scale_dims);
24+
input_scale_ = this->layer_param_.softmax_param().input_scale(); //CUSTOMIZATION
2425
}
2526

2627
template <typename Dtype>

src/caffe/layers/softmax_layer.cu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ void SoftmaxLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
9191
int count = bottom[0]->count();
9292
int channels = top[0]->shape(softmax_axis_);
9393
caffe_copy(count, bottom_data, top_data);
94+
//<--CUSTOMIZATION
95+
if (input_scale_ != Dtype(1)) {
96+
caffe_gpu_scal(count, input_scale_, top_data);
97+
//caffe_gpu_round(count, top_data);
98+
}
99+
//CUSTOMIZATION-->
94100
// We need to subtract the max to avoid numerical issues, compute the exp,
95101
// and then normalize.
96102
// compute max

src/caffe/proto/caffe.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,6 +2261,7 @@ message SoftmaxParameter {
22612261
// from the end (e.g., -1 for the last axis).
22622262
// Any other axes will be evaluated as independent softmaxes.
22632263
optional int32 axis = 2 [default = 1];
2264+
optional double input_scale = 3 [default = 1]; //CUSTOMIZATION
22642265
}
22652266

22662267
// ***************** MulticoreWare_Modified - Feature: Pruning / Splicing ******************

0 commit comments

Comments
 (0)