quanda.utils.cache module¶
Module for caching explanations.
- class quanda.utils.cache.BatchedCachedExplanations(cache_dir: str, device: str | None = None)[source]¶
Bases:
objectUtility class for lazy loading and saving batched explanations.
- class quanda.utils.cache.Cache[source]¶
Bases:
objectAbstract class for caching. Methods of this class are static.
- class quanda.utils.cache.ExplanationsCache[source]¶
Bases:
CacheClass for caching generated explanations at a given path.
- static exists(path: str, num_id: str | int | None = None) bool[source]¶
Check if the explanations exist at the given path.
- Parameters:
path (str) – Path to the explanations.
num_id (Optional[Union[str, int]]) – Number identifier for the explanations.
- Returns:
True if the explanations exist, False otherwise.
- Return type:
bool
- static load(path: str, device: str | None = None) BatchedCachedExplanations[source]¶
Load the explanations from the given path.
- Parameters:
path (str) – Path to load the explanations.
device (Optional[str]) – Device to load the explanations on.
- Returns:
BatchedCachedExplanations object that can load explanations lazily by index.
- Return type:
- static save(path: str, exp_tensors: Tensor, num_id: str | int) None[source]¶
Save the explanations to the given path.
- Parameters:
path (str) – Path to save the explanations.
exp_tensors (torch.Tensor) – Explanations to save.
num_id (Union[str, int]) – Number identifier for the explanations.
- Return type:
None