Is there a way to calculate the gradient wrt the input without applying it?

My question is much the same as : Can I get the gradient of a tensor with respect to the input without applying the input?

Is there a way to get the gradient wrt. to an input and then inserting a new input? Something that would allow us to find phi_z(x,z,t)|z=a.

I have tried forcing a layer to be equal to phi_z(x,z,t), and the evaluating z. But this did not yield great results.

Any help would be appreciated. Thanks.

/cc @thea @Joana Just to monitor stackoverflow->forum duplicates