aws_lambda/pytorch/source/torch/jit/__init__.py
def load(f, map_location=None):
    r"""
        Load a ``ScriptModule`` previously saved with :func:`save <torch.jit.save>`

        All previously saved modules, no matter their device, are first loaded onto CPU,
        and then are moved to the devices they were saved from. If this fails (e.g. because
        the run time system doesn't have certain devices), an exception is raised.
        However, storages can be dynamically remapped to an alternative set of devices
        using the `map_location` argument. Comparing to :func:`torch.load`, `map_location`
        in this function is simplified, which only accepts a string (e.g., 'cpu', 'cuda:0'),
        or torch.device (e.g., torch.device('cpu'))

        Arguments:
            f: a file-like object (has to implement read, readline, tell, and seek),
                or a string containing a file name
            map_location: can a string (e.g., 'cpu', 'cuda:0'), a device (e.g.,
                torch.device('cpu'))

        Returns:
            A ``ScriptModule`` object.

        Example:
            >>> torch.jit.load('scriptmodule.pt')
            # Load ScriptModule from io.BytesIO object
            >>> with open('scriptmodule.pt', 'rb') as f:
                    buffer = io.BytesIO(f.read())
            # Load all tensors to the original device
            >>> torch.jit.load(buffer)
            # Load all tensors onto CPU, using a device
            >>> torch.jit.load(buffer, map_location=torch.device('cpu'))
            # Load all tensors onto CPU, using a string
            >>> torch.jit.load(buffer, map_location='cpu')
    """
    m = ScriptModule()

    def module_lookup(names):
        curr = m
        for name in names:
            if not hasattr(curr, name):
                setattr(curr, name, ScriptModule())
            curr = getattr(curr, name)
        return curr

    if isinstance(map_location, string_classes):
        map_location = torch.device(map_location)
    elif not (map_location is None or
              isinstance(map_location, torch.device)):
        raise ValueError("map_location should be either None, string or torch.device, "
                         "but got type: " + str(type(map_location)))
    if (str(map_location).startswith('cuda')):
        validate_cuda_device(map_location)

    if isinstance(f, str) or \
            (sys.version_info[0] == 2 and isinstance(f, unicode)) or \
            (sys.version_info[0] == 3 and isinstance(f, pathlib.Path)):
        torch._C.import_ir_module(module_lookup, f, map_location)
    else:
        torch._C.import_ir_module_from_buffer(module_lookup, f.read(), map_location)
    return m
