gpt4 book ai didi

python - Normalize_token 的意外行为

转载 作者:太空宇宙 更新时间:2023-11-03 14:39:08 27 4
gpt4 key购买 nike

我在以下测试中遇到了意外行为。我可能误解了一些东西,但目前我没有想法,希望得到您的意见。考虑以下测试:

# test passing an object
from dask import delayed, compute, get, set_options
# for testing the caching
from dask.base import normalize_token
from dask.cache import Cache

set_options(delayed_pure=True)


def test_object_hash():
cache_tmp = cache.Cache(1e9)
# test that object hashing is working
class Foo:
a = 1
b = 2

@normalize_token.register(Foo)
def tokenize_foo(self):
return normalize_token((self.a, self.b))

global_list = list()

def add(foo):
print("here")
global_list.append(1)
return foo.a + foo.b

# first, verify the hashes are the same
myobj = Foo()
first = delayed(add)(myobj)
myobj2 = Foo()
second = delayed(add)(myobj2)
assert first.key == second.key

# don't test with streams since it should be the same result
# this better highlights the problem
compute(first, get=get)
compute(second, get=get)
assert global_list == [1]

第一个断言语句通过,但第二个语句没有通过。我认为 dask 缓存了结果,以便使用相同 dask 键的计算仅计算一次。这段代码中是否缺少某些内容?请注意,这在 dask.distributed 中一直有效,因此这可能是 API 中的误解。

谢谢!

最佳答案

我回答了我自己的问题。我没有正确注册缓存。我必须添加以下行: 缓存.register()

如果有人对此有其他评论,我很高兴听到。谢谢。

关于python - Normalize_token 的意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46690961/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com