SaveModelcall back error

Can some help with this error.
i simple do
learn.load('best_model_…) from previous training cycle.but want to save forthing coming models with different names

/opt/conda/lib/python3.7/site-packages/fastai/learner.py:54: UserWarning: Saved filed doesn't contain an optimizer state.
  elif with_opt: warn("Saved filed doesn't contain an optimizer state.")
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    153     def _with_events(self, f, event_type, ex, final=noop):
--> 154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in __call__(self, event_name)
    131 
--> 132     def __call__(self, event_name): L(event_name).map(self._call_one)
    133 
/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in map(self, f, gen, *args, **kwargs)
    178 
--> 179     def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
    180     def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
/opt/conda/lib/python3.7/site-packages/fastcore/basics.py in map_ex(iterable, f, gen, *args, **kwargs)
    606     if gen: return res
--> 607     return list(res)
    608 
/opt/conda/lib/python3.7/site-packages/fastcore/basics.py in __call__(self, *args, **kwargs)
    596         fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 597         return self.func(*fargs, **kwargs)
    598 
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _call_one(self, event_name)
    135         assert hasattr(event, event_name), event_name
--> 136         [cb(event_name) for cb in sort_by_run(self.cbs)]
    137 
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in <listcomp>(.0)
    135         assert hasattr(event, event_name), event_name
--> 136         [cb(event_name) for cb in sort_by_run(self.cbs)]
    137 
/opt/conda/lib/python3.7/site-packages/fastai/callback/core.py in __call__(self, event_name)
     43         res = None
---> 44         if self.run and _run: res = getattr(self, event_name, noop)()
     45         if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit
/opt/conda/lib/python3.7/site-packages/fastai/callback/fp16.py in before_fit(self)
     84     def before_fit(self):
---> 85         assert self.dls.device.type == 'cuda', "Mixed-precision training requires a GPU, remove the call `to_fp16`"
     86         if self.learn.opt is None: self.learn.create_opt()
AssertionError: Mixed-precision training requires a GPU, remove the call `to_fp16`
During handling of the above exception, another exception occurred:
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-60-ff4d58f0ddc0> in <module>
      8                                  #MixUp1(),
      9                                  ReduceLROnPlateau(monitor='accuracy_multi',factor=5,patience=2)
---> 10                                 ,SaveModelCallback(monitor='accuracy_multi',fname=f'best_model_dense_ext_{fold}')  ] )
/opt/conda/lib/python3.7/site-packages/fastai/callback/schedule.py in fit_sgdr(self, n_cycles, cycle_len, lr_max, cycle_mult, cbs, reset_opt, wd)
    146     scheds = [SchedCos(lr_max, 0) for _ in range(n_cycles)]
    147     scheds = {'lr': combine_scheds(pcts, scheds)}
--> 148     self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
    149 
    150 # Cell
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
    203             self.opt.set_hypers(lr=self.lr if lr is None else lr)
    204             self.n_epoch = n_epoch
--> 205             self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)
    206 
    207     def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')
--> 156         finally:   self(f'after_{event_type}')        ;final()
    157 
    158     def all_batches(self):
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in __call__(self, event_name)
    130     def ordered_cbs(self, event): return [cb for cb in sort_by_run(self.cbs) if hasattr(cb, event)]
    131 
--> 132     def __call__(self, event_name): L(event_name).map(self._call_one)
    133 
    134     def _call_one(self, event_name):
/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in map(self, f, gen, *args, **kwargs)
    177     def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
    178 
--> 179     def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
    180     def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
    181     def filter(self, f=noop, negate=False, gen=False, **kwargs):
/opt/conda/lib/python3.7/site-packages/fastcore/basics.py in map_ex(iterable, f, gen, *args, **kwargs)
    605     res = map(g, iterable)
    606     if gen: return res
--> 607     return list(res)
    608 
    609 # Cell
/opt/conda/lib/python3.7/site-packages/fastcore/basics.py in __call__(self, *args, **kwargs)
    595             if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
    596         fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 597         return self.func(*fargs, **kwargs)
    598 
    599 # Cell
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _call_one(self, event_name)
    134     def _call_one(self, event_name):
    135         assert hasattr(event, event_name), event_name
