MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / to_cpu

Method to_cpu

lightx2v/common/modules/weight_module.py:103–123  ·  view source on GitHub ↗
(self, non_blocking=False)

Source from the content-addressed store, hash-verified

101 yield from module.named_parameters(prefix + name + ".")
102
103 def to_cpu(self, non_blocking=False):
104 for name, param in self._parameters.items():
105 if param is not None:
106 if hasattr(param, "cpu"):
107 self._parameters[name] = param.to("cpu", non_blocking=non_blocking)
108 setattr(self, name, self._parameters[name])
109 elif hasattr(param, "to_cpu"):
110 self._parameters[name].to_cpu()
111 setattr(self, name, self._parameters[name])
112 for module in self._modules.values():
113 if isinstance(module, WeightModuleList):
114 for i in range(len(module)):
115 for m in module[i]._modules.values():
116 if m is not None and hasattr(m, "to_cpu"):
117 m.to_cpu()
118 for m in module[i]._parameters.values():
119 if m is not None and hasattr(m, "to_cpu"):
120 m.to_cpu()
121 else:
122 if module is not None and hasattr(module, "to_cpu"):
123 module.to_cpu()
124
125 def to_cuda(self, non_blocking=False):
126 """Move parameters to GPU device (supports cuda/intel xpu)"""

Callers 1

to_cpu_asyncMethod · 0.45

Calls 3

cpuMethod · 0.80
itemsMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected