(
self,
value_threshold: float,
including_act: bool = False,
act_multiplier: float = 0.5,
including_bias: bool = False,
bias_multiplier: float = 0.5,
method: EqualizationMethod = EqualizationMethod.ABSOLUTE_MAX
)
| 316 | self.downstream_layers = downstream_layers |
| 317 | |
| 318 | def equalize( |
| 319 | self, |
| 320 | value_threshold: float, |
| 321 | including_act: bool = False, |
| 322 | act_multiplier: float = 0.5, |
| 323 | including_bias: bool = False, |
| 324 | bias_multiplier: float = 0.5, |
| 325 | method: EqualizationMethod = EqualizationMethod.ABSOLUTE_MAX |
| 326 | ): |
| 327 | # extract key value from pair |
| 328 | upstream_key_values, downstream_key_values = [], [] |
| 329 | for op in self.upstream_layers: |
| 330 | key_value = EqualizationHelper.key_value_from_upstream( |
| 331 | op=op, including_bias=including_bias, including_act=including_act, |
| 332 | bias_multiplier=bias_multiplier, act_multiplier=act_multiplier) |
| 333 | upstream_key_values.append(key_value) |
| 334 | |
| 335 | for op in self.downstream_layers: |
| 336 | key_value = EqualizationHelper.key_value_from_downstream(op=op) |
| 337 | downstream_key_values.append(key_value) |
| 338 | |
| 339 | upstream_key_values = self.reduce_by_axis(upstream_key_values, method=method) |
| 340 | downstream_key_values = self.reduce_by_axis(downstream_key_values, method=method) |
| 341 | |
| 342 | # calculate scale |
| 343 | scale = self.calculate_scale( |
| 344 | upstream_key_values=upstream_key_values, |
| 345 | downstream_key_values=downstream_key_values, |
| 346 | value_threshold=value_threshold) |
| 347 | |
| 348 | # write back all params |
| 349 | for op in self.upstream_layers: |
| 350 | EqualizationHelper.scale_to_upstream(op, scale) |
| 351 | |
| 352 | for op in self.downstream_layers: |
| 353 | EqualizationHelper.scale_to_downstream(op, scale) |
| 354 | |
| 355 | def channel_split( |
| 356 | self, |
no test coverage detected