pytorch_pfn_extras.training.extensions.snapshot_writers.StandardWriter#
- class pytorch_pfn_extras.training.extensions.snapshot_writers.StandardWriter(savefun=<function save>, fs=None, out_dir='', **kwds)#
Bases:
Writer,Generic[_Worker]Base class of snapshot writers which use thread or process.
This class creates a new thread or a process every time when
__call__is invoked.- Parameters:
savefun (Callable[[...], None]) – Callable object. It takes three arguments: the output file path, the serialized dictionary object, and the optional keyword arguments.
fs (Any) – FileSystem abstracting interface to implement all the operations. optional, defaults to None
out_dir (str) – str. Specifies the directory this writer will use. It takes precedence over the one specified in __call__ optional, defaults to
''kwds (Any) – Keyword arguments for the
savefun.
Methods
__init__([savefun, fs, out_dir])create_worker(filename, out_dir, target, *)Creates a worker for the snapshot.
finalize()Finalizes the writer.
initialize(out_dir)save(filename, out_dir, target, savefun, ...)- __call__(filename, out_dir, target, *, savefun=None, append=False)#
Does the actual writing to the file.
This method is invoked by a
Snapshotobject every time it takes a snapshot.- Parameters:
filename (str) – Name of the file into which the serialized target is saved. It is a concrete file name, i.e. not a pre-formatted template string.
out_dir (str) –
Output directory. Corresponds to :py:attr:`ExtensionsManager.out
<pytorch_pfn_extras.training.ExtensionsManager.out>`.
target (dict) – Serialized object which will be saved.
savefun (callable) – A callable that accepts a two positional arguments (an object to be serialized, file path) like torch.save.
append (bool) – Mode used to open the file. True to use the append mode, False to use the write mode (truncates the file if it already exists).
- Return type:
None
- __init__(savefun=<function save>, fs=None, out_dir='', **kwds)#
- create_worker(filename, out_dir, target, *, savefun=None, append=False, **savefun_kwargs)#
Creates a worker for the snapshot.
This method creates a thread or a process to take a snapshot. The created worker must have
start()andjoin()methods. If the worker has anexitcodeattribute (e.g.,multiprocessing.Process), the value will be tested.
- finalize()#
Finalizes the writer.
Calling this method on already-finalized Writer does nothing.
- Return type:
None