From 8ae40860bc5b1ce58402f5f0a4f2e7779613b9fb Mon Sep 17 00:00:00 2001 From: Philippe Lelievre Date: Wed, 4 Sep 2024 15:49:00 -0400 Subject: [PATCH 1/5] fix: cache key as string --- outlines/caching.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/outlines/caching.py b/outlines/caching.py index 6fdda6214..83b91755e 100644 --- a/outlines/caching.py +++ b/outlines/caching.py @@ -126,7 +126,8 @@ 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 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 From 8c881d219dfe457bea55e3b1a646761e63fa7c29 Mon Sep 17 00:00:00 2001 From: Philippe Lelievre Date: Wed, 4 Sep 2024 15:56:03 -0400 Subject: [PATCH 2/5] remove comment --- outlines/caching.py | 1 - 1 file changed, 1 deletion(-) diff --git a/outlines/caching.py b/outlines/caching.py index 83b91755e..3e58c7c16 100644 --- a/outlines/caching.py +++ b/outlines/caching.py @@ -126,7 +126,6 @@ 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 From 058f505b0c224f73da1ff7f23fdc0d59eced5740 Mon Sep 17 00:00:00 2001 From: Philippe Lelievre Date: Thu, 12 Sep 2024 10:47:11 -0400 Subject: [PATCH 3/5] add tests --- tests/test_cache.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_cache.py b/tests/test_cache.py index eb4ec406e..0f9fb58fc 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -1,3 +1,4 @@ +from dataclasses import dataclass import os import tempfile import unittest @@ -68,6 +69,39 @@ 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() + dummy_object.dummy_function.__dict__["__memory__"] = memory + + 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 From 9851ec6ddd29c3e65d89a314c6dc0355cbf09018 Mon Sep 17 00:00:00 2001 From: Philippe Lelievre Date: Thu, 12 Sep 2024 10:50:10 -0400 Subject: [PATCH 4/5] remove not need line --- tests/test_cache.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_cache.py b/tests/test_cache.py index 0f9fb58fc..3c3a679f0 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -87,9 +87,7 @@ def dummy_function(cls, a): class DummyArg: a: int - dummy_object = DummyObject() - dummy_object.dummy_function.__dict__["__memory__"] = memory a_1 = DummyArg(1) From 7496ffe65c04bfc46a5ee5a27aba9a3b0d33546a Mon Sep 17 00:00:00 2001 From: Philippe Lelievre Date: Thu, 12 Sep 2024 12:51:52 -0400 Subject: [PATCH 5/5] remove unused code section --- tests/test_cache.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_cache.py b/tests/test_cache.py index 3c3a679f0..4492ed58a 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -70,10 +70,6 @@ def f(x): def test_get_cache_from_class_method(test_cache): - import outlines - memory = outlines.get_cache() - memory.clear() - store = list() class DummyObject: