MCPcopy Index your code
hub / github.com/pytorch/tutorials / compute_sample_grads

Function compute_sample_grads

intermediate_source/per_sample_grads.py:91–96  ·  view source on GitHub ↗

manually process each sample with per sample gradient

(data, targets)

Source from the content-addressed store, hash-verified

89
90
91def compute_sample_grads(data, targets):
92 """ manually process each sample with per sample gradient """
93 sample_grads = [compute_grad(data[i], targets[i]) for i in range(batch_size)]
94 sample_grads = zip(*sample_grads)
95 sample_grads = [torch.stack(shards) for shards in sample_grads]
96 return sample_grads
97
98per_sample_grads = compute_sample_grads(data, targets)
99

Callers 1

Calls 1

compute_gradFunction · 0.85

Tested by

no test coverage detected