RichProgressBar#

class braintools.trainer.RichProgressBar(refresh_rate=1, leave=False)#

Rich progress bar for training visualization.

Rendering is delegated to RichProgressBarWrapper, the same progress bar the Trainer uses. If the ‘rich’ package is not installed, a warning is emitted and the wrapper falls back to SimpleProgressBar.

Parameters:
  • refresh_rate (int) – Number of batches between progress bar updates.

  • leave (bool) – Whether to leave the progress bar after completion. False makes the rich bar transient, so it is removed when the epoch ends.

Examples

Disable the trainer’s built-in bar so the callback is the only one shown:

>>> import numpy as np
>>> import jax.numpy as jnp
>>> import brainstate
>>> import braintools
>>> class Regressor(braintools.trainer.LightningModule):
...     def __init__(self):
...         super().__init__()
...         self.linear = brainstate.nn.Linear(2, 1)
...     def training_step(self, batch, batch_idx):
...         x, y = batch
...         loss = jnp.mean((self.linear(x) - y) ** 2)
...         self.log('loss', loss, prog_bar=True)
...         return {'loss': loss}
...     def validation_step(self, batch, batch_idx):
...         x, y = batch
...         return {'loss': jnp.mean((self.linear(x) - y) ** 2)}
...     def configure_optimizers(self):
...         return braintools.optim.Adam(lr=0.1)
>>> rng = np.random.default_rng(0)
>>> X = rng.normal(size=(64, 2)).astype(np.float32)
>>> y = X @ np.array([[1.0], [-2.0]], dtype=np.float32) + 0.5
>>> loader = braintools.trainer.DataLoader((X, y), batch_size=32)
>>> brainstate.random.seed(0)
>>> model = Regressor()
>>> progress = braintools.trainer.RichProgressBar()
>>> trainer = braintools.trainer.Trainer(
...     max_epochs=2, callbacks=[progress],
...     logger=False, enable_progress_bar=False, enable_checkpointing=False)
>>> trainer.fit(model, loader)
>>> trainer.global_step
4
on_train_batch_end(trainer, module, outputs, batch, batch_idx)[source]#

Update progress bar.

on_train_epoch_end(trainer, module)[source]#

Complete progress bar.

on_train_epoch_start(trainer, module)[source]#

Create progress bar for epoch.