Debugging¤
Debugging mode can be turned on globally by setting the FEEDBAX_DEBUG
environment variable to "True"
.
This can be done from within Python, as shown below, or by setting FEEDBAX_DEBUG=True
in your shell before executing Python from the command line.
import os
os.environ["FEEDBAX_DEBUG"] = str(True)
Logging details of model execution¤
The main debugging feature implemented in Feedbax so far is automatic logging of the state operations performed by any subclass of AbstractStagedModel
.
For example, now that we've enabled debugging, when a model is executed during training or validation...
import jax
from feedbax.xabdeef import point_mass_nn_simple_reaches
key_init, key_eval = jax.random.split(jax.random.PRNGKey(0))
context = point_mass_nn_simple_reaches(key=key_init)
task, model = context.task, context.model
# We won't bother to train the model for this example
states = task.eval(model, key=key_eval)
...a detailed summary of the model stages that were executed will be saved to the log.
!cat feedbax.log
Each entry in the log begins with the date and time the log was made.
Entries whose first line contains [DEBUG] feedbax.staged
are logs of model stages that were just executed. Thus, the time between the previous log entry and the current one gives the approximate duration of the current stage.
Following that first line are indented lines that provide details:
The type of AbstractStagedModel
that the stage that was just executed belongs to.
The stage's label, which is used to identify it among all the stages that belong to its model type.
What is actually called, in order to execute the stage. This may be:
- an Equinox model—such as another type of
AbstractStagedModel
—in which case the code that was executed can be found in that module's__call__
method. For example, in the stage"hidden"
of model typeSimpleStagedNetwork
logged above, the Equinox moduleGRUCell
was called; - a method of a class or module. Typically these are logged as
BoundMethod
, where__func__
provides the name of the method, and__self__
provides the class that the method belongs to; - some other function or callable object.
Logs the structure of the input that was passed to the callable.
The part of the model type's state that can be updated by the model stage.
For example, the state associated with the staged model SimpleFeedback
is SimpleFeedbackState
, which contains a field network
of type NetworkState
. The stage "nn_step"
of SimpleFeedback
passes this NetworkState
to SimpleStagedNetwork
which returns an updated NetworkState
.
Warning
Keep in mind that for long training runs, enabling FEEDBAX_DEBUG
may result in very large log files, with all of the model stages logged repeatedly on every training run. If you are trying to debug a structural problem in the model step, it's preferable to do a single evaluation of the model as above, so that each stage will only be executed once.