MCPcopy Create free account
hub / github.com/ChenWu98/cycle-diffusion / nested_truncate

Function nested_truncate

trainer/trainer.py:98–106  ·  view source on GitHub ↗

Truncate `tensors` at `limit` (even if it's a nested list/tuple/dict of tensors).

(tensors, limit)

Source from the content-addressed store, hash-verified

96
97
98def nested_truncate(tensors, limit):
99 "Truncate `tensors` at `limit` (even if it's a nested list/tuple/dict of tensors)."
100 if isinstance(tensors, (list, tuple)):
101 return type(tensors)(nested_truncate(t, limit) for t in tensors)
102 elif isinstance(tensors, dict):
103 return type(tensors)({k: nested_truncate(v, limit) for k, v in tensors.items()})
104 elif tensors is None:
105 return None
106 return tensors[:limit]
107
108
109def _secs2timedelta(secs):

Callers 1

evaluation_loopMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected