"tests/vscode:/vscode.git/clone" did not exist on "650f6ee1e0b3c2888a2c6d7db9c3d159cae5a583"
Commit c0e3fa40 authored by yuguo960516yuguo's avatar yuguo960516yuguo
Browse files

gitignore

parent de2e6515
# This file is used by clang-format to autoformat paddle source code
#
# The clang-format is part of llvm toolchain.
# It need to install llvm and clang to format source code style.
#
# The basic usage is,
# clang-format -i -style=file PATH/TO/SOURCE/CODE
#
# The -style=file implicit use ".clang-format" file located in one of
# parent directory.
# The -i means inplace change.
#
# The document of clang-format is
# http://clang.llvm.org/docs/ClangFormat.html
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
---
Language: Cpp
BasedOnStyle: Google
IndentWidth: 2
TabWidth: 2
ContinuationIndentWidth: 4
AccessModifierOffset: -1 # The private/protected/public has no indent in class
Standard: Cpp11
AllowAllParametersOfDeclarationOnNextLine: true
BinPackParameters: false
BinPackArguments: false
IncludeBlocks: Preserve
IncludeIsMainSourceRegex: (\.cu)$
...
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------
# Options affecting formatting.
# -----------------------------
with section("format"):
# How wide to allow formatted cmake files
line_width = 80
# ------------------------------------------------
# Options affecting comment reflow and formatting.
# ------------------------------------------------
with section("markup"):
# enable comment markup parsing and reflow
enable_markup = False
# If comment markup is enabled, don't reflow the first comment block in each
# listfile. Use this to preserve formatting of your copyright/license
# statements.
first_comment_is_literal = True
# ----------------------------------
# Options affecting listfile parsing
# ----------------------------------
with section("parse"):
# Additional FLAGS and KWARGS for custom commands
additional_commands = {
"cc_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"nv_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"hip_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"xpu_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"hip_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"hip_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"go_library": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"copy": {
"kwargs": {
"SRCS": '*',
"DSTS": '*',
}
},
"cc_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"nv_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"hip_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"xpu_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"go_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
},
"py_test": {
"kwargs": {
"SRCS": '*',
"DEPS": '*',
}
}
}
*.DS_Store
build/
*.user
.vscode
.idea
.project
.cproject
.pydevproject
Makefile
.test_env/
third_party/
*~
bazel-*
!build/*.deb
name: 🐛 报BUG Bug Report
description: 报告一个可复现的BUG帮助我们修复框架。 Report a bug to help us reproduce and fix it.
labels: [type/bug-report, status/new-issue]
body:
- type: markdown
attributes:
value: >
#### 在向Paddle报bug之前,请先查询[历史issue](https://github.com/PaddlePaddle/Paddle/issues)是否报过同样的bug。
#### Before submitting a bug, please make sure the issue hasn't been already addressed by searching through [the existing and past issues](https://github.com/PaddlePaddle/Paddle/issues).
- type: textarea
id: code
attributes:
label: bug描述 Describe the Bug
description: |
请清晰简洁的描述这个bug,最好附上bug复现环境、bug复现步骤及最小代码集,以便我们可以通过运行代码来重现错误。代码片段需要尽可能简洁,请花些时间去掉不相关的代码以帮助我们有效地调试。我们希望通过复制代码并运行得到与你相同的结果,请避免任何外部数据或包含相关的导入等。例如:
```python
# 导入所有必要的库。 All necessary imports at the beginning.
# paddlepaddle <= 2.1.2
import paddle
# 一个简洁的片段,能够定位到bug。 A succinct reproducing example trimmed down to the essential parts.
a = paddle.rand(shape=[1,4])
b = paddle.rand(shape=[1,4])
a.stop_gradient = False
b.stop_gradient = False
c = paddle.zeros((4, 4))
c[0, :] = a/b
print('Is c requires grad: ', not c.stop_gradient) # 注意:这里出现了bug,期望requires_grad=True
```
如果代码太长,请将可执行代码放到[AIStudio](https://aistudio.baidu.com/aistudio/index)中并将项目设置为公开(或者放到github gist上),请在项目中描述清楚bug复现步骤,在issue中描述期望结果与实际结果。
如果你报告的是一个报错信息,请将完整回溯的报错贴在这里,并使用 ` ```三引号块``` `展示错误信息。
placeholder: |
请清晰简洁的描述这个bug。A clear and concise description of what the bug is.
```python
# 最小可复现代码。 Sample code to reproduce the problem.
```
```shell
带有完整回溯的报错信息。 The error message you got, with the full traceback.
```
validations:
required: true
- type: textarea
id: others
attributes:
label: 其他补充信息 Additional Supplementary Information
description: |
如果你还有其他需要补充的内容,请写在这里。
If you have anything else to add, please write it here.
validations:
required: false
- type: markdown
attributes:
value: >
感谢你的贡献 🎉!Thanks for your contribution 🎉!
name: 🚀 新需求 Feature Request
description: 提交一个你对Paddle的新需求。 Submit a request for a new Paddle feature.
labels: [type/feature-request, status/new-issue]
body:
- type: markdown
attributes:
value: >
#### 你可以在这里提出你对Paddle框架的新需求,包括但不限于:功能或模型缺失、功能不全或无法使用、精度/性能不符合预期等。
#### You could submit a request for a new Paddle feature here, including but not limited to: new features or models, incomplete or unusable features, accuracy/performance not as expected, etc.
- type: textarea
id: description
attributes:
label: 需求描述 Feature Description
description: |
请尽可能包含任务目标、需求场景、功能描述等信息,全面的信息有利于我们准确评估你的需求。
Please include as much information as possible, such as mission objectives, requirement scenarios, functional descriptions, etc. Comprehensive information will help us accurately assess your feature request.
value: "任务目标(请描述你正在做的项目是什么,如模型、论文、项目是什么?); <br /> 需求场景(请描述你的项目中为什么需要用此功能); <br /> 功能描述(请简单描述或设计这个功能)"
validations:
required: true
- type: textarea
id: alternatives
attributes:
label: 替代实现 Alternatives
description: |
如果你考虑过的任何替代解决方案或功能,请简要描述下,我们会综合评估。
A description of any alternative solutions or features you've considered, if any.
validations:
required: false
- type: markdown
attributes:
value: >
感谢你的贡献 🎉!Thanks for your contribution 🎉!
name: 🗂 安装 Build/Installation Issue
description: 报告一个安装问题。 Report an issue related to build or install Paddle.
labels: [type/build, status/new-issue]
body:
- type: markdown
attributes:
value: >
#### 安装请参考[官网文档](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/develop/install/pip/linux-pip.html),若未能解决你的问题,你可以在这里提issue。
#### Before submitting a Build/Installation Issue, please make sure you have visited the [official website](https://www.paddlepaddle.org.cn/documentation/docs/en/install/index_en.html).
- type: textarea
id: error
attributes:
label: 问题描述 Issue Description
description: |
请详细描述你的问题,同步贴出报错信息、日志/代码关键片段、复现步骤,以便我们快速排查问题。
Please describe your problem in detail, and synchronously post the error message, key log/code snippet, and reproduction steps, so that we can quickly troubleshoot the problem.
validations:
required: true
- type: textarea
id: environment
attributes:
label: 版本&环境信息 Version & Environment Information
description: |
请参考以下命令运行脚本[summary_env.py](https://github.com/PaddlePaddle/Paddle/blob/develop/tools/summary_env.py)获取版本&环境信息,并将输出拷贝在这里。
Please run the following and paste the output below.
```shell
wget https://raw.githubusercontent.com/PaddlePaddle/Paddle/develop/tools/summary_env.py
python3 -m pip install distro
python3 summary_env.py
```
若运行脚本出现问题,请在issue中说明,并提供以下信息:
1. PaddlePaddle版本:请提供你的PaddlePaddle版本号(如2.0.0)或CommitID。
2. CPU(可选):请提供CPU型号,MKL/OpenBlas/MKLDNN/等数学库的使用情况,是否支持AVX指令集。
3. GPU:请提供GPU型号,CUDA(如cuda10.2)和CUDNN版本号(如cudnn7.6.5)。
4. 系统环境:请说明系统类型、版本(如Mac OS 10.14)。
5. Python版本(如python 3.7)。
6. (可选)若安装过程遇到问题,请提供安装方式(pip/conda/docker/源码编译)和相应的安装命令。
7. (可选)若使用paddle过程中,遇到了无法使用gpu相关问题,请在命令行中键入`nvidia-smi`和`nvcc -V`,提供这两个命令输出的截图。
8. (可选)若使用特殊硬件,请单独注明。
placeholder: |
****************************************
Paddle version:
Paddle With CUDA:
OS:
Python version:
CUDA version:
cuDNN version:
Nvidia driver version:
****************************************
validations:
required: true
- type: markdown
attributes:
value: >
感谢你的贡献 🎉!Thanks for your contribution 🎉!
name: 📚 文档 Documentation Issue
description: 反馈一个官网文档错误。 Report an issue related to https://www.paddlepaddle.org.cn/.
labels: [type/docs, status/new-issue]
body:
- type: markdown
attributes:
value: >
#### 请确认反馈的问题来自PaddlePaddle官网文档:https://www.paddlepaddle.org.cn/ 。
#### Before submitting a Documentation Issue, Please make sure that issue is related to https://www.paddlepaddle.org.cn/.
- type: textarea
id: link
attributes:
label: 文档链接&描述 Document Links & Description
description: |
请说明有问题的文档链接以及该文档存在的问题。
Please fill in the link to the document and describe the question.
validations:
required: true
- type: textarea
id: error
attributes:
label: 请提出你的建议 Please give your suggestion
description: |
请告诉我们,你希望如何改进这个文档。或者你可以提个PR修复这个问题。[教程参考](https://github.com/PaddlePaddle/docs/wiki#%E8%B4%A1%E7%8C%AE%E6%96%87%E6%A1%A3)
Please tell us how you would like to improve this document. Or you can submit a PR to fix this problem.
validations:
required: false
- type: markdown
attributes:
value: >
感谢你的贡献 🎉!Thanks for your contribution 🎉!
name: 🙋🏼‍♀️🙋🏻‍♂️提问 Ask a Question
description: 提出一个使用/咨询问题。 Ask a usage or consultation question.
labels: [type/question, status/new-issue]
body:
- type: markdown
attributes:
value: >
#### 你可以在这里提出一个使用/咨询问题,提问之前请确保:
- 1)已经百度/谷歌搜索过你的问题,但是没有找到解答;
- 2)已经在官网查询过[API文档](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html)与[FAQ](https://www.paddlepaddle.org.cn/documentation/docs/zh/faq/index_cn.html),但是没有找到解答;
- 3)已经在[历史issue](https://github.com/PaddlePaddle/Paddle/issues)中搜索过,没有找到同类issue或issue未被解答。
#### You could ask a usage or consultation question here, before your start, please make sure:
- 1) You have searched your question on Baidu/Google, but found no answer;
- 2) You have checked the [API documentation](https://www.paddlepaddle.org.cn/documentation/docs/en/api/index_en.html), but found no answer;
- 3) You have searched [the existing and past issues](https://github.com/PaddlePaddle/Paddle/issues), but found no similar issue or the issue has not been answered.
- type: textarea
id: question
attributes:
label: 请提出你的问题 Please ask your question
validations:
required: true
name: 🧩 其他 Others
description: 提出其他问题。 Report any other non-support related issues.
labels: [type/others, status/new-issue]
body:
- type: markdown
attributes:
value: >
#### 你可以在这里提出任何前面几类模板不适用的问题,包括但不限于:优化性建议、框架使用体验反馈、版本兼容性问题、报错信息不清楚等。
#### You can report any issues that are not applicable to the previous types of templates, including but not limited to: enhancement suggestions, feedback on the use of the framework, version compatibility issues, unclear error information, etc.
- type: textarea
id: others
attributes:
label: 问题描述 Please describe your issue
validations:
required: true
- type: markdown
attributes:
value: >
感谢你的贡献 🎉! Thanks for your contribution 🎉!
<!-- Demo: https://github.com/PaddlePaddle/Paddle/pull/24810 -->
### PR types
<!-- One of [ New features | Bug fixes | Function optimization | Performance optimization | Breaking changes | Others ] -->
### PR changes
<!-- One of [ OPs | APIs | Docs | Others ] -->
### Describe
<!-- Describe what this PR does -->
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
rev: v1.1.14
hooks:
- id: remove-crlf
files: (?!.*third_party)^.*$ | (?!.*book)^.*$
- repo: https://github.com/psf/black.git
rev: 22.8.0
hooks:
- id: black
files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
exclude: |
(?x)^(
python/paddle/fluid/tests/unittests/dygraph_to_static/test_error.py|
python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py
)$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-symlinks
- id: detect-private-key
files: (?!.*third_party)^.*$ | (?!.*book)^.*$
- id: end-of-file-fixer
- id: sort-simple-yaml
files: (op|backward|op_[a-z_]+)\.yaml$
- repo: local
hooks:
- id: clang-format
name: clang-format
description: Format files with ClangFormat.
entry: bash ./tools/codestyle/clang_format.hook -i
language: system
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps)$
exclude: |
(?x)^(
paddle/fluid/distributed/ps/thirdparty/round_robin.h
)$
- repo: local
hooks:
- id: cpplint-cpp-source
name: cpplint
description: Check C++ code style using cpplint.py.
entry: bash ./tools/codestyle/cpplint_pre_commit.hook
language: system
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx)$
- repo: local
hooks:
- id: pylint-doc-string
name: pylint
description: Check python docstring style using docstring_checker.
entry: bash ./tools/codestyle/pylint_pre_commit.hook
language: system
files: \.(py)$
- repo: local
hooks:
- id: copyright_checker
name: copyright_checker
entry: python ./tools/codestyle/copyright.hook
language: system
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|xpu|kps|py|sh)$
exclude: |
(?x)^(
paddle/utils/.*
)$
- repo: local
hooks:
- id: auto-generate-cmakelists
name: auto-generate-cmakelists
entry: bash ./tools/gen_ut_cmakelists.hook
language: system
files: testslist.csv$
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
# exclude paddle/fluid/operators/CMakeLists.txt, see the comment
# https://github.com/PaddlePaddle/Paddle/pull/43057#pullrequestreview-993471860
exclude: |
(?x)^(
paddle/fluid/operators/CMakeLists.txt
)$
- repo: https://github.com/cmake-lint/cmake-lint
rev: 1.4.2
hooks:
- id: cmakelint
args: [--config=./tools/codestyle/.cmakelintrc]
......@@ -242,7 +242,7 @@ if(WITH_GPU)
endif()
if(WITH_ROCM)
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} ${SAFE_GPU_COMMON_FLAGS} --gpu-max-threads-per-block=1024")
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} ${SAFE_GPU_COMMON_FLAGS} --gpu-max-threads-per-block=1024")
endif()
# Disable -Werror, otherwise the compile will fail for rocblas_gemm_ex
......
.timestamp
*.o
*.a
.svn
GPATH
GRTAGS
GTAGS
.idl*
*~
*.pyc
*.pb.cc
*.pb.h
*_pb2.py
output/
google/
Makefile
log/
.pptool_config
hf/
build
issue.info
ar
g++
gcc
ld
ld-linux-x86-64.so.2
x86_64-scm-linux-gnu/
.lint.*.md5
.idea/
.test_env
Paddle_wrap.cxx
Paddle_wrap.h
paddle.py
py_paddle-*.whl
py_paddle/paddle.py
.py_paddle_extra_link_flags
HPPL_ERROR_LOG
unittest.list
proto
dist
setup.py
generated/**
autocodegen/generated_example/
\ No newline at end of file
fluid_generated/**
eager_generated/**
\ No newline at end of file
add_subdirectory(backwards)
add_subdirectory(forwards)
cc_library(
scale_node
SRCS scale_node.cc
DEPS global_utils phi phi_api grad_node_info)
if(NOT (NOT WITH_PYTHON AND ON_INFER))
cc_library(
final_dygraph_node
SRCS nodes.cc ${eager_manual_nodes}
DEPS ${eager_deps})
add_dependencies(final_dygraph_node eager_codegen)
endif()
// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/fluid/eager/api/generated/eager_generated/backwards/scale_node.h"
#include "glog/logging.h"
#include "paddle/fluid/eager/api/utils/global_utils.h"
#include "paddle/fluid/eager/eager_tensor.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/errors.h"
#include "paddle/phi/kernels/scale_kernel.h"
namespace egr {
template <typename DeviceContext>
static void ScaleDeviceDispatch(const phi::DenseTensor& dense_tensor,
const DeviceContext& dev_ctx,
float scale,
float bias,
bool bias_after_scale,
phi::DenseTensor* dense_out) {
switch (dense_tensor.dtype()) {
case phi::DataType::FLOAT64: {
phi::ScaleKernel<
double,
typename paddle::framework::ConvertToPhiContext<DeviceContext>::TYPE>(
static_cast<const typename paddle::framework::ConvertToPhiContext<
DeviceContext>::TYPE&>(dev_ctx),
dense_tensor /* tensor */,
scale /* scale */,
bias /* bias */,
bias_after_scale /* bias_after_scale */,
dense_out /* out tensor */);
break;
}
case phi::DataType::FLOAT32: {
phi::ScaleKernel<
float,
typename paddle::framework::ConvertToPhiContext<DeviceContext>::TYPE>(
static_cast<const typename paddle::framework::ConvertToPhiContext<
DeviceContext>::TYPE&>(dev_ctx),
dense_tensor /* tensor */,
scale /* scale */,
bias /* bias */,
bias_after_scale /* bias_after_scale */,
dense_out /* out tensor */);
break;
}
case phi::DataType::INT64: {
phi::ScaleKernel<
int64_t,
typename paddle::framework::ConvertToPhiContext<DeviceContext>::TYPE>(
static_cast<const typename paddle::framework::ConvertToPhiContext<
DeviceContext>::TYPE&>(dev_ctx),
dense_tensor /* tensor */,
scale /* scale */,
bias /* bias */,
bias_after_scale /* bias_after_scale */,
dense_out /* out tensor */);
break;
}
case phi::DataType::INT32: {
phi::ScaleKernel<
int32_t,
typename paddle::framework::ConvertToPhiContext<DeviceContext>::TYPE>(
static_cast<const typename paddle::framework::ConvertToPhiContext<
DeviceContext>::TYPE&>(dev_ctx),
dense_tensor /* tensor */,
scale /* scale */,
bias /* bias */,
bias_after_scale /* bias_after_scale */,
dense_out /* out tensor */);
break;
}
default: {
PADDLE_THROW(paddle::platform::errors::Fatal(
"Detected unsupported data type."
"Only Float64, Float32, Int64, Int32 are supported for now."));
break;
}
}
}
void ScaleAPI(const paddle::experimental::Tensor& x,
float scale,
float bias,
bool bias_after_scale,
paddle::experimental::Tensor* out) {
// TODO(jiabin): Support multiple tensor here, Create DenseTensor is not a
// proper way to Demo it
// Run Forward Function
auto dense_tensor = std::dynamic_pointer_cast<phi::DenseTensor>(x.impl());
// Init output tensor
auto tensor_meta = phi::DenseTensorMeta(
dense_tensor->dtype(), dense_tensor->dims(), dense_tensor->layout());
auto place = dense_tensor->place();
size_t bytes_size =
phi::product(dense_tensor->dims()) * SizeOf(dense_tensor->dtype());
auto dense_out = std::make_shared<phi::DenseTensor>(
paddle::memory::Alloc(place, bytes_size), std::move(tensor_meta));
// Handle Device Context
const paddle::platform::Place& expected_kernel_place =
Controller::Instance().GetExpectedPlace();
paddle::platform::DeviceContextPool& pool =
paddle::platform::DeviceContextPool::Instance();
if (expected_kernel_place == paddle::platform::CPUPlace()) {
auto* dev_ctx =
dynamic_cast<phi::CPUContext*>(pool.Get(expected_kernel_place));
if (!dev_ctx) {
PADDLE_THROW(paddle::platform::errors::Fatal(
"Cannot convert device_context to phi::CPUContext."
"This indicates backend mismatch."
"Pleas double check your expected place"));
}
ScaleDeviceDispatch<phi::CPUContext>(*dense_tensor.get(),
*dev_ctx,
scale,
bias,
bias_after_scale,
dense_out.get());
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
} else if (expected_kernel_place == paddle::platform::CUDAPlace()) {
auto* dev_ctx =
dynamic_cast<phi::GPUContext*>(pool.Get(expected_kernel_place));
if (!dev_ctx) {
PADDLE_THROW(paddle::platform::errors::Fatal(
"Cannot convert device_context to CUDADeviceContext."
"This indicates backend mismatch."
"Pleas double check your expected place"));
}
ScaleDeviceDispatch<phi::GPUContext>(*dense_tensor.get(),
*dev_ctx,
scale,
bias,
bias_after_scale,
dense_out.get());
#endif
} else {
PADDLE_THROW(paddle::platform::errors::Fatal(
"Detected unsupported backend."
"Only CPU and CUDA Backend are supported for now."
"Please double check if your backend falls into the above two "
"categories."));
}
out->set_impl(dense_out);
}
void GradNodeScale::SetTensorWrappers_X(
const std::vector<paddle::experimental::Tensor>& tensors) {
// Does nothing for scale
}
void GradNodeScale::SetAttributes_scale(float scale) { scale_ = scale; }
paddle::small_vector<std::vector<paddle::experimental::Tensor>,
kSlotSmallVectorSize>
GradNodeScale::operator()(
paddle::small_vector<std::vector<paddle::experimental::Tensor>,
kSlotSmallVectorSize>& grads, // NOLINT
bool create_graph,
bool is_new_grad) {
// 1. Check Output Size
VLOG(6) << "grad size is: " << grads.size();
PADDLE_ENFORCE(
((grads.size() == 1) && (grads[0].size() == 1)),
paddle::platform::errors::Fatal(
"ScaleGradNode takes exactly 1 grad tensor."
"However received: %d",
"This indicates an issue with Eager Dygraph Backward logic",
grads.size()));
paddle::small_vector<std::vector<paddle::experimental::Tensor>,
kSlotSmallVectorSize>
outs;
// 2. Create needed out parttern
paddle::experimental::Tensor out;
// Apply Gradient Hooks
if (GradientHooksRegistered()) {
// TODO(jiabin): Shall we apply hook slot by slot here or accept
// vector<vector<phi::tensor>> to apply all hooks?
paddle::small_vector<std::vector<paddle::experimental::Tensor>,
kSlotSmallVectorSize>
hooked_grads = ApplyGradientHooks(grads);
ScaleAPI(/* slot by slot set */ hooked_grads[0][0],
scale_,
0.0 /* bias */,
true /* bias_after_scale */,
&out);
} else {
ScaleAPI(
grads[0][0], scale_, 0.0 /* bias */, true /* bias_after_scale */, &out);
}
return {{out}};
}
} // namespace egr
// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "paddle/fluid/eager/grad_node_info.h"
#include "paddle/fluid/eager/tensor_wrapper.h"
/*
Each Operation has a specific GradNode inheritted from GradNodeBase
A specific GradNode defines
1. Input Tensors
2. overrides operator() to perform actual backward computations
TODO: Generate GradNode via auto-code-generation
*/
namespace egr {
void ScaleAPI(const paddle::experimental::Tensor& x,
float scale,
float bias,
bool bias_after_scale,
paddle::experimental::Tensor* out);
class GradNodeScale : public GradNodeBase {
public:
// Constructor: configure fwd input tensors to grad node
GradNodeScale(size_t bwd_in_slot_num, size_t bwd_out_slot_num)
: GradNodeBase(bwd_in_slot_num, bwd_out_slot_num) {}
~GradNodeScale() override = default;
// Functor: perform backward computations
virtual paddle::small_vector<std::vector<paddle::experimental::Tensor>,
kSlotSmallVectorSize>
operator()(paddle::small_vector<std::vector<paddle::experimental::Tensor>,
kSlotSmallVectorSize>& grads, // NOLINT
bool create_graph = false,
bool is_new_grad = false) override;
void ClearTensorWrappers() override { VLOG(6) << "Do nothing here now"; }
void SetTensorWrappers_X(
const std::vector<paddle::experimental::Tensor>& tensors);
void SetAttributes_scale(float scale);
std::string name() override { return "scale node"; }
// Members: define fwd input tensors
// For Scale there is no fwd input tensor needed
std::shared_ptr<GradNodeBase> Copy() const override {
auto copied_node = std::make_shared<GradNodeScale>(*this);
return copied_node;
}
private:
float scale_{1.0};
};
} // namespace egr
cc_library(
eager_scale
SRCS scale.cc
DEPS phi_api phi autograd_meta scale_node)
if(NOT (NOT WITH_PYTHON AND ON_INFER))
cc_library(
final_dygraph_function
SRCS dygraph_functions.cc ${eager_manual_functions}
DEPS ${eager_deps})
add_dependencies(final_dygraph_function eager_codegen)
endif()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment