You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

grad_debug_ops.py 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Generate bprop for debug ops"""
  16. from .. import operations as P
  17. from ..composite.multitype_ops.zeros_like_impl import zeros_like
  18. from .grad_base import bprop_getters
  19. # Unused parameters are placeholders.
  20. @bprop_getters.register(P.ScalarSummary)
  21. def get_bprop_scalar_summary(self):
  22. """Generate bprop for ScalarSummary"""
  23. def bprop(tag, x, out, dout):
  24. return tag, zeros_like(x)
  25. return bprop
  26. @bprop_getters.register(P.TensorSummary)
  27. def get_bprop_tensor_summary(self):
  28. """Generate bprop for TensorSummary"""
  29. def bprop(tag, x, out, dout):
  30. return tag, zeros_like(x)
  31. return bprop
  32. @bprop_getters.register(P.ImageSummary)
  33. def get_bprop_image_summary(self):
  34. """Generate bprop for ImageSummary"""
  35. def bprop(tag, x, out, dout):
  36. return tag, zeros_like(x)
  37. return bprop
  38. @bprop_getters.register(P.HistogramSummary)
  39. def get_bprop_histogram_summary(self):
  40. """Generate bprop for HistogramSummary"""
  41. def bprop(tag, x, out, dout):
  42. return tag, zeros_like(x)
  43. return bprop
  44. @bprop_getters.register(P.InsertGradientOf)
  45. def get_bprop_insert_gradient_of(self):
  46. """Generate bprop for InsertGradientOf"""
  47. f = self.f
  48. def bprop(x, out, dout):
  49. return (f(dout),)
  50. return bprop