def load_state_dict(module, state_dict, strict=False, logger=None):
unexpected_keys = []<EOL>own_state = module.state_dict()<EOL>for name, param in state_dict.items():<EOL><INDENT>if name not in own_state:<EOL><INDENT>unexpected_keys.append(name)<EOL>continue<EOL><DEDENT>if isinstance(param, torch.nn.Parameter):<EOL><INDENT>param = param.data<EOL><DEDENT>try:<EOL><INDENT>own_state[name].copy_(param)<EOL><DEDENT>except Exception:<EOL><INDENT>raise RuntimeError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>.format(name, own_state[name].size(),<EOL>param.size()))<EOL><DEDENT><DEDENT>missing_keys = set(own_state.keys()) - set(state_dict.keys())<EOL>err_msg = []<EOL>if unexpected_keys:<EOL><INDENT>err_msg.append('<STR_LIT>'.format(<EOL>'<STR_LIT:U+002CU+0020>'.join(unexpected_keys)))<EOL><DEDENT>if missing_keys:<EOL><INDENT>err_msg.append('<STR_LIT>'.format(<EOL>'<STR_LIT:U+002CU+0020>'.join(missing_keys)))<EOL><DEDENT>err_msg = '<STR_LIT:\n>'.join(err_msg)<EOL>if err_msg:<EOL><INDENT>if strict:<EOL><INDENT>raise RuntimeError(err_msg)<EOL><DEDENT>elif logger is not None:<EOL><INDENT>logger.warn(err_msg)<EOL><DEDENT>else:<EOL><INDENT>print(err_msg)<EOL><DEDENT><DEDENT>
Load state_dict to a module.

    This method is modified from :meth:`torch.nn.Module.load_state_dict`.
    Default value for ``strict`` is set to ``False`` and the message for
    param mismatch will be shown even if strict is False.

    Args:
        module (Module): Module that receives the state_dict.
        state_dict (OrderedDict): Weights.
        strict (bool): whether to strictly enforce that the keys
            in :attr:`state_dict` match the keys returned by this module's
            :meth:`~torch.nn.Module.state_dict` function. Default: ``False``.
        logger (:obj:`logging.Logger`, optional): Logger to log the error
            message. If not specified, print function will be used.