Skip to content

Commit 9a344f6

Browse files
authored
fix sampling_id, fix xpu python whl, fix quant_dequant pass (#9636) (#9648)
1 parent 18f668d commit 9a344f6

File tree

5 files changed

+40
-20
lines changed

5 files changed

+40
-20
lines changed

lite/api/python/setup.py.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ if '${WITH_MKL}' == 'ON' and '${WITH_STATIC_MKL}' == 'ON' and os.name != 'nt':
6262
shutil.copy('${MKLML_SHARED_IOMP_LIB}', LIB_PATH)
6363
PACKAGE_DATA['paddlelite.libs'] += ['libiomp5.so']
6464

65+
if '${LITE_WITH_XPU}' == 'ON':
66+
shutil.copy('${XPU_INSTALL_DIR}/xpu/xdnn/so/libxpuapi.so', LIB_PATH)
67+
PACKAGE_DATA['paddlelite.libs'] += ['libxpuapi.so']
68+
shutil.copy('${XPU_INSTALL_DIR}/xpu/xre/so/libxpurt.so', LIB_PATH)
69+
PACKAGE_DATA['paddlelite.libs'] += ['libxpurt.so']
70+
6571
if '${LITE_WITH_NNADAPTER}' == 'ON':
6672
shutil.copy('${PADDLE_BINARY_DIR}/lite/backends/nnadapter/nnadapter/src/libnnadapter.so', LIB_PATH)
6773
PACKAGE_DATA['paddlelite.libs'] += ['libnnadapter.so']

lite/core/optimizer/mir/fusion/quant_dequant_op_fuser.cc

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ static float FindAbsMax(const float* input, int size) {
5656
template <typename T>
5757
void QuantizeTensorInPlace(Tensor* input, float scale) {
5858
if (input->precision() != PRECISION(kFloat)) {
59-
LOG(FATAL) << "Error: the precision of input should be float. actual is "
60-
<< PrecisionToStr(input->precision());
59+
LOG(WARNING)
60+
<< "Warning: the precision of input should be float, but actual is "
61+
<< PrecisionToStr(input->precision())
62+
<< ". There may be several ops share the same weight and the weight "
63+
"has already been transed to int8.";
64+
return;
6165
}
6266
Tensor temp_tensor;
6367
temp_tensor.CopyDataFrom(*input);
@@ -76,24 +80,22 @@ void QuantizeTensorInPlace(Tensor* input,
7680
const std::vector<float>& scales,
7781
int quant_axis) {
7882
if (input->precision() != PRECISION(kFloat)) {
79-
LOG(FATAL) << "Error: the precision of input should be float. actual is "
80-
<< PrecisionToStr(input->precision());
81-
}
82-
if (quant_axis != 0 && quant_axis != 1) {
83-
LOG(FATAL) << "Input error: quant_axis should be 0 or 1.";
83+
LOG(WARNING)
84+
<< "Warning: the precision of input should be float, but actual is "
85+
<< PrecisionToStr(input->precision())
86+
<< ". There may be several ops share the same weight and the weight "
87+
"has already been transed to int8.";
88+
return;
8489
}
90+
8591
Tensor origin_tensor;
8692
origin_tensor.CopyDataFrom(*input);
8793
input->clear();
8894

8995
auto dims = origin_tensor.dims();
9096
const int64_t channel = dims[quant_axis];
91-
if (dims.size() < 2) {
92-
LOG(FATAL) << "Error: the rank of input tensor should at least be 2.";
93-
}
94-
if (scales.size() != channel) {
95-
LOG(FATAL) << "Params Error: scale size should be equal to channel.";
96-
}
97+
CHECK_GE(dims.size(), 2);
98+
CHECK_EQ(scales.size(), channel);
9799
float* origin_data = origin_tensor.mutable_data<float>();
98100
T* quantized_data = input->mutable_data<T>();
99101

@@ -122,15 +124,23 @@ void QuantizeTensorInPlace(Tensor* input,
122124
});
123125
}
124126
}
127+
} else {
128+
LOG(FATAL)
129+
<< "Only support quant_axis is 0 or 1, but received quant_axis is "
130+
<< quant_axis;
125131
}
126132
}
127133

128134
// Per-layer cast tensor
129135
template <typename T>
130136
static void TensorCaster(Tensor* input) {
131137
if (input->precision() != PRECISION(kFloat)) {
132-
LOG(FATAL) << "Error: the precision of input should be float. actual is "
133-
<< PrecisionToStr(input->precision());
138+
LOG(WARNING)
139+
<< "Warning: the precision of input should be float, but actual is "
140+
<< PrecisionToStr(input->precision())
141+
<< ". There may be several ops share the same weight and the weight "
142+
"has already been transed to int8.";
143+
return;
134144
}
135145
Tensor temp_tensor;
136146
temp_tensor.CopyDataFrom(*input);

lite/kernels/arm/concat_compute.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void ConcatCompute::Run() {
8080
if (type == PRECISION(kUnk)) {
8181
type = tensor->precision();
8282
} else {
83-
VLOG(4) << "type: " << PrecisionRepr(type)
83+
VLOG(7) << "type: " << PrecisionRepr(type)
8484
<< ", tensor: " << PrecisionRepr(tensor->precision());
8585
#ifdef ENABLE_ARM_FP16
8686
if (type != tensor->precision()) {

lite/kernels/host/sampling_id_compute.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ namespace lite {
1919
namespace kernels {
2020
namespace host {
2121

22-
template <class T>
22+
template <typename T>
2323
void SamplingIdCompute<T>::PrepareForRun() {
2424
auto& param = this->template Param<param_t>();
2525
int seed = param.seed;
2626

27-
auto engine_ = std::make_shared<std::mt19937_64>();
27+
engine_ = std::make_shared<std::mt19937_64>();
2828
if (seed == 0) {
2929
std::random_device rd;
3030
seed = ((((uint64_t)rd()) << 32) + rd()) & 0x1FFFFFFFFFFFFF;
3131
}
3232
engine_->seed(seed);
3333
}
3434

35-
template <class T>
35+
template <typename T>
3636
void SamplingIdCompute<T>::Run() {
3737
auto& param = this->template Param<param_t>();
3838
const lite::Tensor* x = param.x;
@@ -44,6 +44,10 @@ void SamplingIdCompute<T>::Run() {
4444
auto out_data = out->mutable_data<int64_t>();
4545
std::uniform_real_distribution<T> dist(static_cast<T>(param.min),
4646
static_cast<T>(param.max));
47+
int seed = param.seed;
48+
if (seed != 0) {
49+
engine_->seed(seed);
50+
}
4751

4852
for (int64_t i = 0; i < batch_size; ++i) {
4953
T r = dist(*engine_);

lite/kernels/host/sampling_id_compute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace lite {
2323
namespace kernels {
2424
namespace host {
2525

26-
template <class T>
26+
template <typename T>
2727
class SamplingIdCompute
2828
: public KernelLite<TARGET(kHost), PRECISION(kAny), DATALAYOUT(kAny)> {
2929
public:

0 commit comments

Comments
 (0)