MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / EmptyInitOnDevice

Class EmptyInitOnDevice

diffsynth/models/stepvideo_text_encoder.py:30–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28
29
30class EmptyInitOnDevice(torch.overrides.TorchFunctionMode):
31 def __init__(self, device=None):
32 self.device = device
33
34 def __torch_function__(self, func, types, args=(), kwargs=None):
35 kwargs = kwargs or {}
36 if getattr(func, '__module__', None) == 'torch.nn.init':
37 if 'tensor' in kwargs:
38 return kwargs['tensor']
39 else:
40 return args[0]
41 if self.device is not None and func in torch.utils._device._device_constructors() and kwargs.get('device') is None:
42 kwargs['device'] = self.device
43 return func(*args, **kwargs)
44
45
46def with_empty_init(func):

Callers 1

wrapperFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected