Extracting grad tensors from a subgraph

Here is what I want to do: