Skip to content
fn

detach_and_bump

void detach_and_bump(const int & a)

What to do when there was no graph position to adopt.

Nothing to adopt means the op is not differentiable — ceil, floor, round and sign all end the graph. a's contents no longer depend on what they were, so leaving its old grad_fn in place answers with the gradient of whatever produced a, unchanged. Cut it, which is the out-of-place convention — and cut its views with it, since they read the same constant values.

Only under an active GradMode: inside no_grad the write is an ordinary mutation of a tensor belonging to a graph built earlier, and severing it there would lose a chain the caller means to keep — the version counter guards that case, and it still runs.