Skip to content

Commit 430b312

Browse files
authored
fix ncnn2int8 top_blob int8 scales saving for dequant only style (#6425)
1 parent 5da919f commit 430b312

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

docs/how-to-use-and-FAQ/quantized-int8-inference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Example with mobilenet, just need three steps.
88

99
### 1. Optimize model
1010

11+
NOTE: **If your model is converted via pnnx, skip this step.**
12+
1113
```shell
1214
./ncnnoptimize mobilenet.param mobilenet.bin mobilenet-opt.param mobilenet-opt.bin 0
1315
```

tools/modelwriter.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,10 @@ int ModelWriter::save(const char* parampath, const char* binpath)
900900
{
901901
fwrite_weight_data(op->weight_data_int8_scales, bp, 90, 100);
902902
fwrite_weight_data(op->bottom_blob_int8_scales, bp, 0.001, 1);
903-
fwrite_weight_data(op->top_blob_int8_scales, bp, 0.001, 1);
903+
if (op->int8_scale_term > 100)
904+
{
905+
fwrite_weight_data(op->top_blob_int8_scales, bp, 0.001, 1);
906+
}
904907
}
905908
#endif // NCNN_INT8
906909
}
@@ -1073,7 +1076,10 @@ int ModelWriter::save(const char* parampath, const char* binpath)
10731076
{
10741077
fwrite_weight_data(op->weight_data_int8_scales, bp, 90, 100);
10751078
fwrite_weight_data(op->bottom_blob_int8_scales, bp, 0.001, 1);
1076-
fwrite_weight_data(op->top_blob_int8_scales, bp, 0.001, 1);
1079+
if (op->int8_scale_term > 100)
1080+
{
1081+
fwrite_weight_data(op->top_blob_int8_scales, bp, 0.001, 1);
1082+
}
10771083
}
10781084
#endif // NCNN_INT8
10791085
}

0 commit comments

Comments
 (0)