Manage quantization annotations for TOSA-compatible backends. .. warning:: Setting ``use_composable_quantizer=True`` enables an experimental API surface that may change without notice.
| 467 | |
| 468 | |
| 469 | class TOSAQuantizer(Quantizer): |
| 470 | """Manage quantization annotations for TOSA-compatible backends. |
| 471 | |
| 472 | .. warning:: |
| 473 | Setting ``use_composable_quantizer=True`` enables an experimental API |
| 474 | surface that may change without notice. |
| 475 | |
| 476 | """ |
| 477 | |
| 478 | def __init__( |
| 479 | self, |
| 480 | compile_spec_or_tosa_spec, |
| 481 | use_composable_quantizer: bool = False, |
| 482 | ) -> None: |
| 483 | """Create a TOSA quantizer from a TOSA spec or Arm compile spec. |
| 484 | |
| 485 | .. warning:: |
| 486 | Setting ``use_composable_quantizer=True`` enables an experimental |
| 487 | API surface that may change without notice. |
| 488 | |
| 489 | """ |
| 490 | self.use_composable_quantizer = use_composable_quantizer |
| 491 | self.quantizer: _TOSAQuantizerV1 | _TOSAQuantizerV2 |
| 492 | if use_composable_quantizer: |
| 493 | logger.info( |
| 494 | "Using composable quantizer implementation in the arm backend. See https://github.com/pytorch/executorch/issues/17701" |
| 495 | ) |
| 496 | self.quantizer = _TOSAQuantizerV2(compile_spec_or_tosa_spec) |
| 497 | else: |
| 498 | logger.info( |
| 499 | "Using default quantizer in the arm backend. This quantizer is planned to be replaced by the composable quantizer implementation in the future, see https://github.com/pytorch/executorch/issues/17701" |
| 500 | ) |
| 501 | self.quantizer = _TOSAQuantizerV1(compile_spec_or_tosa_spec) |
| 502 | |
| 503 | @property |
| 504 | def tosa_spec(self): |
| 505 | return self.quantizer.tosa_spec |
| 506 | |
| 507 | @property |
| 508 | def compile_spec(self): |
| 509 | return self.quantizer.compile_spec |
| 510 | |
| 511 | @property |
| 512 | def global_config(self): |
| 513 | return self.quantizer.global_config |
| 514 | |
| 515 | @global_config.setter |
| 516 | def global_config(self, value: Optional[QuantizationConfig]) -> None: |
| 517 | if isinstance(self.quantizer, _TOSAQuantizerV1): |
| 518 | self.quantizer.global_config = value |
| 519 | else: |
| 520 | raise NotImplementedError( |
| 521 | "Composable quantizer does not allow setting global_config directly. Please use set_global() instead." |
| 522 | ) |
| 523 | |
| 524 | @property |
| 525 | def io_config(self): |
| 526 | if isinstance(self.quantizer, _TOSAQuantizerV1): |
no outgoing calls