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

Dian xt ms #29

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
优化算子使用
  • Loading branch information
AmiyaSX committed Feb 7, 2023
commit 6948ace9531d6e1bb9da07229bb54a8191415cf5
8 changes: 4 additions & 4 deletions xt/model/dqn/dqn_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def construct(self, x):

@_grad_scale.register("Tensor", "Tensor")
def tensor_grad_scale(scale, grad):
return grad * ms.ops.cast(ms.ops.Reciprocal()(scale), ms.ops.dtype(grad))
return grad * ops.cast(ops.Reciprocal()(scale), ops.dtype(grad))


class MyTrainOneStepCell(ms.nn.TrainOneStepWithLossScaleCell):
Expand All @@ -123,11 +123,11 @@ def construct(self, state, label):
loss = self.network(state, label)
scaling_sens = self.scale_sense
status, scaling_sens = self.start_overflow_check(loss, scaling_sens)
scaling_sens_filled = ms.ops.ones_like(loss) * ms.ops.cast(scaling_sens, ms.ops.dtype(loss))
scaling_sens_filled = ops.ones_like(loss) * ops.cast(scaling_sens, ops.dtype(loss))
grads = self.grad(self.network, weights)(state, label, scaling_sens_filled)
grads = self.hyper_map(ms.ops.partial(_grad_scale, scaling_sens), grads)
grads = self.hyper_map(ops.partial(_grad_scale, scaling_sens), grads)
if self.grad_clip:
grads = ms.ops.clip_by_global_norm(grads, self.clipnorm)
grads = ops.clip_by_global_norm(grads, self.clipnorm)
grads = self.grad_reducer(grads)
cond = self.get_overflow_status(status, grads)
overflow = self.process_loss_scale(cond)
Expand Down