--> 136         [cb(event_name) for cb in sort_by_run(self.cbs)]
    137 
    138     def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in <listcomp>(.0)
    134     def _call_one(self, event_name):
    135         assert hasattr(event, event_name), event_name
--> 136         [cb(event_name) for cb in sort_by_run(self.cbs)]
    137 
    138     def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)
/opt/conda/lib/python3.7/site-packages/fastai/callback/core.py in __call__(self, event_name)
     42                (self.run_valid and not getattr(self, 'training', False)))
     43         res = None
---> 44         if self.run and _run: res = getattr(self, event_name, noop)()
     45         if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit
     46         return res
/opt/conda/lib/python3.7/site-packages/fastai/callback/tracker.py in after_fit(self, **kwargs)
     85     def after_fit(self, **kwargs):
     86         "Load the best model."
---> 87         if not self.every_epoch: self.learn.load(f'{self.fname}', with_opt=self.with_opt)
     88 
     89 # Cell
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in load(self, file, with_opt, device, **kwargs)
    291         if self.opt is None: self.create_opt()
    292         file = join_path_file(file, self.path/self.model_dir, ext='.pth')
--> 293         load_model(file, self.model, self.opt, with_opt=with_opt, device=device, **kwargs)
    294         return self
    295 
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in load_model(file, model, opt, with_opt, device, strict)
     44     if isinstance(device, int): device = torch.device('cuda', device)
     45     elif device is None: device = 'cpu'
---> 46     state = torch.load(file, map_location=device)
     47     hasopt = set(state)=={'model', 'opt'}
     48     model_state = state['model'] if hasopt else state
/opt/conda/lib/python3.7/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    579         pickle_load_args['encoding'] = 'utf-8'
    580 
--> 581     with _open_file_like(f, 'rb') as opened_file:
    582         if _is_zipfile(opened_file):
    583             # The zipfile reader is going to advance the current file position.
/opt/conda/lib/python3.7/site-packages/torch/serialization.py in _open_file_like(name_or_buffer, mode)
    228 def _open_file_like(name_or_buffer, mode):
    229     if _is_path(name_or_buffer):
--> 230         return _open_file(name_or_buffer, mode)
    231     else:
    232         if 'w' in mode:
/opt/conda/lib/python3.7/site-packages/torch/serialization.py in __init__(self, name, mode)
    209 class _open_file(_opener):
    210     def __init__(self, name, mode):
--> 211         super(_open_file, self).__init__(open(name, mode))
    212 
    213     def __exit__(self, *args):
FileNotFoundError: [Errno 2] No such file or directory: 'models/best_model_dense_ext_3.pth'

SaveModelCallback (monitor ='valid_loss' , comp =None , min_delta =0.0 , fname ='model' , every_epoch =False , with_opt =False , reset_on_fit =True )

I believe you can name your weights file with fname argument.

I use it this way only… but still get an error which is mysterious some time i get some time i m not.

ModuleAttributeError                      Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    153     def _with_events(self, f, event_type, ex, final=noop):
--> 154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_epoch(self)
    189     def _do_epoch(self):
--> 190         self._do_epoch_train()
    191         self._do_epoch_validate()

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_epoch_train(self)
    181         self.dl = self.dls.train
--> 182         self._with_events(self.all_batches, 'train', CancelTrainException)
    183 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    153     def _with_events(self, f, event_type, ex, final=noop):
--> 154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in all_batches(self)
    159         self.n_iter = len(self.dl)
--> 160         for o in enumerate(self.dl): self.one_batch(*o)
    161 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in one_batch(self, i, b)
    177         self._split(b)
--> 178         self._with_events(self._do_one_batch, 'batch', CancelBatchException)
    179 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    153     def _with_events(self, f, event_type, ex, final=noop):
--> 154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_one_batch(self)
    162     def _do_one_batch(self):
