MCPcopy Create free account
hub / github.com/pytorch/pytorch / _traverse_obj

Method _traverse_obj

test/test_modules.py:298–306  ·  view source on GitHub ↗
(self, obj, func)

Source from the content-addressed store, hash-verified

296 self.assertEqual(input_args[0].grad, input_arg_copy[0].grad)
297
298 def _traverse_obj(self, obj, func):
299 if isinstance(obj, (tuple, list)):
300 return type(obj)(self._traverse_obj(o, func) for o in obj)
301 elif isgenerator(obj):
302 return tuple(self._traverse_obj(o, func) for o in obj)
303 elif isinstance(obj, dict):
304 return {name: self._traverse_obj(o, func) for name, o in obj.items()}
305 elif isinstance(obj, (torch.Tensor, torch.nn.Parameter)):
306 return func(obj)
307
308 def _retain_grad(self, obj):
309 # gradients needs to be retained to check for grad. This is useful when

Callers 7

_retain_gradMethod · 0.95
_get_gradsMethod · 0.95
_zero_gradMethod · 0.95
_make_non_contiguousMethod · 0.95
_to_mem_formatMethod · 0.95
_check_out_mem_formatMethod · 0.95

Calls 3

isinstanceFunction · 0.85
funcFunction · 0.50
itemsMethod · 0.45

Tested by

no test coverage detected