aws_lambda/pytorch/source/torch/jit/__init__.py
def trace(func,
          example_inputs,
          optimize=True,
          check_trace=True,
          check_inputs=None,
          check_tolerance=1e-5,
          _force_outplace=False):
    """
    Trace a function and return an executable trace that will be optimized
    using just-in-time compilation.

    .. warning::

        Tracing only correctly records functions and modules which are not data
        dependent (e.g., have conditionals on data in tensors) and do not have
        any untracked external dependencies (e.g., perform input/output or
        access global variables). If you trace such models, you may silently get
        incorrect results on subsequent invocations of the model. The tracer
        will try to emit warnings when doing something that may cause an
        incorrect trace to be produced.

    Arguments:
        func (callable or torch.nn.Module):  a python function or torch.nn.Module
                                             that will be run with example_inputs.
                                             arguments and returns to func must be Tensors
                                             or (possibly nested) tuples that
                                             contain tensors.
        example_inputs (tuple):  a tuple of example inputs that will be passed to the function
                                 while tracing. The resulting trace can be run with
                                 inputs of different types and shapes assuming the traced operations
                                 support those types and shapes. example_inputs may also be a single
                                 Tensor in which case it is automatically wrapped in a tuple

    Keyword arguments:
        optimize (bool, optional): whether or not to apply optimizations.  Default: ``True``.
        check_trace (bool, optional): check if the same inputs run through
                                      traced code produce the same outputs. Default: ``True``. You might want
                                      to disable this if, for example, your network contains non-
                                      deterministic ops or if you are sure that the network is correct despite
                                      a checker failure.

        check_inputs (list of tuples, optional): A list of tuples of input arguments that should be used
                                                 to check the trace against what is expected. Each tuple
                                                 is equivalent to a seet of input arguments that would
                                                 be specified in ``args``. For best results, pass in a
                                                 set of checking inputs representative of the space of
                                                 shapes and types of inputs you expect the network to see.
                                                 If not specified, the original ``args`` is used for checking
        check_tolerance (float, optional): Floating-point comparison tolerance to use in the checker procedure.
                                           This can be used to relax the checker strictness in the event that
                                           results diverge numerically for a known reason, such as operator fusion.

    Returns:
        A ``ScriptModule`` object with a single ``forward()`` method containing the traced code.
        When func is a ``torch.nn.Module``, the returned ``ScriptModule`` will have the same set of
        sub-modules and parameters as func.

    Example:
       >>> def f(x):
       ...     return x * 2
       >>> traced_f = torch.jit.trace(f, torch.rand(1))

    """
    if not _enabled:
        return func
    executor_options = {'optimize': bool(optimize)}
    # Special case for common case of passing a single Tensor
    if isinstance(example_inputs, torch.Tensor):
        example_inputs = (example_inputs,)
    # done primarily so that weird iterables fail here and not pybind11 code
    elif not isinstance(example_inputs, tuple):
        example_inputs = tuple(example_inputs)
    module = TopLevelTracedModule(func, **executor_options)
    var_lookup_fn = _create_interpreter_name_lookup_fn(0)
    module._create_method_from_trace('forward', func, example_inputs,
                                     var_lookup_fn, _force_outplace)

    # Check the trace against new traces created from user-specified inputs
    if check_trace:
        if check_inputs is not None:
            _check_trace(check_inputs, func, executor_options, module, check_tolerance, _force_outplace)
        else:
            _check_trace([example_inputs], func, executor_options, module, check_tolerance, _force_outplace)

    return module

    Trace a function and return an executable trace that will be optimized
    using just-in-time compilation.

    .. warning::

        Tracing only correctly records functions and modules which are not data
        dependent (e.g., have conditionals on data in tensors) and do not have
        any untracked external dependencies (e.g., perform input/output or
        access global variables). If you trace such models, you may silently get
        incorrect results on subsequent invocations of the model. The tracer
        will try to emit warnings when doing something that may cause an
        incorrect trace to be produced.

    Arguments:
        func (callable or torch.nn.Module):  a python function or torch.nn.Module
                                             that will be run with example_inputs.
                                             arguments and returns to func must be Tensors
                                             or (possibly nested) tuples that
                                             contain tensors.
        example_inputs (tuple):  a tuple of example inputs that will be passed to the function
                                 while tracing. The resulting trace can be run with
                                 inputs of different types and shapes assuming the traced operations
                                 support those types and shapes. example_inputs may also be a single
                                 Tensor in which case it is automatically wrapped in a tuple

    Keyword arguments:
        optimize (bool, optional): whether or not to apply optimizations.  Default: ``True``.
        check_trace (bool, optional): check if the same inputs run through
                                      traced code produce the same outputs. Default: ``True``. You might want
                                      to disable this if, for example, your network contains non-
                                      deterministic ops or if you are sure that the network is correct despite
                                      a checker failure.

        check_inputs (list of tuples, optional): A list of tuples of input arguments that should be used
                                                 to check the trace against what is expected. Each tuple
                                                 is equivalent to a seet of input arguments that would
                                                 be specified in ``args``. For best results, pass in a
                                                 set of checking inputs representative of the space of
                                                 shapes and types of inputs you expect the network to see.
                                                 If not specified, the original ``args`` is used for checking
        check_tolerance (float, optional): Floating-point comparison tolerance to use in the checker procedure.
                                           This can be used to relax the checker strictness in the event that
                                           results diverge numerically for a known reason, such as operator fusion.

    Returns:
        A ``ScriptModule`` object with a single ``forward()`` method containing the traced code.
        When func is a ``torch.nn.Module``, the returned ``ScriptModule`` will have the same set of
        sub-modules and parameters as func.

    Example:
       >>> def f(x):
       ...     return x * 2
       >>> traced_f = torch.jit.trace(f, torch.rand(1))

    
Trace a function and return an executable trace that will be optimized
using just-in-time compilation.



Tracing only correctly records functions and modules which are not data
dependent  and do not have
any untracked external dependencies . If you trace such models, you may silently get
incorrect results on subsequent invocations of the model. The tracer
will try to emit warnings when doing something that may cause an
incorrect trace to be produced.
Trace a function and return an executable trace that will be optimized using just - in - time compilation . Tracing only correctly records functions and modules which are not data dependent and do not have any untracked external dependencies . If you trace such models you may silently get incorrect results on subsequent invocations of the model . The tracer will try to emit warnings when doing something that may cause an incorrect trace to be produced .
def trace(func,
          example_inputs,
          optimize=True,
          check_trace=True,
          check_inputs=None,
          check_tolerance=1e-5,
          _force_outplace=False):
    if not _enabled:
        return func
    executor_options = {'optimize': bool(optimize)}
    if isinstance(example_inputs, torch.Tensor):
        example_inputs = (example_inputs,)
    elif not isinstance(example_inputs, tuple):
        example_inputs = tuple(example_inputs)
    module = TopLevelTracedModule(func, **executor_options)
    var_lookup_fn = _create_interpreter_name_lookup_fn(0)
    module._create_method_from_trace('forward', func, example_inputs,
                                     var_lookup_fn, _force_outplace)
    if check_trace:
        if check_inputs is not None:
            _check_trace(check_inputs, func, executor_options, module, check_tolerance, _force_outplace)
        else:
            _check_trace([example_inputs], func, executor_options, module, check_tolerance, _force_outplace)
    return module
