MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / data_loader

Function data_loader

utils/pl_utils.py:47–77  ·  view source on GitHub ↗

Decorator to make any fx with this use the lazy property :param fn: :return:

(fn)

Source from the content-addressed store, hash-verified

45
46
47def data_loader(fn):
48 """
49 Decorator to make any fx with this use the lazy property
50 :param fn:
51 :return:
52 """
53
54 wraps(fn)
55 attr_name = '_lazy_' + fn.__name__
56
57 def _get_data_loader(self):
58 try:
59 value = getattr(self, attr_name)
60 except AttributeError:
61 try:
62 value = fn(self) # Lazy evaluation, done only once.
63 if (
64 value is not None and
65 not isinstance(value, list) and
66 fn.__name__ in ['test_dataloader', 'val_dataloader']
67 ):
68 value = [value]
69 except AttributeError as e:
70 # Guard against AttributeError suppression. (Issue #142)
71 traceback.print_exc()
72 error = f'{fn.__name__}: An AttributeError was encountered: ' + str(e)
73 raise RuntimeError(error) from e
74 setattr(self, attr_name, value) # Memoize evaluation.
75 return value
76
77 return _get_data_loader
78
79
80def parallel_apply(modules, inputs, kwargs_tup=None, devices=None): # pragma: no cover

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected