Skip to content

Commit

Permalink
deprecated spectral_ and bjorck_ initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
franckma31 committed Feb 3, 2025
1 parent baa4ee2 commit 8a8ed6b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 3 additions & 0 deletions deel/torchlip/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# =====================================================================================
"""
"""
import warnings
import torch

from .normalizers import bjorck_normalization
Expand Down Expand Up @@ -57,6 +58,7 @@ def spectral_(
eps_spectral (float): stopping criterion of iterative power method
maxiter_spectral (int): maximum number of iterations for the power iteration
"""
warnings.warn("spectral_ initialization is deprecated, use torch.nn.init.orthogonal_ instead")
with torch.no_grad():
tensor.copy_(
spectral_normalization(
Expand Down Expand Up @@ -91,6 +93,7 @@ def bjorck_(
maxiter_bjorck (int): maximum number of iterations for bjorck algorithm
beta: Value to use for the :math:`\beta` parameter.
"""
warnings.warn("bjorck_ initialization is deprecated, use torch.nn.init.orthogonal_ instead")
with torch.no_grad():
spectral_tensor = spectral_normalization(
tensor, None, eps=eps_spectral, maxiter=maxiter_spectral
Expand Down
8 changes: 1 addition & 7 deletions tests/utils_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def __call__(self, **kwargs):
Model = module_Unavailable_class
compute_layer_sv = module_Unavailable_class
OrthLinearRegularizer = module_Unavailable_class
SpectralInitializer = module_Unavailable_class

MODEL_PATH = "model.h5"
LIP_LAYERS = "torchlip_layers"
Expand Down Expand Up @@ -591,13 +592,6 @@ def scaleDivAlpha(alpha):
return 1.0 / (1 + 1.0 / alpha)


def SpectralInitializer(eps_spectral, eps_bjorck):
if eps_bjorck is None:
return partial(spectral_, eps_spectral=eps_spectral)
else:
return partial(bjorck_, eps_spectral=eps_spectral, eps_bjorck=eps_bjorck)


class tAdd(torch.nn.Module):
def __init__(self):
super(tAdd, self).__init__()
Expand Down

0 comments on commit 8a8ed6b

Please sign in to comment.