MCPcopy Index your code
hub / github.com/pytorch/pytorch / CreateOperator

Function CreateOperator

caffe2/python/core.py:362–422  ·  view source on GitHub ↗

A function wrapper that allows one to create operators based on the operator type. The type should be a string corresponding to an operator registered with Caffe2.

(
    operator_type,
    inputs,
    outputs,
    name='',
    control_input=None,
    device_option=None,
    arg=None,
    engine=None,
    debug_info=None,
    **kwargs
)

Source from the content-addressed store, hash-verified

360
361
362def CreateOperator(
363 operator_type,
364 inputs,
365 outputs,
366 name='',
367 control_input=None,
368 device_option=None,
369 arg=None,
370 engine=None,
371 debug_info=None,
372 **kwargs
373):
374 """A function wrapper that allows one to create operators based on the
375 operator type. The type should be a string corresponding to an operator
376 registered with Caffe2.
377 """
378 operator = caffe2_pb2.OperatorDef()
379 if (os.environ.get('CAFFE2_DEBUG')):
380 stack = traceback.format_stack()
381 operator.debug_info = "".join(stack[:-1])
382
383 operator.type = operator_type
384 operator.name = name
385 # Add rectified inputs and outputs
386 inputs = _RectifyInputOutput(inputs)
387 outputs = _RectifyInputOutput(outputs)
388 operator.input.extend(map(str, inputs))
389 operator.output.extend(map(str, outputs))
390 if control_input:
391 control_input = _RectifyInputOutput(control_input)
392 operator.control_input.extend(map(str, control_input))
393 # Set device option:
394 # (1) If device_option is explicitly set, use device_option.
395 # (2) If not, but scope.CurrentDeviceScope() is set,
396 # then we use scope.CurrentDeviceScope().
397 # (3) Otherwise, do not set device option.
398 if device_option is not None:
399 operator.device_option.CopyFrom(device_option)
400 elif scope.CurrentDeviceScope() is not None:
401 operator.device_option.CopyFrom(scope.CurrentDeviceScope())
402 if engine is not None:
403 operator.engine = engine
404 if debug_info is not None:
405 operator.debug_info = debug_info
406 # random seed is defined in the device option, so we need to do special
407 # care.
408
409 if 'random_seed' in kwargs:
410 operator.device_option.random_seed = kwargs['random_seed']
411 del kwargs['random_seed']
412 # Add given arguments that do not need parsing
413 if arg is not None:
414 operator.arg.extend(arg)
415 # Add all other arguments
416 for key, value in kwargs.items():
417 if value is not None:
418 operator.arg.add().CopyFrom(utils.MakeArgument(key, value))
419

Callers 15

AddDirectGradientFunction · 0.90
AddUseOutputGradientFunction · 0.90
AddUseInputGradientFunction · 0.90
testDirectMethod · 0.90
testDirectInPlaceMethod · 0.90
testVersionMismatchMethod · 0.90
testUseOutputMethod · 0.90
testUseOutputInPlaceMethod · 0.90

Calls 6

_RectifyInputOutputFunction · 0.85
getMethod · 0.45
joinMethod · 0.45
extendMethod · 0.45
itemsMethod · 0.45
addMethod · 0.45

Tested by 15

AddDirectGradientFunction · 0.72
AddUseOutputGradientFunction · 0.72
AddUseInputGradientFunction · 0.72
testDirectMethod · 0.72
testDirectInPlaceMethod · 0.72
testVersionMismatchMethod · 0.72
testUseOutputMethod · 0.72
testUseOutputInPlaceMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…