r"""
        Load a ``ScriptModule`` previously saved with :func:`save <torch.jit.save>`

        All previously saved modules, no matter their device, are first loaded onto CPU,
        and then are moved to the devices they were saved from. If this fails (e.g. because
        the run time system doesn't have certain devices), an exception is raised.
        However, storages can be dynamically remapped to an alternative set of devices
        using the `map_location` argument. Comparing to :func:`torch.load`, `map_location`
        in this function is simplified, which only accepts a string (e.g., 'cpu', 'cuda:0'),
        or torch.device (e.g., torch.device('cpu'))

        Arguments:
            f: a file-like object (has to implement read, readline, tell, and seek),
                or a string containing a file name
            map_location: can a string (e.g., 'cpu', 'cuda:0'), a device (e.g.,
                torch.device('cpu'))

        Returns:
            A ``ScriptModule`` object.

        Example:
            >>> torch.jit.load('scriptmodule.pt')
            # Load ScriptModule from io.BytesIO object
            >>> with open('scriptmodule.pt', 'rb') as f:
                    buffer = io.BytesIO(f.read())
            # Load all tensors to the original device
            >>> torch.jit.load(buffer)
            # Load all tensors onto CPU, using a device
            >>> torch.jit.load(buffer, map_location=torch.device('cpu'))
            # Load all tensors onto CPU, using a string
            >>> torch.jit.load(buffer, map_location='cpu')
    


All previously saved modules, no matter their device, are first loaded onto CPU,
and then are moved to the devices they were saved from. If this fails , an exception is raised.
However, storages can be dynamically remapped to an alternative set of devices
using the `map_location` argument. Comparing to :func:`torch.load`, `map_location`
in this function is simplified, which only accepts a string ,
or torch.device )
All previously saved modules no matter their device are first loaded onto CPU and then are moved to the devices they were saved from . If this fails an exception is raised . However storages can be dynamically remapped to an alternative set of devices using the ` map_location ` argument . Comparing to : func : ` torch . load ` ` map_location ` in this function is simplified which only accepts a string or torch . device )
def load(f, map_location=None):
    m = ScriptModule()
    def module_lookup(names):
        curr = m
        for name in names:
            if not hasattr(curr, name):
                setattr(curr, name, ScriptModule())
            curr = getattr(curr, name)
        return curr
    if isinstance(map_location, string_classes):
        map_location = torch.device(map_location)
    elif not (map_location is None or
              isinstance(map_location, torch.device)):
        raise ValueError("map_location should be either None, string or torch.device, "
                         "but got type: " + str(type(map_location)))
    if (str(map_location).startswith('cuda')):
        validate_cuda_device(map_location)
    if isinstance(f, str) or \
            (sys.version_info[0] == 2 and isinstance(f, unicode)) or \
            (sys.version_info[0] == 3 and isinstance(f, pathlib.Path)):
        torch._C.import_ir_module(module_lookup, f, map_location)
    else:
        torch._C.import_ir_module_from_buffer(module_lookup, f.read(), map_location)
    return m
def load ( f , map_location = None ) : m = ScriptModule ( ) def module_lookup ( names ) : curr = m for name in names : if not hasattr ( curr , name ) : setattr ( curr , name , ScriptModule ( ) ) curr = getattr ( curr , name ) return curr if isinstance ( map_location , string_classes ) : map_location = torch . device ( map_location ) elif not ( map_location is None or isinstance ( map_location , torch . device ) ) : raise ValueError ( "map_location should be either None, string or torch.device, " "but got type: " + str ( type ( map_location ) ) ) if ( str ( map_location ) . startswith ( 'cuda' ) ) : validate_cuda_device ( map_location ) if isinstance ( f , str ) or ( sys . version_info [ 0 ] == 2 and isinstance ( f , unicode ) ) or ( sys . version_info [ 0 ] == 3 and isinstance ( f , pathlib . Path ) ) : torch . _C . import_ir_module ( module_lookup , f , map_location ) else : torch . _C . import_ir_module_from_buffer ( module_lookup , f . read ( ) , map_location ) return m
r"""
Load a ``ScriptModule`` previously saved with :func:`save <torch.jit.save>`
r " " " Load a ` ` ScriptModule ` ` previously saved with : func : ` save <torch . jit . save > `
r"""
        Load a ``ScriptModule`` previously saved with :func:`save <torch.jit.save>`

        All previously saved modules, no matter their device, are first loaded onto CPU,
        and then are moved to the devices they were saved from. If this fails (e.g. because
        the run time system doesn't have certain devices), an exception is raised.
        However, storages can be dynamically remapped to an alternative set of devices
        using the `map_location` argument. Comparing to :func:`torch.load`, `map_location`
        in this function is simplified, which only accepts a string (e.g., 'cpu', 'cuda:0'),
        or torch.device (e.g., torch.device('cpu'))

        Arguments:
            f: a file-like object (has to implement read, readline, tell, and seek),
                or a string containing a file name
            map_location: can a string (e.g., 'cpu', 'cuda:0'), a device (e.g.,
                torch.device('cpu'))

        Returns:
            A ``ScriptModule`` object.

        Example:
            >>> torch.jit.load('scriptmodule.pt')
            # Load ScriptModule from io.BytesIO object
            >>> with open('scriptmodule.pt', 'rb') as f:
                    buffer = io.BytesIO(f.read())
            # Load all tensors to the original device
            >>> torch.jit.load(buffer)
            # Load all tensors onto CPU, using a device
            >>> torch.jit.load(buffer, map_location=torch.device('cpu'))
            # Load all tensors onto CPU, using a string
            >>> torch.jit.load(buffer, map_location='cpu')
    """
A ``ScriptModule`` object.
A ` ` ScriptModule ` ` object .
f
a file-like object (has to implement read, readline, tell, and seek),
or a string containing a file name
a file - like object ( has to implement read readline tell and seek ) or a string containing a file name
map_location
can a string , a device )
can a string a device )
examples
>>> torch.jit.load('scriptmodule.pt')
Load ScriptModule from io.BytesIO object
>>> with open('scriptmodule.pt', 'rb') as f:
buffer = io.BytesIO(f.read())
Load all tensors to the original device
>>> torch.jit.load(buffer)
Load all tensors onto CPU, using a device
>>> torch.jit.load(buffer, map_location=torch.device('cpu'))
Load all tensors onto CPU, using a string
>>> torch.jit.load(buffer, map_location='cpu')
>>> torch . jit . load ( ' scriptmodule . pt ' ) Load ScriptModule from io . BytesIO object >>> with open ( ' scriptmodule . pt ' ' rb ' ) as f : buffer = io . BytesIO ( f . read () ) Load all tensors to the original device >>> torch . jit . load ( buffer ) Load all tensors onto CPU using a device >>> torch . jit . load ( buffer map_location = torch . device ( ' cpu ' )) Load all tensors onto CPU using a string >>> torch . jit . load ( buffer map_location = ' cpu ' )