Shortcuts

utils

class trojanzoo.utils.lock.Lock[source]

A boolean lock class used for contextmanager. It’s used in KFAC to avoid auxiliary computation operations.

Example:
>>> from trojanzoo.utils.lock import Lock
>>>
>>> track = Lock()
>>> print(bool(track))
False
>>> with track():
>>>     print(bool(track))
True
>>> print(bool(track))
False
>>> track.enable()
>>> print(bool(track))
True
>>> track.disable()
>>> print(bool(track))
False
disable()[source]

Set lock boolean value as False. It’s used together with enable() when contextmanager is not suitable for the case.

enable()[source]

Set lock boolean value as True. It’s used together with disable() when contextmanager is not suitable for the case.

trojanzoo.utils.memory.empty_cache(threshold=None)[source]

Call torch.cuda.empty_cache to empty GPU cache when torch.cuda.memory_cached() > thresholdMB.

Parameters:

threshold (float) – The cached memory threshold (MB). Defaults to env['cache_threshold'].

trojanzoo.utils.memory.output_memory(device=None, full=False, indent=0, **kwargs)[source]

Output memory usage information.

Parameters:

Docs

Access comprehensive developer documentation for TrojanZoo

View Docs