Configuration for differentiable quantization.
| 85 | |
| 86 | @dataclass |
| 87 | class QuantizerConfig: |
| 88 | """Configuration for differentiable quantization.""" |
| 89 | |
| 90 | attributes: Dict[str, AttributeQuantizerConfig] = field( |
| 91 | default_factory=_default_attribute_configs |
| 92 | ) |
| 93 | |
| 94 | def copy_for_attribute_overrides( |
| 95 | self, overrides: Optional[Mapping[str, Mapping[str, Any]]] |
| 96 | ) -> "QuantizerConfig": |
| 97 | if not overrides: |
| 98 | return self |
| 99 | updated = { |
| 100 | name: AttributeQuantizerConfig( |
| 101 | enabled=config.enabled, |
| 102 | bitwidth=config.bitwidth, |
| 103 | clamp_range=config.clamp_range, |
| 104 | warmup_steps=config.warmup_steps, |
| 105 | warmup_bitwidth=config.warmup_bitwidth, |
| 106 | mode=config.mode, |
| 107 | ) |
| 108 | for name, config in self.attributes.items() |
| 109 | } |
| 110 | for name, cfg in overrides.items(): |
| 111 | if name not in updated: |
| 112 | continue |
| 113 | attr_cfg = updated[name] |
| 114 | for key, value in cfg.items(): |
| 115 | if not hasattr(attr_cfg, key): |
| 116 | raise KeyError(f"Unknown quantizer setting '{name}.{key}'") |
| 117 | setattr(attr_cfg, key, value) |
| 118 | return QuantizerConfig(attributes=updated) |
| 119 | |
| 120 | |
| 121 | @dataclass |
no outgoing calls
no test coverage detected