Module Expr Str Import alias Import alias Import alias ImportFrom alias ImportFrom alias ImportFrom alias alias alias ImportFrom alias alias ImportFrom alias ImportFrom alias ImportFrom alias Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Str Assign NameStore Str Assign NameStore Str Assign NameStore Str Assign NameStore Str ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults NameLoad NameLoad NameLoad NameLoad body If CompareIs NameLoad NameLoad body If CompareIs NameLoad NameLoad body Assign NameStore AttributeLoad NameLoad attr Assign NameStore Call SubscriptLoad NameLoad Index NameLoad If CompareIs NameLoad NameLoad body Assign NameStore ListLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call NameLoad Assign AttributeStore NameLoad attr NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad decorator_list FunctionDef arguments args NameParam defaults body If UnaryOpNot AttributeLoad NameLoad attr body Raise Call NameLoad BinOpAdd Str NameLoad Return AttributeLoad NameLoad attr decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Return TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list NameLoad FunctionDef arguments args NameParam NameParam defaults body Assign TupleStore AttributeStore NameLoad attr AttributeStore NameLoad attr NameLoad decorator_list AttributeLoad NameLoad attr FunctionDef arguments args NameParam defaults body Expr Str Return AttributeLoad AttributeLoad NameLoad attr attr decorator_list NameLoad FunctionDef arguments args NameParam defaults body Expr Str Expr Call AttributeLoad NameLoad attr Assign AttributeStore AttributeLoad NameLoad attr attr ListLoad If BoolOpAnd AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr NameLoad Call NameLoad AttributeLoad NameLoad attr NameLoad body If UnaryOpNot CompareEq Call NameLoad Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr attr Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr body Expr Call AttributeLoad NameLoad attr Str With Call NameLoad AttributeLoad NameLoad attr body Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr TryFinally body TryExcept body Expr Call AttributeLoad NameLoad attr Str If UnaryOpNot SubscriptLoad AttributeLoad NameLoad attr Index Str body For NameStore AttributeLoad NameLoad attr body Assign AttributeStore NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Str With Call NameLoad Str AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad If CompareGt SubscriptLoad AttributeLoad AttributeLoad NameLoad attr attr Index Str Num body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr Str Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad With Call NameLoad Str AttributeLoad NameLoad attr body While Call AttributeLoad NameLoad attr body Pass handlers ExceptHandler type NameLoad body Assign SubscriptStore AttributeLoad AttributeLoad NameLoad attr attr Index Str NameLoad ExceptHandler type NameLoad name NameStore body Expr Call AttributeLoad NameLoad attr Assign SubscriptStore AttributeLoad AttributeLoad NameLoad attr attr Index Str Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpAdd Str NameLoad TryExcept body Expr Call AttributeLoad NameLoad attr Str handlers ExceptHandler type NameLoad body Expr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpAdd Str NameLoad Expr Call NameLoad NameLoad finalbody Expr Call AttributeLoad NameLoad attr If Call AttributeLoad AttributeLoad AttributeLoad NameLoad attr attr attr Str NameLoad body Expr Call AttributeLoad NameLoad attr Str If AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return Call NameLoad ListComp NameLoad comprehension NameStore AttributeLoad NameLoad attr CompareEq AttributeLoad NameLoad attr NameLoad keyword NameLoad decorator_list FunctionDef arguments args NameParam defaults body If UnaryOpNot Call AttributeLoad AttributeLoad NameLoad attr attr Str NameLoad body TryExcept body Assign SubscriptStore AttributeLoad AttributeLoad NameLoad attr attr Index Str NameLoad Assign AttributeStore NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr keyword NameLoad handlers ExceptHandler type NameLoad body Return NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad Expr Call AttributeLoad NameLoad attr Str With Call NameLoad Str AttributeLoad NameLoad attr body While Call AttributeLoad NameLoad attr body Pass Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad AugAssignAdd SubscriptStore AttributeLoad NameLoad attr Index Str Num AugAssignAdd SubscriptStore AttributeLoad NameLoad attr Index Str ListLoad SubscriptLoad AttributeLoad NameLoad attr Index Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body TryExcept body With Call NameLoad Str AttributeLoad NameLoad attr body Assign NameStore Call NameLoad AttributeLoad NameLoad attr handlers ExceptHandler type NameLoad body If UnaryOpNot SubscriptLoad AttributeLoad AttributeLoad NameLoad attr attr Index Str body Expr Call NameLoad Call NameLoad Str Return NameLoad Assign SubscriptStore AttributeLoad AttributeLoad NameLoad attr attr Index Str NameLoad Expr Call AttributeLoad NameLoad attr Str NameLoad With Call NameLoad Str AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad AugAssignAdd SubscriptStore AttributeLoad NameLoad attr Index Str Num Expr Call AttributeLoad NameLoad attr Str NameLoad Expr Call AttributeLoad NameLoad attr Str Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults vararg body With Call NameLoad NameLoad AttributeLoad NameLoad attr body For NameStore AttributeLoad NameLoad attr body With Call NameLoad AttributeLoad Call NameLoad NameLoad attr AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str If BoolOpOr Call AttributeLoad AttributeLoad AttributeLoad NameLoad attr attr attr Str NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr Str NameLoad body Raise NameLoad If BoolOpAnd CompareEq NameLoad Str Call AttributeLoad AttributeLoad NameLoad attr attr Str NameLoad body Raise NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Call AttributeLoad NameLoad attr BinOpAdd Str NameLoad Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign SubscriptStore AttributeLoad AttributeLoad NameLoad attr attr Index Str NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpAdd Str NameLoad Assign SubscriptStore AttributeLoad AttributeLoad NameLoad attr attr Index Str NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index Str NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases NameLoad body Expr Str Pass decorator_list
N/A N/A The event-based main loop of Blocks. N/A signal N/A logging N/A traceback blocks.config config blocks.log BACKENDS blocks.utils reraise_as unpack change_recursion_limit blocks.utils.profile Profile Timer blocks.algorithms DifferentiableCostMinimizer blocks.extensions CallbackName blocks.model Model N/A logger N/A N/A logging getLogger __name__ N/A error_message 

