Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize performance for pynative #730

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mindcv/optim/adamw.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
from mindspore.nn.optim import Optimizer
from mindspore.nn.optim.optimizer import opt_init_args_register

try:
from mindspore import jit
except ImportError:
from mindspore import ms_function as jit


def _check_param_value(beta1, beta2, eps, prim_name):
"""Check the type of inputs."""
Expand Down Expand Up @@ -154,6 +159,7 @@ def __init__(
self.reciprocal_scale = Tensor(1.0 / loss_scale, ms.float32)
self.clip = clip

@jit
def construct(self, gradients):
lr = self.get_lr()
gradients = scale_grad(gradients, self.reciprocal_scale)
Expand Down
6 changes: 6 additions & 0 deletions mindcv/optim/adan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from mindspore.common.tensor import Tensor
from mindspore.nn.optim.optimizer import Optimizer, opt_init_args_register

try:
from mindspore import jit
except ImportError:
from mindspore import ms_function as jit

_adan_opt = ops.MultitypeFuncGraph("adan_opt")


Expand Down Expand Up @@ -144,6 +149,7 @@ def __init__(

self.weight_decay = Tensor(weight_decay, mstype.float32)

@jit
def construct(self, gradients):
params = self._parameters
moment1 = self.moment1
Expand Down
6 changes: 6 additions & 0 deletions mindcv/optim/lion.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from mindspore.nn.optim import Optimizer
from mindspore.nn.optim.optimizer import opt_init_args_register

try:
from mindspore import jit
except ImportError:
from mindspore import ms_function as jit


def _check_param_value(beta1, beta2, prim_name):
"""Check the type of inputs."""
Expand Down Expand Up @@ -142,6 +147,7 @@ def __init__(
self.reciprocal_scale = Tensor(1.0 / loss_scale, ms.float32)
self.clip = clip

@jit
def construct(self, gradients):
lr = self.get_lr()
gradients = scale_grad(gradients, self.reciprocal_scale)
Expand Down
6 changes: 6 additions & 0 deletions mindcv/optim/nadam.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
from mindspore.nn.optim import Optimizer
from mindspore.nn.optim.optimizer import opt_init_args_register

try:
from mindspore import jit
except ImportError:
from mindspore import ms_function as jit


def _check_param_value(beta1, beta2, eps, prim_name):
"""Check the type of inputs."""
Expand Down Expand Up @@ -48,6 +53,7 @@ def __init__(
self.mu_schedule = Parameter(initializer(1, [1], ms.float32), name="mu_schedule")
self.beta2_power = Parameter(initializer(1, [1], ms.float32), name="beta2_power")

@jit
def construct(self, gradients):
lr = self.get_lr()
params = self.parameters
Expand Down