Skip to content

self.out not initialised properly #118

@lJoublanc

Description

@lJoublanc

I'm fitting a model from fastai using jupyter notebook, and it always throws the following exception:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[76], line 1
----> 1 _.fit_one_cycle(1, 0.1)

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastai/callback/schedule.py:121, in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt, start_epoch)
    118 lr_max = np.array([h['lr'] for h in self.opt.hypers])
    119 scheds = {'lr': combined_cos(pct_start, lr_max[/div](http://localhost:8888/div), lr_max, lr_max[/div_final](http://localhost:8888/div_final)),
    120           'mom': combined_cos(pct_start, *(self.moms if moms is None else moms))}
--> 121 self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd, start_epoch=start_epoch)

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastai/learner.py:272, in Learner.fit(self, n_epoch, lr, wd, cbs, reset_opt, start_epoch)
    270 self.opt.set_hypers(lr=self.lr if lr is None else lr)
    271 self.n_epoch = n_epoch
--> 272 self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastai/learner.py:207, in Learner._with_events(self, f, event_type, ex, final)
    206 def _with_events(self, f, event_type, ex, final=noop):
--> 207     try: self(f'before_{event_type}');  f()
    208     except ex: self(f'after_cancel_{event_type}')
    209     self(f'after_{event_type}');  final()

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastai/learner.py:180, in Learner.__call__(self, event_name)
--> 180 def __call__(self, event_name): L(event_name).map(self._call_one)

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastcore/foundation.py:225, in curryable.<locals>.wrapper(self, *args, **kwargs)
    222 @wraps(f)
    223 def wrapper(self, *args, **kwargs):
    224     if not isinstance(self, L): return lambda items: f(L(items), self, *args, **kwargs)
--> 225     return f(L(self), *args, **kwargs)

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastcore/foundation.py:233, in map(self, f, *args, **kwargs)
    229 @patch
    230 @curryable
    231 def map(self:L, f, *args, **kwargs):
    232     "Create new `L` with `f` applied to all `items`, passing `args` and `kwargs` to `f`"
--> 233     return self._new(map_ex(self, f, *args, gen=False, **kwargs))

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastcore/basics.py:952, in map_ex(iterable, f, gen, *args, **kwargs)
    950 res = map(g, iterable)
    951 if gen: return res
--> 952 return list(res)

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastcore/basics.py:937, in bind.__call__(self, *args, **kwargs)
    935     if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
    936 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 937 return self.func(*fargs, **kwargs)

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastai/learner.py:184, in Learner._call_one(self, event_name)
    182 def _call_one(self, event_name):
    183     if not hasattr(event, event_name): raise Exception(f'missing {event_name}')
--> 184     for cb in self.cbs.sorted('order'): cb(event_name)

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastai/callback/core.py:64, in Callback.__call__(self, event_name)
     62     try: res = getcallable(self, event_name)()
     63     except (CancelBatchException, CancelBackwardException, CancelEpochException, CancelFitException, CancelStepException, CancelTrainException, CancelValidException): raise
---> 64     except Exception as e: raise modify_exception(e, f'Exception occured in `{self.__class__.__name__}` when calling event `{event_name}`:\n\t{e.args[0]}', replace=True)
     65 if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit
     66 return res

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastai/callback/core.py:62, in Callback.__call__(self, event_name)
     60 res = None
     61 if self.run and _run: 
---> 62     try: res = getcallable(self, event_name)()
     63     except (CancelBatchException, CancelBackwardException, CancelEpochException, CancelFitException, CancelStepException, CancelTrainException, CancelValidException): raise
     64     except Exception as e: raise modify_exception(e, f'Exception occured in `{self.__class__.__name__}` when calling event `{event_name}`:\n\t{e.args[0]}', replace=True)

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastai/callback/progress.py:23, in ProgressCallback.before_fit(self)
     21 if self.learn.logger != noop:
     22     self.old_logger,self.learn.logger = self.logger,self._write_stats
---> 23     self._write_stats(self.recorder.metric_names)
     24 else: self.old_logger = noop

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastai/callback/progress.py:48, in ProgressCallback._write_stats(self, log)
     47 def _write_stats(self, log):
---> 48     if getattr(self, 'mbar', False): self.mbar.write([f'{l:.6f}' if isinstance(l, float) else str(l) for l in log], table=True)

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastprogress/fastprogress.py:239, in NBMasterBar.write(self, line, table)
    237 if table: self.lines.append(line); self.text_parts = [text2html_table(self.lines)]
    238 else: self.text_parts.append(P(line))
--> 239 self.show()

File ~/src/fastai-course/.venv/lib/python3.12/site-packages/fastprogress/fastprogress.py:234, in NBMasterBar.show(self)
    231 self.inner_dict['text'] = Div(*self.text_parts)
    232 children = [getattr(item, 'progress', None) or item for n in self.order
    233     if (item := self.inner_dict.get(n))]
--> 234 self.out.update(Div(*children))

AttributeError: Exception occured in `ProgressCallback` when calling event `before_fit`:
	'NBMasterBar' object has no attribute 'out'

This can be worked around by disabling the progress bar callback (learn.remove_cb(ProgressCallback)).

Fast.ai before_fit instantiates the progress bar, and then calls show, without ever initialising self.out.

In the code, self.out is initialised in on_iter_begin.

fastprogress version 1.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions