Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 8096e15

Browse files
authored
raise exception for GMPruningModifier args that are no longer supported (#640) (#641)
1 parent 77166e4 commit 8096e15

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/sparseml/pytorch/sparsification/pruning/modifier_pruning_magnitude.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ class GMPruningModifier(BaseGradualPruningModifier, BaseGMPruningModifier):
113113
:param global_sparsity: set True to use global magnitude pruning, False for
114114
layer-wise. Default is False. [DEPRECATED] - use GlobalMagnitudePruningModifier
115115
for global magnitude pruning and MagnitudePruningModifier for layer-wise
116+
:param phased: NO LONGER SUPPORTED - former parameter for AC/DC pruning. Will raise
117+
an exception if set to True. Use ACDCPruningModifier for AC/DC pruning
118+
:param score_type: NO LONGER SUPPORTED - former parameter for using different
119+
sparsification algorithms, will raise an exception if set to the non default
120+
value
116121
"""
117122

118123
def __init__(
@@ -128,8 +133,10 @@ def __init__(
128133
log_types: Union[str, List[str]] = ALL_TOKEN,
129134
mask_type: str = "unstructured",
130135
global_sparsity: bool = False,
136+
phased: bool = False,
137+
score_type: str = "magnitude",
131138
):
132-
self._check_warn_global_sparsity(global_sparsity)
139+
self._check_deprecated_params(global_sparsity, phased, score_type)
133140

134141
super(GMPruningModifier, self).__init__(
135142
params=params,
@@ -180,13 +187,29 @@ def global_sparsity(self) -> bool:
180187
"""
181188
return self._global_sparsity
182189

183-
def _check_warn_global_sparsity(self, global_sparsity):
190+
def _check_deprecated_params(
191+
self,
192+
global_sparsity: bool,
193+
phased: bool,
194+
score_type: str,
195+
):
184196
if self.__class__.__name__ == "GMPruningModifier" and global_sparsity is True:
185197
_LOGGER.warning(
186198
"Use of global_sparsity parameter in GMPruningModifier is now "
187199
"deprecated. Use GlobalMagnitudePruningModifier instead for global "
188200
"magnitude pruning"
189201
)
202+
if phased:
203+
raise ValueError(
204+
f"Use of phased=True in {self.__class__.__name__} is no longer "
205+
"supported use the ACDCPruningModifier for phased (AC/DC) pruning"
206+
)
207+
if score_type != "magnitude":
208+
raise ValueError(
209+
"use of score_type to specify a sparsification algorithm is no longer "
210+
"supported. Use the specific pruning modifier for the desired "
211+
f"sparsification algorithm instead. Found score_type={score_type}"
212+
)
190213

191214

192215
@PyTorchModifierYAML()

0 commit comments

Comments
 (0)