--> 163         self.pred = self.model(*self.xb)
    164         self('after_pred')

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(

<ipython-input-49-b3fc2b107514> in forward(self, x)
     76     def forward(self, x):
---> 77         x = self.forward_features(x)
     78 

<ipython-input-49-b3fc2b107514> in forward_features(self, x)
     40             self.dropblock.step()
---> 41         x = self.model.layer0(x)
     42         #pdb.set_trace()

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in __getattr__(self, name)
    778         raise ModuleAttributeError("'{}' object has no attribute '{}'".format(
--> 779             type(self).__name__, name))
    780 

ModuleAttributeError: 'ResNet' object has no attribute 'layer0'

During handling of the above exception, another exception occurred:

IndexError                                Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    153     def _with_events(self, f, event_type, ex, final=noop):
--> 154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _do_fit(self)
    195             self.epoch=epoch
--> 196             self._with_events(self._do_epoch, 'epoch', CancelEpochException)
    197 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    155         except ex: self(f'after_cancel_{event_type}')
--> 156         finally:   self(f'after_{event_type}')        ;final()
    157 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in __call__(self, event_name)
    131 
--> 132     def __call__(self, event_name): L(event_name).map(self._call_one)
    133 

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in map(self, f, gen, *args, **kwargs)
    178 
--> 179     def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
    180     def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))

/opt/conda/lib/python3.7/site-packages/fastcore/basics.py in map_ex(iterable, f, gen, *args, **kwargs)
    606     if gen: return res
--> 607     return list(res)
    608 

/opt/conda/lib/python3.7/site-packages/fastcore/basics.py in __call__(self, *args, **kwargs)
    596         fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 597         return self.func(*fargs, **kwargs)
    598 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _call_one(self, event_name)
    135         assert hasattr(event, event_name), event_name
--> 136         [cb(event_name) for cb in sort_by_run(self.cbs)]
    137 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in <listcomp>(.0)
    135         assert hasattr(event, event_name), event_name
--> 136         [cb(event_name) for cb in sort_by_run(self.cbs)]
    137 

/opt/conda/lib/python3.7/site-packages/fastai/callback/core.py in __call__(self, event_name)
     43         res = None
---> 44         if self.run and _run: res = getattr(self, event_name, noop)()
     45         if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit

/opt/conda/lib/python3.7/site-packages/fastai/callback/tracker.py in after_epoch(self)
     54         "Compare the value monitored to its best score and maybe stop training."
---> 55         super().after_epoch()
     56         if self.new_best: self.wait = 0

/opt/conda/lib/python3.7/site-packages/fastai/callback/tracker.py in after_epoch(self)
     38         "Compare the last value to the best up to now"
---> 39         val = self.recorder.values[-1][self.idx]
     40         if self.comp(val - self.min_delta, self.best): self.best,self.new_best = val,True

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in __getitem__(self, idx)
    135     def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
--> 136     def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)
    137     def copy(self): return self._new(self.items.copy())

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in _get(self, i)
    139     def _get(self, i):
--> 140         if is_indexer(i) or isinstance(i,slice): return getattr(self.items,'iloc',self.items)[i]
    141         i = mask2idxs(i)

IndexError: list index out of range

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-65-c808bf10bc3a> in <module>
      9                                  EarlyStoppingCallback(patience=4,monitor='roc_auc_score'),
     10                                  ReduceLROnPlateau(monitor='roc_auc_score',factor=5,patience=2)
---> 11                                 ,SaveModelCallback(monitor='roc_auc_score',fname=f'best_model_eca_ext_{fold}')  ] )
     12 

/opt/conda/lib/python3.7/site-packages/fastai/callback/schedule.py in fit_sgdr(self, n_cycles, cycle_len, lr_max, cycle_mult, cbs, reset_opt, wd)
    146     scheds = [SchedCos(lr_max, 0) for _ in range(n_cycles)]
    147     scheds = {'lr': combine_scheds(pcts, scheds)}
--> 148     self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
    149 
    150 # Cell

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
    203             self.opt.set_hypers(lr=self.lr if lr is None else lr)
    204             self.n_epoch = n_epoch
