This is definitely the right way to change the value of the Tensor without changing the graph.
Just to be sure we understand each other. Here is a code sample that shows what this does (most likely nothing).
import torch


# The loss is given by the sum operation.
# The backward of this op does not use the output value
def my_fn(x, modify_res=False):
    loss = (2*x).sum(0, keepdim=True)
    if modify_res:
        with torch.no_grad():
            loss[0] = 10
    return loss

inp = torch.rand(1, requires_grad=True)

my_fn(inp).backward()
print("base")
print(inp.grad)

inp.grad.zero_()

my_fn(inp, modify_res=True).backward()
print("modified")
print(inp.grad)