MCPcopy Create free account
hub / github.com/apple/ml-pointersect / to

Method to

cdslib/core/models/base_model.py:115–147  ·  view source on GitHub ↗

Send the model to device.

(self, device: torch.device)

Source from the content-addressed store, hash-verified

113 return parameters
114
115 def to(self, device: torch.device):
116 """
117 Send the model to device.
118 """
119 self.device = device
120
121 # base model
122 isModel = lambda net: isinstance(net, BaseModel)
123 nets = inspect.getmembers(self, isModel) # name, net
124 for name, net in nets:
125 getattr(self, name).to(device)
126
127 # nn module
128 isNNModule = lambda net: isinstance(net, torch.nn.Module)
129 nets = inspect.getmembers(self, isNNModule) # name, net
130 for name, net in nets:
131 getattr(self, name).to(device)
132
133 # buffer
134 for name in self.buffer_names:
135 b = getattr(self, name, None)
136 if b is None:
137 continue
138 else:
139 setattr(self, name, b.to(device=device))
140
141 # parameter
142 for name in self.parameter_names:
143 b = getattr(self, name, None)
144 if b is None:
145 continue
146 else:
147 setattr(self, name, b.to(device=device))
148
149 def train(self):
150 """Set all the nn.modules to train mode."""

Callers 6

optimizer_toFunction · 0.45
get_valid_maskFunction · 0.45
forwardMethod · 0.45
forwardMethod · 0.45
load_modelFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected