register_hook Class — pytorch Architecture
Architecture documentation for the register_hook class in Tensor.h from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/core/Tensor.h lines 76–87
template <typename T>
auto Tensor::register_hook(T&& hook) const -> Tensor::hook_return_void_t<T> {
// Return the grad argument in case of a hook with void return type to have an
// std::function with Tensor return type
static_assert(std::is_same_v<decltype(hook(Tensor())), void>,
"Expected hook to return void");
return _register_hook([fn=std::forward<T>(hook)](const TensorBase& grad_base) {
TensorRef grad(grad_base);
fn(*grad);
return Tensor();
});
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free