Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion outlines/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def wrapper(*args, **kwargs):

def __cache_key__(*args, **kwargs):
"""Make key for cache given function arguments."""
return args_to_key(base, args, kwargs, typed, ignore)
return str(args_to_key(base, args, kwargs, typed, ignore))

wrapper.__cache_key__ = __cache_key__ # type: ignore
wrapper.__memory__ = memory # type: ignore
Expand Down
32 changes: 32 additions & 0 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dataclasses import dataclass
import os
import tempfile
import unittest
Expand Down Expand Up @@ -68,6 +69,37 @@ def f(x):
assert len(store) == store_size + 1


def test_get_cache_from_class_method(test_cache):
import outlines
memory = outlines.get_cache()
memory.clear()

store = list()

class DummyObject:
@classmethod
@test_cache
def dummy_function(cls, a):
store.append(a)
return a

@dataclass
class DummyArg:
a: int

dummy_object = DummyObject()

a_1 = DummyArg(1)

dummy_object.dummy_function(a_1)
assert len(store) == 1
store_size = len(store)

a_2 = DummyArg(1)
dummy_object.dummy_function(a_2)
assert len(store) == store_size


def test_disable_cache(test_cache):
"""Make sure that we can disable the cache."""
import outlines
Expand Down