pytorch_pfn_extras.training.extensions.VariableStatisticsPlot#

class pytorch_pfn_extras.training.extensions.VariableStatisticsPlot(targets, max_sample_size=1000, report_data=True, report_grad=True, plot_mean=True, plot_std=True, percentile_sigmas=(0, 0.13, 2.28, 15.87, 50, 84.13, 97.72, 99.87, 100), trigger=(1, 'epoch'), filename='statistics.png', figsize=None, marker=None, grid=True)#

Bases: Extension

An extension to plot statistics for Tensors.

This extension collects statistics for a single torch.Tensor, a list of torch.Tensors or similarly a single or a list of torch.nn.Modules containing one or more torch.Tensors. In case multiple torch.Tensors are found, the means are computed. The collected statistics are plotted and saved as an image in the directory specified by the Manager.

Statistics include mean, standard deviation and percentiles.

This extension uses reservoir sampling to preserve memory, using a fixed size running sample. This means that collected items in the sample are discarded uniformly at random when the number of items becomes larger than the maximum sample size, but each item is expected to occur in the sample with equal probability.

:param targets (torch.Tensor: or list of either): Parameters for which statistics are collected. :param torch.nn.Module: or list of either): Parameters for which statistics are collected. :param max_sample_size: Maximum number of running samples. :type max_sample_size: int :param report_data: If True, data (e.g. weights) statistics are plotted. If

False, they are neither computed nor plotted.

Parameters:
  • report_grad (bool) – If True, gradient statistics are plotted. If False, they are neither computed nor plotted.

  • plot_mean (bool) – If True, means are plotted. If False, they are neither computed nor plotted.

  • plot_std (bool) – If True, standard deviations are plotted. If False, they are neither computed nor plotted.

  • percentile_sigmas (float or tuple of floats) – Percentiles to plot in the range \([0, 100]\).

  • trigger (Optional[Union[Trigger, Callable[[ExtensionsManagerProtocol], bool], Tuple[float, str]]]) – Trigger that decides when to save the plots as an image. This is distinct from the trigger of this extension itself. If it is a tuple in the form <int>, 'epoch' or <int>, 'iteration', it is passed to IntervalTrigger.

  • filename (str) – Name of the output image file under the output directory. For historical reasons file_name is also accepted as an alias of this argument.

  • figsize (tuple of int) – Matlotlib figsize argument that specifies the size of the output image.

  • marker (str) – Matplotlib marker argument that specified the marker style of the plots.

  • grid (bool) – Matplotlib grid argument that specifies whether grids are rendered in in the plots or not.

  • writer (writer object, optional) – must be callable. object to dump the log to. If specified, it needs to have a correct savefun defined. The writer can override the save location in the pytorch_pfn_extras.training.ExtensionsManager object

  • targets (Any) –

  • max_sample_size (int) –

  • report_data (bool) –

  • kwargs (Any) –

Methods

__init__(targets[, max_sample_size, ...])

available()

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.

save_plot_using_module(plt, manager)

state_dict()

Serializes the extension state.

Attributes

default_name

Default name of the extension.

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__(targets, max_sample_size=1000, report_data=True, report_grad=True, plot_mean=True, plot_std=True, percentile_sigmas=(0, 0.13, 2.28, 15.87, 50, 84.13, 97.72, 99.87, 100), trigger=(1, 'epoch'), filename=None, figsize=None, marker=None, grid=True, **kwargs)#
Parameters:
  • targets (Any) –

  • max_sample_size (int) –

  • report_data (bool) –

  • report_grad (bool) –

  • plot_mean (bool) –

  • plot_std (bool) –

  • percentile_sigmas (Union[float, Tuple[float, ...]]) –

  • trigger (Optional[Union[Trigger, Callable[[ExtensionsManagerProtocol], bool], Tuple[float, str]]]) –

  • filename (Optional[str]) –

  • figsize (Optional[Tuple[int, ...]]) –

  • marker (Optional[str]) –

  • grid (bool) –

  • kwargs (Any) –

static available()#
Return type:

bool

finalize(manager)#

Finalizes the extension.

This method is called at the end of the training loop.

Parameters:

manager (ExtensionsManagerProtocol) –

Return type:

None

save_plot_using_module(plt, manager)#
Parameters:
Return type:

None