Co-authored-by: shaoyf02<shaoyifan1@huawei.com> # message auto-generated for no-merge-commit merge: merge 210_autograd into v2.1.0 Support registering functions on AutogradPrivateUse1 via YAML dispatch configuration Created-by: shaoyf Commit-by: shaoyf02 Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one ` /kind <>` line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: 背景:解决高版本下默认针对没有注册autograd相关key但进行反向的api的告警 方案:通过提供支持添加dispatch字段注册到autogradprivateuse1上,避免出现告警: 例如: ``` - func: npu_moe_token_unpermute_with_routing_map(Tensor permuted_tokens, Tensor sorted_indices, int[] restore_shape, *, Tensor? probs=None, Tensor? routing_map=None, bool drop_and_pad=False) -> Tensor op_api: [v2.1, newest] dispatch: AutogradPrivateUse1: npu_moe_token_unpermute_with_routing_map ``` 具体样例: 添加dispatch前存在告警,添加后无 ``` [W919 12:36:08.793215810 compiler_depend.ts:67] Warning: npu::npu_moe_token_unpermute_with_routing_map: an autograd kernel was not registered to the Autograd key(s) but we are trying to backprop through it. This may lead to silently incorrect behavior. This behavior is deprecated and will be removed in a future version of PyTorch. If your operator is differentiable, please ensure you have registered an autograd kernel to the correct Autograd key (e.g. DispatchKey::Autograd, DispatchKey::CompositeImplicitAutograd). If your operator is not differentiable, or to squash this warning and use the previous behavior, please register torch::CppFunction::makeFallthrough() to DispatchKey::Autograd. (function operator()) ``` **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!25032
72 lines
1.5 KiB
C++
72 lines
1.5 KiB
C++
#include <c10/core/TensorImpl.h>
|
|
#include <c10/core/Allocator.h>
|
|
#include <ATen/DeviceGuard.h>
|
|
#include <ATen/NativeFunctions.h>
|
|
#include <ATen/MetaFunctions.h>
|
|
#include <ATen/NamedTensorUtils.h>
|
|
#include <ATen/Utils.h>
|
|
#include <ATen/WrapDimUtils.h>
|
|
#include <ATen/Dispatch.h>
|
|
#include <c10/util/Half.h>
|
|
#include <c10/core/UndefinedTensorImpl.h>
|
|
#include <c10/util/Optional.h>
|
|
#include <ATen/Tensor.h>
|
|
#include <ATen/Functions.h>
|
|
#include <ATen/native/Resize.h>
|
|
#include <ATen/core/op_registration/adaption.h>
|
|
|
|
#include <cstddef>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <utility>
|
|
|
|
#include <ATen/Config.h>
|
|
#include <torch/library.h>
|
|
#include <torch/csrc/autograd/function.h>
|
|
#include <torch/csrc/jit/frontend/tracer.h>
|
|
|
|
#include "torch_npu/csrc/aten/NPUNativeFunctions.h"
|
|
#include "torch_npu/csrc/aten/VariableType.h"
|
|
#include "torch_npu/csrc/core/npu/NPUException.h"
|
|
#include "torch_npu/csrc/core/npu/NPURecovery.h"
|
|
#include "torch_npu/csrc/framework/interface/EnvVariables.h"
|
|
#include "torch_npu/csrc/framework/OpHook.h"
|
|
#include "op_plugin/OpInterface.h"
|
|
|
|
namespace at_npu {
|
|
|
|
namespace native {
|
|
|
|
${custom_op_definitions}
|
|
|
|
namespace {
|
|
|
|
TORCH_LIBRARY(npu, m) {
|
|
|
|
${custom_schema_registrations}
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
namespace {
|
|
|
|
TORCH_LIBRARY_IMPL(npu, PrivateUse1, m) {
|
|
|
|
${custom_impl_registrations}
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
namespace {
|
|
|
|
TORCH_LIBRARY_IMPL(npu, AutogradPrivateUse1, m) {
|
|
|
|
${custom_autograd_impl_registrations}
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
} // namespace native
|
|
|
|
} // namespace at_npu
|