From 2b2c13df2c4ab33abdf32680d3481babf11c0015 Mon Sep 17 00:00:00 2001 From: Shiyi Zheng Date: Wed, 15 Jul 2026 17:57:14 +0800 Subject: [PATCH] recipe(opus-mt-fr-en): add CPU fp32 and fp16 configs --- .../cpu/translation_fp16_decoder_config.json | 76 +++++++++++++++++++ .../cpu/translation_fp16_encoder_config.json | 53 +++++++++++++ .../cpu/translation_fp32_decoder_config.json | 54 +++++++++++++ .../cpu/translation_fp32_encoder_config.json | 45 +++++++++++ 4 files changed, 228 insertions(+) create mode 100644 examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp16_decoder_config.json create mode 100644 examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp16_encoder_config.json create mode 100644 examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp32_decoder_config.json create mode 100644 examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp32_encoder_config.json diff --git a/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp16_decoder_config.json b/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp16_decoder_config.json new file mode 100644 index 000000000..7762e86fa --- /dev/null +++ b/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp16_decoder_config.json @@ -0,0 +1,76 @@ +{ + "export": { + "opset_version": 17, + "batch_size": 1, + "export_params": true, + "do_constant_folding": true, + "verbose": false, + "dynamo": false, + "enable_hierarchy_tags": true, + "clean_onnx": false, + "hierarchy_tag_format": "full", + "input_tensors": [ + {"name": "decoder_input_ids", "dtype": "int32", "shape": [1, 1], "value_range": [0, 59514]}, + {"name": "encoder_hidden_states", "dtype": "float32", "shape": [1, 512, 512], "value_range": [0, 1]}, + {"name": "attention_mask", "dtype": "int64", "shape": [1, 512]}, + {"name": "decoder_attention_mask", "dtype": "int64", "shape": [1, 512]}, + {"name": "cache_position", "dtype": "int64", "shape": [1]}, + {"name": "past_0_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_0_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_1_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_1_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_2_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_2_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_3_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_3_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_4_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_4_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_5_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_5_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]} + ], + "output_tensors": [ + {"name": "logits"}, + {"name": "present_0_key"}, {"name": "present_0_value"}, + {"name": "present_1_key"}, {"name": "present_1_value"}, + {"name": "present_2_key"}, {"name": "present_2_value"}, + {"name": "present_3_key"}, {"name": "present_3_value"}, + {"name": "present_4_key"}, {"name": "present_4_value"}, + {"name": "present_5_key"}, {"name": "present_5_value"} + ] + }, + "optim": { + "clamp_constant_values": true, + "gelu_fusion": true, + "matmul_add_fusion": true, + "remove_isnan_in_attention_mask": true + }, + "quant": { + "mode": "fp16", + "samples": 10, + "calibration_method": "minmax", + "weight_type": "uint8", + "activation_type": "uint8", + "per_channel": false, + "symmetric": false, + "weight_symmetric": null, + "activation_symmetric": null, + "save_calibration": false, + "distribution": "uniform", + "seed": null, + "calibration_load_path": null, + "calibration_save_path": null, + "op_types_to_quantize": null, + "nodes_to_exclude": null, + "task": "text2text-generation", + "model_id": "Helsinki-NLP/opus-mt-fr-en", + "model_type": "marian", + "fp16_keep_io_types": true, + "fp16_op_block_list": null + }, + "compile": null, + "loader": { + "task": "text2text-generation", + "model_class": "MarianDecoderWrapper", + "model_type": "marian" + } +} diff --git a/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp16_encoder_config.json b/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp16_encoder_config.json new file mode 100644 index 000000000..3e64f6310 --- /dev/null +++ b/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp16_encoder_config.json @@ -0,0 +1,53 @@ +{ + "export": { + "opset_version": 17, + "batch_size": 1, + "export_params": true, + "do_constant_folding": true, + "verbose": false, + "dynamo": false, + "enable_hierarchy_tags": true, + "clean_onnx": false, + "hierarchy_tag_format": "full", + "input_tensors": [ + {"name": "input_ids", "dtype": "int32", "shape": [1, 512], "value_range": [0, 59514]}, + {"name": "attention_mask", "dtype": "int32", "shape": [1, 512], "value_range": [0, 2]} + ], + "output_tensors": [{"name": "encoder_hidden_states"}] + }, + "optim": { + "clamp_constant_values": true, + "gelu_fusion": true, + "matmul_add_fusion": true, + "remove_isnan_in_attention_mask": true + }, + "quant": { + "mode": "fp16", + "samples": 10, + "calibration_method": "minmax", + "weight_type": "uint8", + "activation_type": "uint8", + "per_channel": false, + "symmetric": false, + "weight_symmetric": null, + "activation_symmetric": null, + "save_calibration": false, + "distribution": "uniform", + "seed": null, + "calibration_load_path": null, + "calibration_save_path": null, + "op_types_to_quantize": null, + "nodes_to_exclude": null, + "task": "feature-extraction", + "model_id": "Helsinki-NLP/opus-mt-fr-en", + "model_type": "marian", + "fp16_keep_io_types": true, + "fp16_op_block_list": null + }, + "compile": null, + "loader": { + "task": "feature-extraction", + "model_class": "MarianEncoderWrapper", + "model_type": "marian" + } +} diff --git a/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp32_decoder_config.json b/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp32_decoder_config.json new file mode 100644 index 000000000..4ca782f78 --- /dev/null +++ b/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp32_decoder_config.json @@ -0,0 +1,54 @@ +{ + "export": { + "opset_version": 17, + "batch_size": 1, + "export_params": true, + "do_constant_folding": true, + "verbose": false, + "dynamo": false, + "enable_hierarchy_tags": true, + "clean_onnx": false, + "hierarchy_tag_format": "full", + "input_tensors": [ + {"name": "decoder_input_ids", "dtype": "int32", "shape": [1, 1], "value_range": [0, 59514]}, + {"name": "encoder_hidden_states", "dtype": "float32", "shape": [1, 512, 512], "value_range": [0, 1]}, + {"name": "attention_mask", "dtype": "int64", "shape": [1, 512]}, + {"name": "decoder_attention_mask", "dtype": "int64", "shape": [1, 512]}, + {"name": "cache_position", "dtype": "int64", "shape": [1]}, + {"name": "past_0_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_0_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_1_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_1_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_2_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_2_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_3_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_3_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_4_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_4_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_5_key", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]}, + {"name": "past_5_value", "dtype": "float32", "shape": [1, 8, 512, 64], "value_range": [0, 1]} + ], + "output_tensors": [ + {"name": "logits"}, + {"name": "present_0_key"}, {"name": "present_0_value"}, + {"name": "present_1_key"}, {"name": "present_1_value"}, + {"name": "present_2_key"}, {"name": "present_2_value"}, + {"name": "present_3_key"}, {"name": "present_3_value"}, + {"name": "present_4_key"}, {"name": "present_4_value"}, + {"name": "present_5_key"}, {"name": "present_5_value"} + ] + }, + "optim": { + "clamp_constant_values": true, + "gelu_fusion": true, + "matmul_add_fusion": true, + "remove_isnan_in_attention_mask": true + }, + "quant": null, + "compile": null, + "loader": { + "task": "text2text-generation", + "model_class": "MarianDecoderWrapper", + "model_type": "marian" + } +} diff --git a/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp32_encoder_config.json b/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp32_encoder_config.json new file mode 100644 index 000000000..41be91aa9 --- /dev/null +++ b/examples/recipes/Helsinki-NLP_opus-mt-fr-en/cpu/cpu/translation_fp32_encoder_config.json @@ -0,0 +1,45 @@ +{ + "export": { + "opset_version": 17, + "batch_size": 1, + "export_params": true, + "do_constant_folding": true, + "verbose": false, + "dynamo": false, + "enable_hierarchy_tags": true, + "clean_onnx": false, + "hierarchy_tag_format": "full", + "input_tensors": [ + { + "name": "input_ids", + "dtype": "int32", + "shape": [1, 512], + "value_range": [0, 59514] + }, + { + "name": "attention_mask", + "dtype": "int32", + "shape": [1, 512], + "value_range": [0, 2] + } + ], + "output_tensors": [ + { + "name": "encoder_hidden_states" + } + ] + }, + "optim": { + "clamp_constant_values": true, + "gelu_fusion": true, + "matmul_add_fusion": true, + "remove_isnan_in_attention_mask": true + }, + "quant": null, + "compile": null, + "loader": { + "task": "feature-extraction", + "model_class": "MarianEncoderWrapper", + "model_type": "marian" + } +}