Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

grad_multiply.py 550 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  1. # Copyright (c) 2017-present, Facebook, Inc.
  2. # All rights reserved.
  3. #
  4. # This source code is licensed under the license found in the LICENSE file in
  5. # the root directory of this source tree. An additional grant of patent rights
  6. # can be found in the PATENTS file in the same directory.
  7. import torch
  8. class GradMultiply(torch.autograd.Function):
  9. @staticmethod
  10. def forward(ctx, x, scale):
  11. ctx.scale = scale
  12. res = x.new(x)
  13. return res
  14. @staticmethod
  15. def backward(ctx, grad):
  16. return grad * ctx.scale, None
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...