Blocks will attempt to run `on_error` extensions, potentially saving data, before exiting and reraising the error. Note that the usual `after_training` extensions will *not* be run. The original error will be re-raised and also stored in the training log. Press CTRL + C to halt Blocks immediately. N/A error_in_error_handling_message 

Blocks will now exit. The remaining `on_error` extensions will not be run. N/A epoch_interrupt_message 

Blocks will complete this epoch of training and run extensions before exiting. If you do not want to complete this epoch, press CTRL + C again to stop training after the current batch. N/A batch_interrupt_message 

Blocks will complete the current batch and run extensions before exiting. If you do not want to complete this batch, press CTRL + C again. WARNING: Note that this will end training immediately, and extensions that e.g. save your training progress won't be run. N/A no_model_message 

A possible reason: one of your extensions requires the main loop to have a model. Check documentation of your extensions. MainLoop N/A object N/A N/A The standard main loop of Blocks.

    In the `MainLoop` a model is trained by a training algorithm using data
    extracted from a data stream. This process is scrupulously documented
    in a log object.

    The `MainLoop` itself does very little: only fetching the data from the
    data stream and feeding it to the algorithm. It expects the extensions
    to do most of the job. A respective callback of every extension is
    called at every stage of training. The extensions should communicate
    between themselves and with the main loop object by means of making
    records in the log. For instance in order to stop the training
    procedure an extension can make a record
    `training_finish_requested=True` in the log. The main loop checks for
    such a record after every batch and every epoch and terminates when
    finds it.

    The `MainLoop` also handles interruption signal SIGINT for you (e.g.
    the one program receives when you press Ctrl + C). It notes this event
    in the log and at the next iteration or epoch end the main loop will
    be gracefully finished, with calling all necessary extension callbacks
    and waiting until they finish.

    Parameters
    ----------
    algorithm : instance of :class:`~blocks.algorithms.TrainingAlgorithm`
        The training algorithm.
    data_stream : instance of :class:`.DataStream`.
        The data stream. Should support :class:`AbstractDataStream`
        interface from Fuel.
    model : instance of :class:`.ComputationGraph`, optional
        An annotated computation graph, typically represented
        by :class:`ComputationGraph` or :class:`Model` object. The main
        loop object uses the model only for optional sanity checks, it is
        here mainly for the main loop extensions.
    log : instance of :class:`.TrainingLog`, optional
        The log. When not given, a :class:`.TrainingLog` is created.
    log_backend : str
        The backend to use for the log. Currently `python` and `sqlite` are
        available. If not given, `config.log_backend` will be used. Ignored
        if `log` is passed.
    extensions : list of :class:`.TrainingExtension` instances
        The training extensions. Will be called in the same order as given
        here.

     __init__ N/A N/A self algorithm data_stream model log log_backend extensions N/A None None None None N/A N/A N/A log None N/A N/A N/A log_backend None N/A N/A log_backend N/A config log_backend N/A log N/A N/A BACKENDS N/A log_backend N/A N/A extensions None N/A N/A extensions N/A N/A N/A self data_stream data_stream N/A N/A self algorithm algorithm N/A N/A self log log N/A N/A self extensions extensions N/A N/A self profile N/A Profile N/A N/A self _model model N/A N/A N/A self status N/A training_started False N/A N/A N/A self status N/A epoch_started False N/A N/A N/A self status N/A epoch_interrupt_received False N/A N/A N/A self status N/A batch_interrupt_received False N/A model N/A N/A self N/A N/A N/A N/A N/A self _model N/A N/A N/A AttributeError N/A no model in this main loop no_model_message N/A N/A self _model N/A property iteration_state N/A N/A self N/A N/A N/A Quick access to the (data stream, epoch iterator) pair. N/A N/A N/A self data_stream N/A self epoch_iterator N/A property iteration_state N/A N/A self value N/A N/A N/A N/A N/A self data_stream N/A self epoch_iterator value N/A N/A iteration_state setter status N/A N/A self N/A N/A N/A A shortcut for `self.log.status`. N/A N/A N/A self log status N/A property run N/A N/A self N/A N/A N/A Starts the main loop.

        The main loop ends when a training extension makes
        a `training_finish_requested` record in the log.

         N/A N/A N/A logging basicConfig N/A N/A N/A self profile current N/A N/A N/A N/A self _model N/A isinstance N/A self _model Model N/A isinstance N/A self algorithm DifferentiableCostMinimizer N/A N/A N/A N/A N/A set N/A N/A N/A N/A N/A self _model get_parameter_dict values N/A set N/A N/A self algorithm parameters N/A N/A N/A N/A logger warning different parameters for model and algorithm N/A N/A change_recursion_limit N/A config recursion_limit N/A N/A N/A self original_sigint_handler N/A N/A signal signal N/A signal SIGINT N/A self _handle_epoch_interrupt N/A N/A self original_sigterm_handler N/A N/A signal signal N/A signal SIGTERM N/A self _handle_batch_interrupt N/A N/A N/A N/A N/A N/A N/A logger info Entered the main loop N/A N/A N/A N/A self status N/A training_started N/A N/A extension N/A self extensions N/A N/A N/A extension main_loop self N/A N/A N/A self _run_extensions before_training N/A N/A Timer initialization N/A self profile N/A N/A N/A N/A N/A self algorithm initialize N/A N/A N/A self status N/A training_started True N/A N/A N/A N/A N/A self log status N/A iterations_done 0 N/A N/A N/A N/A N/A self log resume N/A N/A N/A self _run_extensions on_resumption N/A N/A N/A self status N/A epoch_interrupt_received False N/A N/A N/A self status N/A batch_interrupt_received False N/A N/A Timer training N/A self profile N/A N/A N/A N/A self _run_epoch N/A N/A N/A N/A N/A TrainingFinish N/A N/A N/A N/A N/A self log current_row N/A training_finished True N/A N/A Exception N/A e N/A N/A N/A N/A self _restore_signal_handlers N/A N/A N/A N/A self log current_row N/A got_exception N/A N/A traceback format_exc N/A N/A N/A logger error N/A Error occured during training. error_message N/A N/A N/A N/A N/A self _run_extensions on_error N/A N/A N/A Exception N/A N/A N/A N/A logger error N/A N/A traceback format_exc N/A N/A N/A logger error N/A Error occured when running extensions. error_in_error_handling_message N/A N/A reraise_as e N/A N/A N/A N/A self _restore_signal_handlers N/A N/A N/A N/A N/A self log current_row get training_finished False N/A N/A N/A N/A self _run_extensions after_training N/A N/A config profile N/A N/A N/A N/A N/A self profile report N/A find_extension N/A N/A self name N/A N/A N/A Find an extension with a given name.

        Parameters
        ----------
        name : str
            The name of the extension looked for.

        Notes
        -----
        Will crash if there no or several extension found.

         N/A N/A unpack N/A extension N/A extension N/A self extensions N/A N/A extension name name singleton True N/A _run_epoch N/A N/A self N/A N/A N/A N/A N/A N/A N/A self status get epoch_started False N/A N/A N/A N/A N/A N/A N/A self log status N/A received_first_batch False N/A N/A self epoch_iterator N/A N/A N/A self data_stream get_epoch_iterator as_dict True N/A N/A N/A StopIteration N/A N/A False N/A N/A N/A self status N/A epoch_started True N/A N/A N/A self _run_extensions before_epoch N/A N/A Timer epoch N/A self profile N/A N/A N/A N/A self _run_iteration N/A N/A N/A N/A N/A self status N/A epoch_started False N/A N/A N/A self status N/A epochs_done 1 N/A N/A N/A self status N/A _epoch_ends N/A N/A N/A self status N/A iterations_done N/A N/A N/A self _run_extensions after_epoch N/A N/A N/A self _check_finish_training epoch N/A True N/A _run_iteration N/A N/A self N/A N/A N/A N/A N/A N/A Timer read_data N/A self profile N/A N/A batch N/A next N/A self epoch_iterator N/A N/A N/A StopIteration N/A N/A N/A N/A N/A N/A self log status N/A received_first_batch N/A N/A N/A reraise_as N/A ValueError epoch iterator yielded zero batches N/A False N/A N/A N/A N/A self log status N/A received_first_batch True N/A N/A N/A self _run_extensions before_batch batch N/A N/A Timer train N/A self profile N/A N/A N/A N/A N/A self algorithm process_batch batch N/A N/A N/A self status N/A iterations_done 1 N/A N/A N/A self _run_extensions after_batch batch N/A N/A N/A self _check_finish_training batch N/A True N/A _run_extensions N/A N/A self method_name N/A args N/A N/A N/A Timer method_name N/A self profile N/A N/A extension N/A self extensions N/A N/A N/A Timer N/A N/A type extension __name__ N/A self profile N/A N/A N/A N/A extension dispatch N/A CallbackName method_name args N/A _check_finish_training N/A N/A self level N/A N/A N/A Checks whether the current training should be terminated.

        Parameters
        ----------
        level : {'epoch', 'batch'}
            The level at which this check was performed. In some cases, we
            only want to quit after completing the remained of the epoch.

         N/A N/A N/A N/A N/A N/A self log current_row get training_finish_requested False N/A N/A N/A self status get batch_interrupt_received False N/A N/A TrainingFinish N/A N/A N/A level epoch N/A N/A N/A self status get epoch_interrupt_received False N/A N/A TrainingFinish N/A _handle_epoch_interrupt N/A N/A self signal_number frame N/A N/A N/A N/A N/A logger warning N/A Received epoch interrupt signal. epoch_interrupt_message N/A N/A N/A signal signal N/A signal SIGINT N/A self _handle_batch_interrupt N/A N/A N/A N/A self log current_row N/A epoch_interrupt_received True N/A N/A N/A self status N/A epoch_interrupt_received True N/A _handle_batch_interrupt N/A N/A self signal_number frame N/A N/A N/A N/A N/A self _restore_signal_handlers N/A N/A N/A logger warning N/A Received batch interrupt signal. batch_interrupt_message N/A N/A N/A N/A self log current_row N/A batch_interrupt_received True N/A N/A N/A self status N/A batch_interrupt_received True N/A _restore_signal_handlers N/A N/A self N/A N/A N/A N/A N/A signal signal N/A signal SIGINT N/A self original_sigint_handler N/A N/A N/A signal signal N/A signal SIGTERM N/A self original_sigterm_handler N/A N/A TrainingFinish N/A Exception N/A N/A An exception raised when a finish request is found in the log. N/A N/A