caching
Caching and memoization of function calls.
cache(expire=None, typed=False, ignore=())
Caching decorator for memoizing function calls.
The cache key is created based on the values returned by the key_function callable if provided or based on the arguments of the decorated function directly otherwise
This is based on diskcache
's memoize
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expire
|
Optional[float]
|
Seconds until arguments expire. |
None
|
typed
|
Cache different types separately. |
False
|
|
ignore
|
Positional or keyword arguments to ignore. |
()
|
Returns:
Type | Description |
---|---|
A decorator function that can be applied to other functions.
|
|
Source code in outlines/caching.py
clear_cache()
disable_cache()
Disable the cache for this session.
Generative models output different results each time they are called when
sampling. This can be a desirable property for some workflows, in which case
one can call outlines.call.disable
to disable the cache for the session.
This function does not delete the cache, call outlines.cache.clear
instead. It also does not overwrite the cache with the values returned
during the session.
Example
outlines.cache.disable
should be called right after importing outlines:
import outlines.caching as cache cache.disable_cache()
Source code in outlines/caching.py
get_cache()
cached
Get the context object that contains previously-computed return values.
The cache is used to avoid unnecessary computations and API calls, which can be long and expensive for large models.
The cache directory defaults to HOMEDIR/.cache/outlines
, but this choice
can be overridden by the user by setting the value of the OUTLINES_CACHE_DIR
environment variable.