@@ -323,7 +323,7 @@ def get_vulkan_quantizer(pt2e_quantize: str):
323323 return quantizer
324324
325325
326- def get_tosa_quantizer (version : str , pt2e_quantize : str ):
326+ def get_tosa_quantizer (version : str , pt2e_quantize : str , quantize_scope : str ):
327327 from executorch .backends .arm .quantizer .arm_quantizer import (
328328 get_symmetric_quantization_config ,
329329 TOSAQuantizer ,
@@ -335,34 +335,76 @@ def get_tosa_quantizer(version: str, pt2e_quantize: str):
335335 quantizer = TOSAQuantizer (compile_spec )
336336
337337 if pt2e_quantize == "tosa_8a8w" :
338- quantizer . set_global ( get_symmetric_quantization_config () )
338+ quantization_config = get_symmetric_quantization_config ()
339339 else :
340340 raise ValueError (f"Unsupported quantizer specification { pt2e_quantize } " )
341341
342+ _apply_arm_quantize_scope (
343+ quantizer ,
344+ quantization_config = quantization_config ,
345+ quantize_scope = quantize_scope ,
346+ backend_name = "TOSA" ,
347+ )
342348 return quantizer
343349
344350
345351def get_ethosu_quantizer (
346- target : str , system_config : str , memory_mode : str , pt2e_quantize : str
352+ target : str ,
353+ system_config : str ,
354+ memory_mode : str ,
355+ extra_flags : Optional [List [str ]],
356+ pt2e_quantize : str ,
357+ quantize_scope : str ,
347358):
348359 from executorch .backends .arm .ethosu .compile_spec import EthosUCompileSpec
349360 from executorch .backends .arm .quantizer .arm_quantizer import (
350361 EthosUQuantizer ,
362+ get_symmetric_a16w8_quantization_config ,
351363 get_symmetric_quantization_config ,
352364 )
353365
354- compile_spec = EthosUCompileSpec (target , system_config , memory_mode )
366+ compile_spec = EthosUCompileSpec (
367+ target = target ,
368+ system_config = None if system_config == "default" else system_config ,
369+ memory_mode = None if memory_mode == "default" else memory_mode ,
370+ extra_flags = extra_flags ,
371+ )
355372
356373 quantizer = EthosUQuantizer (compile_spec )
357374
358375 if pt2e_quantize == "ethosu_8a8w" :
359- quantizer .set_global (get_symmetric_quantization_config ())
376+ quantization_config = get_symmetric_quantization_config ()
377+ elif pt2e_quantize == "ethosu_16a8w" :
378+ quantization_config = get_symmetric_a16w8_quantization_config ()
360379 else :
361380 raise ValueError (f"Unsupported quantizer specification { pt2e_quantize } " )
362381
382+ _apply_arm_quantize_scope (
383+ quantizer ,
384+ quantization_config = quantization_config ,
385+ quantize_scope = quantize_scope ,
386+ backend_name = "Ethos-U" ,
387+ )
363388 return quantizer
364389
365390
391+ def _apply_arm_quantize_scope (
392+ quantizer ,
393+ * ,
394+ quantization_config ,
395+ quantize_scope : str ,
396+ backend_name : str ,
397+ ):
398+ if quantize_scope == "full" :
399+ quantizer .set_global (quantization_config )
400+ elif quantize_scope == "linear" :
401+ quantizer .set_module_type (torch .nn .Linear , quantization_config )
402+ else :
403+ raise ValueError (
404+ f"Unsupported { backend_name } quantization scope { quantize_scope } "
405+ )
406+
407+
366408def get_vgf_quantizer (
367409 compile_spec : Optional [str ],
368410 compiler_flags : Optional [List [str ]],
@@ -392,11 +434,10 @@ def get_vgf_quantizer(
392434 else :
393435 raise ValueError (f"Unsupported quantizer specification { pt2e_quantize } " )
394436
395- if quantize_scope == "full" :
396- quantizer .set_global (quantization_config )
397- elif quantize_scope == "linear" :
398- quantizer .set_module_type (torch .nn .Linear , quantization_config )
399- else :
400- raise ValueError (f"Unsupported VGF quantization scope { quantize_scope } " )
401-
437+ _apply_arm_quantize_scope (
438+ quantizer ,
439+ quantization_config = quantization_config ,
440+ quantize_scope = quantize_scope ,
441+ backend_name = "VGF" ,
442+ )
402443 return quantizer
0 commit comments