def trace ( func , example_inputs , optimize = True , check_trace = True , check_inputs = None , check_tolerance = 1e-5 , _force_outplace = False ) : if not _enabled : return func executor_options = { 'optimize' : bool ( optimize ) } if isinstance ( example_inputs , torch . Tensor ) : example_inputs = ( example_inputs , ) elif not isinstance ( example_inputs , tuple ) : example_inputs = tuple ( example_inputs ) module = TopLevelTracedModule ( func , ** executor_options ) var_lookup_fn = _create_interpreter_name_lookup_fn ( 0 ) module . _create_method_from_trace ( 'forward' , func , example_inputs , var_lookup_fn , _force_outplace ) if check_trace : if check_inputs is not None : _check_trace ( check_inputs , func , executor_options , module , check_tolerance , _force_outplace ) else : _check_trace ( [ example_inputs ] , func , executor_options , module , check_tolerance , _force_outplace ) return module
Trace a function and return an executable trace that will be optimized
using just-in-time compilation.
Trace a function and return an executable trace that will be optimized using just - in - time compilation .
"""
    Trace a function and return an executable trace that will be optimized
    using just-in-time compilation.

    .. warning::

        Tracing only correctly records functions and modules which are not data
        dependent (e.g., have conditionals on data in tensors) and do not have
        any untracked external dependencies (e.g., perform input/output or
        access global variables). If you trace such models, you may silently get
        incorrect results on subsequent invocations of the model. The tracer
        will try to emit warnings when doing something that may cause an
        incorrect trace to be produced.

    Arguments:
        func (callable or torch.nn.Module):  a python function or torch.nn.Module
                                             that will be run with example_inputs.
                                             arguments and returns to func must be Tensors
                                             or (possibly nested) tuples that
                                             contain tensors.
        example_inputs (tuple):  a tuple of example inputs that will be passed to the function
                                 while tracing. The resulting trace can be run with
                                 inputs of different types and shapes assuming the traced operations
                                 support those types and shapes. example_inputs may also be a single
                                 Tensor in which case it is automatically wrapped in a tuple

    Keyword arguments:
        optimize (bool, optional): whether or not to apply optimizations.  Default: ``True``.
        check_trace (bool, optional): check if the same inputs run through
                                      traced code produce the same outputs. Default: ``True``. You might want
                                      to disable this if, for example, your network contains non-
                                      deterministic ops or if you are sure that the network is correct despite
                                      a checker failure.

        check_inputs (list of tuples, optional): A list of tuples of input arguments that should be used
                                                 to check the trace against what is expected. Each tuple
                                                 is equivalent to a seet of input arguments that would
                                                 be specified in ``args``. For best results, pass in a
                                                 set of checking inputs representative of the space of
                                                 shapes and types of inputs you expect the network to see.
                                                 If not specified, the original ``args`` is used for checking
        check_tolerance (float, optional): Floating-point comparison tolerance to use in the checker procedure.
                                           This can be used to relax the checker strictness in the event that
                                           results diverge numerically for a known reason, such as operator fusion.

    Returns:
        A ``ScriptModule`` object with a single ``forward()`` method containing the traced code.
        When func is a ``torch.nn.Module``, the returned ``ScriptModule`` will have the same set of
        sub-modules and parameters as func.

    Example:
       >>> def f(x):
       ...     return x * 2
       >>> traced_f = torch.jit.trace(f, torch.rand(1))

    """ # Special case for common case of passing a single Tensor # done primarily so that weird iterables fail here and not pybind11 code # Check the trace against new traces created from user-specified inputs
A ``ScriptModule`` object with a single ``forward()`` method containing the traced code.
When func is a ``torch.nn.Module``, the returned ``ScriptModule`` will have the same set of
sub-modules and parameters as func.
A ` ` ScriptModule ` ` object with a single ` ` forward () ` ` method containing the traced code . When func is a ` ` torch . nn . Module ` ` the returned ` ` ScriptModule ` ` will have the same set of sub - modules and parameters as func .
func
a python function or torch.nn.Module
that will be run with example_inputs.
arguments and returns to func must be Tensors
or (possibly nested) tuples that
contain tensors.
a python function or torch . nn . Module that will be run with example_inputs . arguments and returns to func must be Tensors or ( possibly nested ) tuples that contain tensors .
example_inputs
a tuple of example inputs that will be passed to the function
while tracing. The resulting trace can be run with
inputs of different types and shapes assuming the traced operations
support those types and shapes. example_inputs may also be a single
Tensor in which case it is automatically wrapped in a tuple
a tuple of example inputs that will be passed to the function while tracing . The resulting trace can be run with inputs of different types and shapes assuming the traced operations support those types and shapes . example_inputs may also be a single Tensor in which case it is automatically wrapped in a tuple
optimize
check_trace
check_inputs
check_tolerance
_force_outplace
examples
>>> def f(x):
return x * 2
>>> traced_f = torch.jit.trace(f, torch.rand(1))
>>> def f ( x ) : return x * 2 >>> traced_f = torch . jit . trace ( f torch . rand ( 1 ))