def load_model(file, model, opt, with_opt=None, device=None, strict=True):
    'Load `model` from `file` along with `opt` (if available, and if `with_opt`)'
    if isinstance(device, int):
        device = torch.device('cuda', device)
    elif (device is None):
        device = 'cpu'
    state = torch.load(file, map_location=device)
    hasopt = (set(state) == {'model', 'opt'})
    model_state = (state['model'] if hasopt else state)
    get_model(model).load_state_dict(model_state, strict=strict)
    if (hasopt and ifnone(with_opt, True)):
        try:
            opt.load_state_dict(state['opt'])
        except:
            if with_opt:
                warn('Could not load the optimizer state.')
    elif with_opt:
        warn("Saved filed doesn't contain an optimizer state.")
Load `model` from `file` along with `opt` (if available, and if `with_opt`)
def load_model(file, model, opt, with_opt=None, device=None, strict=True):
    
    if isinstance(device, int):
        device = torch.device('cuda', device)
    elif (device is None):
        device = 'cpu'
    state = torch.load(file, map_location=device)
    hasopt = (set(state) == {'model', 'opt'})
    model_state = (state['model'] if hasopt else state)
    get_model(model).load_state_dict(model_state, strict=strict)
    if (hasopt and ifnone(with_opt, True)):
        try:
            opt.load_state_dict(state['opt'])
        except:
            if with_opt:
                warn('Could not load the optimizer state.')
    elif with_opt:
        warn("Saved filed doesn't contain an optimizer state.")