Skip to content

Commit 6badd1e

Browse files
author
namgyu-youn
committed
Replcae torch.norm with torch.linalg.vector_norm in L1-norm
torch.norm is deprecated and may be removed in future PyTorch releases
1 parent 5a2bf34 commit 6badd1e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

modelopt/torch/nas/modules/conv.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ def _estimate_importance(self) -> TracedHp.Importance:
139139
return None
140140
weight = self._parameters["weight"] # retrieve full weight tensor
141141
c_in = weight.shape[1]
142-
return torch.norm(torch.reshape(weight.detach().transpose(0, 1), (c_in, -1)), dim=1)
142+
return torch.linalg.vector_norm(
143+
torch.reshape(weight.detach().transpose(0, 1), (c_in, -1)), dim=1
144+
)
143145

144146
def _setup(self):
145147
# only support ungrouped conv or grouped conv with in_channels == out_channels
@@ -249,4 +251,6 @@ def _estimate_importance(self) -> TracedHp.Importance:
249251
return None
250252
weight = self._parameters["weight"] # retrieve full weight tensor
251253
c_in = weight.shape[0]
252-
return torch.norm(torch.reshape(weight.detach(), (c_in, -1)), dim=1)
254+
return torch.linalg.vector_norm(
255+
torch.reshape(weight.detach().transpose(0, 1), (c_in, -1)), dim=1
256+
)

modelopt/torch/nas/modules/linear.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _get_bias(mod: "_DynamicLinear", bias: torch.Tensor | None) -> torch.Tensor
4141
return get_sliced_tensor(mod, bias, "out_features")
4242

4343
def _estimate_importance(self) -> TracedHp.Importance:
44-
return self._parameters["weight"].detach().norm(dim=0)
44+
return torch.linalg.vector_norm(self._parameters["weight"].detach(), dim=0)
4545

4646
def _setup(self):
4747
# register hyperparameters

0 commit comments

Comments
 (0)