def save_model(file, model, opt, with_opt=True):
    'Save `model` to `file` along with `opt` (if available, and if `with_opt`)'
    if (opt is None):
        with_opt = False
    state = get_model(model).state_dict()
    if with_opt:
        state = {'model': state, 'opt': opt.state_dict()}
    torch.save(state, file)
Save `model` to `file` along with `opt` (if available, and if `with_opt`)
def save_model(file, model, opt, with_opt=True):
    
    if (opt is None):
        with_opt = False
    state = get_model(model).state_dict()
    if with_opt:
        state = {'model': state, 'opt': opt.state_dict()}
    torch.save(state, file)