Does Post-training full integer quantization support BERT?
@yyoon is already working on this.
Since May 3, 2023.
Assessment
This issue has not been assessed yet.
Description
Does Post-training full integer quantization in https://www.tensorflow.org/lite/performance/post_training_integer_quant#convert_using_float_fallback_quantization support BERT?
I convert my pb model to tf lite:
dataset = create_dataset()
def representative_dataset():
for data in dataset:
yield {
"token_type_ids": np.array(data.segment_ids),
"attention_mask": np.array(data.input_mask),
"input_ids": np.array(data.input_ids),
}
converter = tf.lite.TFLiteConverter.from_saved_model(pb_dir)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset
tflite_quant_model = converter.convert()
tflite_path = res_tf_lite_file
open(tflite_path, "wb").write(tflite_quant_model)
assert os.path.exists(tflite_path)
print("tflite model={} converted successfully.".format(tflite_path))
interpreter = tf.lite.Interpreter(model_path=tflite_path)
# Get input and output tensors
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
print(f'tflite input {input_details}')
print(f'tflite output {output_details}')
I use float fallback quantization from https://www.tensorflow.org/lite/performance/post_training_integer_quant.
However the result is totally different compare to the not quantization result.
Anyone can help? Thanks a lot!
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 349
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tensorflow/model-optimization
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
tensorflow/model-optimization#1301 · 1 comment ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
tensorflow/model-optimization#1272 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 50/100
tensorflow/model-optimization#1270 · 2 comments ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
tensorflow/model-optimization#1241 ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
tensorflow/model-optimization#1182 · 1 comment ·
All issues in tensorflow/model-optimization
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/skills#1811 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
datalayer/mcp-compose#42 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
UKGovernmentBEIS/inspect_evals#2523 ·