dygraph_utils.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
  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. from paddle import _legacy_C_ops
  15. from .framework import dygraph_only
  16. @dygraph_only
  17. def _append_activation_in_dygraph(input, act=None, use_cudnn=None):
  18. """Append activation in dygraph mode.
  19. Args:
  20. input: the input variable.
  21. act: activation type
  22. use_cudnn: if use cudnn
  23. Return the Variable after append activation
  24. """
  25. if act is None:
  26. return input
  27. attrs = ()
  28. if use_cudnn:
  29. attrs = ('use_cudnn', use_cudnn)
  30. act_op = getattr(_legacy_C_ops, act)
  31. return act_op(input, *attrs)