r"""Adds a child pruning ``method`` to the container. Args: method (subclass of BasePruningMethod): child pruning method to be added to the container.
(self, method)
| 289 | self.add_pruning_method(method) |
| 290 | |
| 291 | def add_pruning_method(self, method): |
| 292 | r"""Adds a child pruning ``method`` to the container. |
| 293 | Args: |
| 294 | method (subclass of BasePruningMethod): child pruning method |
| 295 | to be added to the container. |
| 296 | """ |
| 297 | # check that we're adding a pruning method to the container |
| 298 | if not isinstance(method, BasePruningMethod) and method is not None: |
| 299 | raise TypeError( |
| 300 | "{} is not a BasePruningMethod subclass".format(type(method)) |
| 301 | ) |
| 302 | elif method is not None and self._tensor_name != method._tensor_name: |
| 303 | raise ValueError( |
| 304 | "Can only add pruning methods acting on " |
| 305 | "the parameter named '{}' to PruningContainer {}.".format( |
| 306 | self._tensor_name, self |
| 307 | ) |
| 308 | + " Found '{}'".format(method._tensor_name) |
| 309 | ) |
| 310 | # if all checks passed, add to _pruning_methods tuple |
| 311 | self._pruning_methods += (method,) # type: ignore[operator] |
| 312 | |
| 313 | def __len__(self): |
| 314 | return len(self._pruning_methods) |