How to diable progress bar completely

I want to suppress all output from fastai2 and other packages, so I used %%capture magic.

But it seems fastai2 requires stream to display progress bar, so it raised error, can anybody tell me how to disable the progress bar completely?

%%capture --no-stderr
learn = Learner(...)

get AttributeError: 'NBMasterBar' object has no attribute 'out'

<ipython-input-9-886578be0f8a> in run_it(hparam, config, run_name, device)
     12   learn.recorder.silent = True
     13   # fit
---> 14   lr,_ = learn.lr_find(show_plot=False, num_it=int(46000/hparam['batch_size']/hparam['sequence_length']))
     15   config['lr'] = lr
     16   learn.fit_one_cycle(hparam['num_epoch'], lr, cbs=[MyWandbCallback(config=config, name=run_name),])

/usr/local/lib/python3.6/dist-packages/fastai2/callback/ in lr_find(self, start_lr, end_lr, num_it, stop_div, show_plot, suggestions)
    217     n_epoch = num_it//len(self.dls.train) + 1
    218     cb=LRFinder(start_lr=start_lr, end_lr=end_lr, num_it=num_it, stop_div=stop_div)
--> 219     with self.no_logging():, cbs=cb)
    220     if show_plot: self.recorder.plot_lr_find()
    221     if suggestions:

/usr/local/lib/python3.6/dist-packages/fastai2/ in fit(self, n_epoch, lr, wd, cbs, reset_opt)
    181             except CancelFitException:             self('after_cancel_fit')
--> 182             finally:                               self('after_fit')
    184     def validate(self, ds_idx=1, dl=None, cbs=None):

/usr/local/lib/python3.6/dist-packages/fastai2/ in __call__(self, event_name)
    106     def ordered_cbs(self, cb_func): return [cb for cb in sort_by_run( if hasattr(cb, cb_func)]
--> 108     def __call__(self, event_name): L(event_name).map(self._call_one)
    109     def _call_one(self, event_name):
    110         assert hasattr(event, event_name)

/usr/local/lib/python3.6/dist-packages/fastcore/ in map(self, f, *args, **kwargs)
    360              else f.format if isinstance(f,str)
    361              else f.__getitem__)
--> 362         return self._new(map(g, self))
    364     def filter(self, f, negate=False, **kwargs):

/usr/local/lib/python3.6/dist-packages/fastcore/ in _new(self, items, *args, **kwargs)
    313     @property
    314     def _xtra(self): return None
--> 315     def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
    316     def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)
    317     def copy(self): return self._new(self.items.copy())

/usr/local/lib/python3.6/dist-packages/fastcore/ in __call__(cls, x, *args, **kwargs)
     39             return x
---> 41         res = super().__call__(*((x,) + args), **kwargs)
     42         res._newchk = 0
     43         return res

/usr/local/lib/python3.6/dist-packages/fastcore/ in __init__(self, items, use_list, match, *rest)
    304         if items is None: items = []
    305         if (use_list is not None) or not _is_array(items):
--> 306             items = list(items) if use_list else _listify(items)
    307         if match is not None:
    308             if is_coll(match): match = len(match)

/usr/local/lib/python3.6/dist-packages/fastcore/ in _listify(o)
    240     if isinstance(o, list): return o
    241     if isinstance(o, str) or _is_array(o): return [o]
--> 242     if is_iter(o): return list(o)
    243     return [o]

/usr/local/lib/python3.6/dist-packages/fastcore/ in __call__(self, *args, **kwargs)
    206             if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
    207         fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 208         return self.fn(*fargs, **kwargs)
    210 # Cell

/usr/local/lib/python3.6/dist-packages/fastai2/ in _call_one(self, event_name)
    109     def _call_one(self, event_name):
    110         assert hasattr(event, event_name)
--> 111         [cb(event_name) for cb in sort_by_run(]
    113     def _bn_bias_state(self, with_bias): return bn_bias_params(self.model, with_bias).map(self.opt.state)

/usr/local/lib/python3.6/dist-packages/fastai2/ in <listcomp>(.0)
    109     def _call_one(self, event_name):
    110         assert hasattr(event, event_name)
--> 111         [cb(event_name) for cb in sort_by_run(]
    113     def _bn_bias_state(self, with_bias): return bn_bias_params(self.model, with_bias).map(self.opt.state)

/usr/local/lib/python3.6/dist-packages/fastai2/callback/ in __call__(self, event_name)
     21         _run = (event_name not in _inner_loop or (self.run_train and getattr(self, 'training', True)) or
     22                (self.run_valid and not getattr(self, 'training', False)))
---> 23         if and _run: getattr(self, event_name, noop)()
     24         if event_name=='after_fit': #Reset to True at each end of fit

/usr/local/lib/python3.6/dist-packages/fastai2/callback/ in after_fit(self)
     37     def after_fit(self):
     38         if getattr(self, 'mbar', False):
---> 39             self.mbar.on_iter_end()
     40             delattr(self, 'mbar')
     41         self.learn.logger = self.old_logger

/usr/local/lib/python3.6/dist-packages/fastprogress/ in on_iter_end(self)
    155             total_time = format_time(time.time() - self.main_bar.start_t)
    156             self.text = f'Total time: {total_time} <p>' + self.text
--> 157         self.out.update(HTML(self.text))
    159     def add_child(self, child):

It’s learn.no_bar. I forget what the other is but there’s two (do no and hit tab)

So you do

with learn.no_bar() and learn.the other one:


So much thanks !!
I found use wiht learn.no_bar() is enough to work with %%capture
and if I don’t want information print by fit completely, I can do with learn.no_bar(), learn.no_logging(), which I won’t see anything completely.

I found there are three related functions, and below is a small note.

no_bar no_mbar no_logging
main bar n n y
progress bar n y y
sheet n n n
L y n n

“progress bar” is phase (e.g. lr find) running.
“main bar” is progress of all epochs.
“sheet” is the table that shows val_loss and other things
“L” is a L object print by fit that records information recorded by sheet originally.