MCPcopy Create free account
hub / github.com/pytorch/pytorch / NetProcessor

Class NetProcessor

caffe2/python/pipeline.py:397–451  ·  view source on GitHub ↗

Processor that clones a core.Net each time it's called, executing the cloned net as the processor. It requires the Net to have input and (optionally) output records set, with net.set_input_record() and net.set_output_record().

Source from the content-addressed store, hash-verified

395
396
397class NetProcessor:
398 """
399 Processor that clones a core.Net each time it's called, executing
400 the cloned net as the processor. It requires the Net to have input
401 and (optionally) output records set, with net.set_input_record() and
402 net.set_output_record().
403 """
404 def __init__(self, net, stop_signal=None, thread_init_nets=None, name=None):
405 assert isinstance(net, core.Net)
406 assert stop_signal is None or isinstance(
407 stop_signal, core.BlobReference)
408 self.name = name or str(net)
409 self.thread_init_nets = thread_init_nets or []
410 self.net = net
411 self._stop_signal = stop_signal
412 self._blob_maps = []
413 self._frozen = False
414 self._cloned_init_nets = []
415
416 def schema(self):
417 return self.net.output_record()
418
419 def setup(self, init_net):
420 self._frozen = True
421 cloned_init_nets = self._cloned_init_nets
422 self._cloned_init_nets = []
423 return cloned_init_nets
424
425 def __call__(self, rec):
426 assert not self._frozen
427 prefix = NetBuilder.current().name + '/'
428 blob_remap = {}
429 for net in self.thread_init_nets:
430 new_net, _ = core.clone_and_bind_net(
431 net, str(net) + prefix, prefix, blob_remap)
432 self._cloned_init_nets.append(new_net)
433
434 new_net, remappings = core.clone_and_bind_net(
435 self.net, str(self.net) + prefix, prefix, blob_remap, rec)
436
437 if self._stop_signal is None:
438 stop_signal = None
439 elif str(self._stop_signal) in remappings:
440 stop_signal = core.BlobReference(
441 remappings[str(self._stop_signal)],
442 net=new_net)
443 else:
444 stop_signal = self._stop_signal
445
446 self._blob_maps.append(remappings)
447 return Output([new_net], new_net.output_record(), stop_signal)
448
449 def blob_maps(self):
450 self._frozen = True
451 return self._blob_maps

Callers 1

make_processorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…