--> 205             self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)
    206 
    207     def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
    154         try:       self(f'before_{event_type}')       ;f()
    155         except ex: self(f'after_cancel_{event_type}')
--> 156         finally:   self(f'after_{event_type}')        ;final()
    157 
    158     def all_batches(self):

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in __call__(self, event_name)
    130     def ordered_cbs(self, event): return [cb for cb in sort_by_run(self.cbs) if hasattr(cb, event)]
    131 
--> 132     def __call__(self, event_name): L(event_name).map(self._call_one)
    133 
    134     def _call_one(self, event_name):

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in map(self, f, gen, *args, **kwargs)
    177     def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
    178 
--> 179     def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
    180     def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
    181     def filter(self, f=noop, negate=False, gen=False, **kwargs):

/opt/conda/lib/python3.7/site-packages/fastcore/basics.py in map_ex(iterable, f, gen, *args, **kwargs)
    605     res = map(g, iterable)
    606     if gen: return res
--> 607     return list(res)
    608 
    609 # Cell

/opt/conda/lib/python3.7/site-packages/fastcore/basics.py in __call__(self, *args, **kwargs)
    595             if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
    596         fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 597         return self.func(*fargs, **kwargs)
    598 
    599 # Cell

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in _call_one(self, event_name)
    134     def _call_one(self, event_name):
    135         assert hasattr(event, event_name), event_name
--> 136         [cb(event_name) for cb in sort_by_run(self.cbs)]
    137 
    138     def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in <listcomp>(.0)
    134     def _call_one(self, event_name):
    135         assert hasattr(event, event_name), event_name
--> 136         [cb(event_name) for cb in sort_by_run(self.cbs)]
    137 
    138     def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)

/opt/conda/lib/python3.7/site-packages/fastai/callback/core.py in __call__(self, event_name)
     42                (self.run_valid and not getattr(self, 'training', False)))
     43         res = None
---> 44         if self.run and _run: res = getattr(self, event_name, noop)()
     45         if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit
     46         return res

/opt/conda/lib/python3.7/site-packages/fastai/callback/tracker.py in after_fit(self, **kwargs)
     85     def after_fit(self, **kwargs):
     86         "Load the best model."
---> 87         if not self.every_epoch: self.learn.load(f'{self.fname}', with_opt=self.with_opt)
     88 
     89 # Cell

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in load(self, file, with_opt, device, **kwargs)
    291         if self.opt is None: self.create_opt()
    292         file = join_path_file(file, self.path/self.model_dir, ext='.pth')
--> 293         load_model(file, self.model, self.opt, with_opt=with_opt, device=device, **kwargs)
    294         return self
    295 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in load_model(file, model, opt, with_opt, device, strict)
     44     if isinstance(device, int): device = torch.device('cuda', device)
     45     elif device is None: device = 'cpu'
---> 46     state = torch.load(file, map_location=device)
     47     hasopt = set(state)=={'model', 'opt'}
     48     model_state = state['model'] if hasopt else state

/opt/conda/lib/python3.7/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    579         pickle_load_args['encoding'] = 'utf-8'
    580 
--> 581     with _open_file_like(f, 'rb') as opened_file:
    582         if _is_zipfile(opened_file):
    583             # The zipfile reader is going to advance the current file position.

/opt/conda/lib/python3.7/site-packages/torch/serialization.py in _open_file_like(name_or_buffer, mode)
    228 def _open_file_like(name_or_buffer, mode):
    229     if _is_path(name_or_buffer):
--> 230         return _open_file(name_or_buffer, mode)
    231     else:
    232         if 'w' in mode:

/opt/conda/lib/python3.7/site-packages/torch/serialization.py in __init__(self, name, mode)
    209 class _open_file(_opener):
    210     def __init__(self, name, mode):
--> 211         super(_open_file, self).__init__(open(name, mode))
    212 
    213     def __exit__(self, *args):

FileNotFoundError: [Errno 2] No such file or directory: 'models/best_model_eca_ext_4.pth'

The error may not be related to SaveModelCallback, it’s got to do with the above one I think.
If possible post the whole code or better a link to the notebook!