Skip to content

Commit

Permalink
Add recipe for dynamic legacy compatibility
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 691951078
  • Loading branch information
marialyu authored and copybara-github committed Nov 1, 2024
1 parent eeb967e commit 5b44430
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions ai_edge_quantizer/quantizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def test_reloaded_calibration_succeeds(self, recipe_path):
)

@parameterized.parameters(
'recipes/dynamic_legacy_wi8_afp32_recipe.json',
'recipes/dynamic_wi8_afp32_recipe.json',
'recipes/default_af32w8float_recipe.json',
)
Expand Down
20 changes: 20 additions & 0 deletions ai_edge_quantizer/recipes/dynamic_legacy_wi8_afp32_recipe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"regex": ".*",
"operation": "*",
"algorithm_key": "min_max_uniform_quantize",
"op_config": {
"weight_tensor_config": {
"num_bits": 8,
"symmetric": true,
"granularity": "CHANNELWISE",
"dtype": "INT",
"block_size": 0
},
"compute_precision": "INTEGER",
"explicit_dequantize": false,
"skip_checks": false,
"min_weight_elements": 1024
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ def test_conv2d_transpose_model_int8_weight_only(
output_tolerance=1e-4 if granularity else 1e-2,
)

def test_conv2d_transpose_model_int8_drq(self):
recipe_path = test_utils.get_path_to_datafile(
'../../recipes/dynamic_wi8_afp32_recipe.json'
)
@parameterized.parameters(
'../../recipes/dynamic_legacy_wi8_afp32_recipe.json',
'../../recipes/dynamic_wi8_afp32_recipe.json',
)
def test_conv2d_transpose_model_int8_drq(self, recipe_path):
recipe_path = test_utils.get_path_to_datafile(recipe_path)
self._quantizer.load_quantization_recipe(recipe_path)

# Check model size.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ def test_depthwise_conv2d_model_int8_weight_only(
output_tolerance=1e-4 if channel_wise_weight else 1e-2,
)

def test_depthwise_conv2d_model_int8_drq(self):
recipe_path = test_utils.get_path_to_datafile(
'../../recipes/dynamic_wi8_afp32_recipe.json'
)
self._quantizer.load_quantization_recipe(recipe_path)
@parameterized.parameters(
'../../recipes/dynamic_legacy_wi8_afp32_recipe.json',
'../../recipes/dynamic_wi8_afp32_recipe.json',
)
def test_depthwise_conv2d_model_int8_drq(self, recipe_path):
full_recipe_path = test_utils.get_path_to_datafile(recipe_path)
self._quantizer.load_quantization_recipe(full_recipe_path)

# Check model size.
quant_result = self._quantizer.quantize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def setUp(self):
@parameterized.parameters(
'../../recipes/default_af32w8float_recipe.json',
'../../recipes/default_af32w4float_recipe.json',
'../../recipes/dynamic_legacy_wi8_afp32_recipe.json',
'../../recipes/dynamic_wi8_afp32_recipe.json',
)
def test_embedding_lookup_model_int_weight_only(self, recipe_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def test_input_output_explicit_set_quantize(
('../../recipes/default_a16w8_recipe.json', 7),
('../../recipes/default_af32w8float_recipe.json', 0),
('../../recipes/dynamic_wi8_afp32_recipe.json', 0),
('../../recipes/dynamic_legacy_wi8_afp32_recipe.json', 0),
)
def test_input_output_with_default_recipe(
self, recipe_path, activation_type_code
Expand Down

0 comments on commit 5b44430

Please sign in to comment.