(
self, layer, inp_blobs, out_blobs, add_prefix=True, reset_grad=False, **kwargs
)
| 174 | return workspace.FetchBlob(tag) |
| 175 | |
| 176 | def AddLayerWrapper( |
| 177 | self, layer, inp_blobs, out_blobs, add_prefix=True, reset_grad=False, **kwargs |
| 178 | ): |
| 179 | # auxiliary routine to adjust tags |
| 180 | def adjust_tag(blobs, on_device): |
| 181 | if blobs.__class__ == str: |
| 182 | _blobs = on_device + blobs |
| 183 | elif blobs.__class__ == list: |
| 184 | _blobs = list(map(lambda tag: on_device + tag, blobs)) |
| 185 | else: # blobs.__class__ == model_helper.ModelHelper or something else |
| 186 | _blobs = blobs |
| 187 | return _blobs |
| 188 | |
| 189 | if self.ndevices > 1 and add_prefix: |
| 190 | # add layer on multiple devices |
| 191 | ll = [] |
| 192 | for d in range(self.ndevices): |
| 193 | # add prefix on_device |
| 194 | on_device = "gpu_" + str(d) + "/" |
| 195 | _inp_blobs = adjust_tag(inp_blobs, on_device) |
| 196 | _out_blobs = adjust_tag(out_blobs, on_device) |
| 197 | # WARNING: reset_grad option was exlusively designed for WeightedSum |
| 198 | # with inp_blobs=[w, tag_one, "", lr], where "" will be replaced |
| 199 | if reset_grad: |
| 200 | w_grad = self.gradientMap[_inp_blobs[0]] |
| 201 | _inp_blobs[2] = w_grad |
| 202 | # add layer to the model |
| 203 | with core.DeviceScope(core.DeviceOption(workspace.GpuDeviceType, d)): |
| 204 | if kwargs: |
| 205 | new_layer = layer(_inp_blobs, _out_blobs, **kwargs) |
| 206 | else: |
| 207 | new_layer = layer(_inp_blobs, _out_blobs) |
| 208 | ll.append(new_layer) |
| 209 | return ll |
| 210 | else: |
| 211 | # add layer on a single device |
| 212 | # WARNING: reset_grad option was exlusively designed for WeightedSum |
| 213 | # with inp_blobs=[w, tag_one, "", lr], where "" will be replaced |
| 214 | if reset_grad: |
| 215 | w_grad = self.gradientMap[inp_blobs[0]] |
| 216 | inp_blobs[2] = w_grad |
| 217 | # add layer to the model |
| 218 | if kwargs: |
| 219 | new_layer = layer(inp_blobs, out_blobs, **kwargs) |
| 220 | else: |
| 221 | new_layer = layer(inp_blobs, out_blobs) |
| 222 | return new_layer |
| 223 | |
| 224 | def create_mlp(self, ln, sigmoid_layer, model, tag): |
| 225 | (tag_layer, tag_in, tag_out) = tag |
no outgoing calls
no test coverage detected