MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / RegisterTensorHook

Function RegisterTensorHook

oneflow/api/python/utils/tensor_utils.cpp:104–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104Maybe<void> RegisterTensorHook(const std::shared_ptr<Tensor>& self,
105 const AutogradMeta::Hook& hook) {
106 CHECK_OR_RETURN(self->requires_grad())
107 << "cannot register a hook on a tensor that doesn't require gradient";
108 if (!self->grad_fn_node()) { JUST(AddAccumulateFunctionNode(self)); }
109 self->mut_autograd_meta()->add_hook(hook);
110 return Maybe<void>::Ok();
111}
112
113Maybe<void> RegisterTensorPostGradAccumulationHook(const std::shared_ptr<Tensor>& self,
114 const AutogradMeta::Hook& hook) {

Callers 2

PyTensorObject_set_dataFunction · 0.85

Calls 5

add_hookMethod · 0.80
requires_gradMethod · 0.45
grad_fn_nodeMethod · 0.45
mut_autograd_metaMethod · 0.45

Tested by

no test coverage detected