From 8328327497f3de189934920ce93e3a0e6b0228d3 Mon Sep 17 00:00:00 2001 From: OwnerSunshine530 Date: Sun, 14 Jun 2026 21:47:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20bench=20=E7=BC=93=E5=AD=98=E6=94=B9?= =?UTF-8?q?=E7=94=A8=20pickle=EF=BC=88torch.load=20=E5=9C=A8=20overlay=20f?= =?UTF-8?q?s=20=E6=8A=A5=20Errno=2038=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 --- 代码/code/bench.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/代码/code/bench.py b/代码/code/bench.py index 6ac3c9d..950da96 100644 --- a/代码/code/bench.py +++ b/代码/code/bench.py @@ -105,17 +105,27 @@ def _load_filtered(history_dir, test_csv, test_users): def _get_data(cur, ref, rebuild=False): - """取过滤后的 (item_dict, user_seq),优先读磁盘缓存。""" - cache = cur / "bench_filtered_cache.pt" + """取过滤后的 (item_dict, user_seq),优先读磁盘缓存。 + + 用 pickle 而非 torch.save/load:AI Studio overlay 文件系统对 torch 的 + zip/mmap 读取会间歇性报 [Errno 38] Function not implemented。 + """ + import pickle + cache = cur / "bench_filtered_cache.pkl" test_csv = ref / "test.csv" history = ref / "history" if cache.exists() and not rebuild: print(f"[BENCH] 读取过滤缓存:{cache}") - d = torch.load(cache, weights_only=False) - return d["item_dict"], d["user_seq"] + try: + with open(cache, "rb") as f: + d = pickle.load(f) + return d["item_dict"], d["user_seq"] + except Exception as e: + print(f"[BENCH][WARN] 缓存读取失败({e}),重新构建") test_users = _test_user_ids(test_csv) item_dict, user_seq = _load_filtered(history, test_csv, test_users) - torch.save({"item_dict": item_dict, "user_seq": user_seq}, cache) + with open(cache, "wb") as f: + pickle.dump({"item_dict": item_dict, "user_seq": user_seq}, f, protocol=4) print(f"[BENCH] 已缓存 -> {cache}") return item_dict, user_seq