The center-piece of this module is the
det_hash() function, which computes a deterministic hash of an
arbitrary Python object. The other things in this module influence how that works in various ways.
- class tango.common.det_hash.CustomDetHash#
det_hash()pickles an object, and returns the hash of the pickled representation. Sometimes you want to take control over what goes into that hash. In that case, derive from this class and implement
det_hash()will pickle the result of this method instead of the object itself.
If you return
det_hash()falls back to the original behavior and pickles the object.
- class tango.common.det_hash.DetHashFromInitParams(*args, **kwargs)#
Add this class as a mixin base class to make sure your class’s det_hash is derived exclusively from the parameters passed to
- class tango.common.det_hash.DetHashWithVersion#
Add this class as a mixin base class to make sure your class’s det_hash can be modified by altering a static
VERSIONmember of your class.
Let’s say you are working on training a model. Whenever you change code that’s part of your experiment, you have to change the
VERSIONof the step that’s running that code to tell Tango that the step has changed and should be re-run. But if you are training your model using Tango’s built-in
TorchTrainStep, how do you change the version of the step? The answer is, leave the version of the step alone, and instead add a
VERSIONto your model by deriving from this class:
class MyModel(DetHashWithVersion): VERSION = "001" def __init__(self, ...): ...