MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / add_pruning_method

Method add_pruning_method

python/oneflow/nn/utils/prune.py:291–311  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)

Callers 5

_get_composite_methodMethod · 0.95
__init__Method · 0.95
global_unstructuredFunction · 0.95

Calls 2

typeEnum · 0.85
formatMethod · 0.45

Tested by 2