pytorch_pfn_extras.training.extensions.BestValue#

class pytorch_pfn_extras.training.extensions.BestValue(key, compare, trigger=(1, 'epoch'))#

Bases: Extension

Extension traces the best value of a specific key in the observation.

Parameters:
  • key (str) – Key of value.

  • compare (callable) – Compare function which takes current best value and new value and returns whether new value is better than current best.

  • trigger (TriggerLike) – Trigger that decides the comparison interval between current best value and new value. This must be a tuple in the form of <int>, 'epoch' or <int>, 'iteration' which is passed to BestValueTrigger.

Methods

__init__(key, compare[, trigger])

finalize(manager)

Finalizes the extension.

initialize(manager)

Initializes up the manager state.

load_state_dict(to_load)

on_error(manager, exc, tb)

Handles the error raised during training before finalization.

state_dict()

Serializes the extension state.

Attributes

best_epoch

Returns the epoch count that the current best value is observed.

best_iteration

Returns the iteration count that the current best value is observed.

best_value

Returns the current best value.

default_name

is_async

name

needs_model_state

priority

trigger

__call__(manager)#

Invokes the extension.

Implementations should override this operator. This method is called at iterations which the corresponding trigger accepts.

Parameters:

manager (ExtensionsManager) – Manager object to call this operator.

Return type:

None

__init__(key, compare, trigger=(1, 'epoch'))#
Parameters:
  • key (str) –

  • compare (Callable[[float, float], bool]) –

  • trigger (TriggerLike) –

Return type:

None

property best_epoch: int#

Returns the epoch count that the current best value is observed.

If no value has been observed yet, it raises a RuntimError.

property best_iteration: int#

Returns the iteration count that the current best value is observed.

If no value has been observed yet, it raises a RuntimError.

property best_value: float#

Returns the current best value.

If no value has been observed yet, it raises a RuntimError.

default_name = 'best_value'#
load_state_dict(to_load)#
Parameters:

to_load (Dict[str, Any]) –

Return type:

None

state_dict()#

Serializes the extension state.

It is called when a manager that owns this extension is serialized. It serializes nothing by default.

Return type:

Dict[str, Any]