Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions benchmarks/convomem_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ def download_evidence_file(category, subpath, cache_dir):
os.makedirs(os.path.dirname(cache_path), exist_ok=True)

if os.path.exists(cache_path):
with open(cache_path) as f:
with open(cache_path, encoding="utf-8") as f:
return json.load(f)

print(f" Downloading: {category}/{subpath}...")
try:
urllib.request.urlretrieve(url, cache_path)
with open(cache_path) as f:
with open(cache_path, encoding="utf-8") as f:
return json.load(f)
except Exception as e:
print(f" Failed to download {url}: {e}")
Expand All @@ -89,7 +89,7 @@ def discover_files(category, cache_dir):
cache_path = os.path.join(cache_dir, f"{category}_filelist.json")

if os.path.exists(cache_path):
with open(cache_path) as f:
with open(cache_path, encoding="utf-8") as f:
return json.load(f)

try:
Expand All @@ -100,7 +100,7 @@ def discover_files(category, cache_dir):
f["path"].split(f"{category}/")[1] for f in files if f["path"].endswith(".json")
]
os.makedirs(os.path.dirname(cache_path), exist_ok=True)
with open(cache_path, "w") as f:
with open(cache_path, "w", encoding="utf-8") as f:
json.dump(paths, f)
return paths
except Exception as e:
Expand Down Expand Up @@ -236,13 +236,13 @@ def run_benchmark(categories, limit_per_cat, top_k, mode, cache_dir, out_file):
print(f" Limit/cat: {limit_per_cat}")
print(f" Top-k: {top_k}")
print(f" Mode: {mode}")
print(f"{'' * 60}")
print(f"{'-' * 60}")
print("\n Loading data from HuggingFace...\n")

items = load_evidence_items(categories, limit_per_cat, cache_dir)

print(f"\n Total items: {len(items)}")
print(f"{'' * 60}\n")
print(f"{'-' * 60}\n")

all_recall = []
per_category = defaultdict(list)
Expand Down Expand Up @@ -302,7 +302,7 @@ def run_benchmark(categories, limit_per_cat, top_k, mode, cache_dir, out_file):
print(f"\n{'=' * 60}\n")

if out_file:
with open(out_file, "w") as f:
with open(out_file, "w", encoding="utf-8") as f:
json.dump(results_log, f, indent=2)
print(f" Results saved to: {out_file}")

Expand Down
12 changes: 6 additions & 6 deletions benchmarks/locomo_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def run_benchmark(
llm_base_url="",
):
"""Run LoCoMo retrieval benchmark."""
with open(data_file) as f:
with open(data_file, encoding="utf-8") as f:
data = json.load(f)

if limit > 0:
Expand All @@ -661,7 +661,7 @@ def run_benchmark(
Path(__file__).parent / "palace_cache_locomo.json"
)
if Path(_palace_cache_path).exists():
with open(_palace_cache_path) as f:
with open(_palace_cache_path, encoding="utf-8") as f:
palace_cache = json.load(f)
print(f" Palace cache: {len(palace_cache)} room assignments loaded")

Expand All @@ -675,7 +675,7 @@ def run_benchmark(
print(f" Top-k: {top_k}")
print(f" Mode: {mode}{rerank_label}")
print(f" Granularity: {granularity}")
print(f"{'' * 60}\n")
print(f"{'-' * 60}\n")

all_recall = []
per_category = defaultdict(list)
Expand Down Expand Up @@ -703,14 +703,14 @@ def run_benchmark(
)
# Persist updated cache after each conversation
if _palace_cache_path:
with open(_palace_cache_path, "w") as f:
with open(_palace_cache_path, "w", encoding="utf-8") as f:
json.dump(palace_cache, f, indent=2)
rooms_summary = {}
for sid, room in room_assignments.items():
rooms_summary[room] = rooms_summary.get(room, 0) + 1
print(
f" [{conv_idx + 1}/{len(data)}] {sample_id}: "
f"{len(sessions)} sessions {len(rooms_summary)} rooms, {len(qa_pairs)} questions"
f"{len(sessions)} sessions -> {len(rooms_summary)} rooms, {len(qa_pairs)} questions"
)
print(f" Rooms: {dict(sorted(rooms_summary.items(), key=lambda x: -x[1]))}")
else:
Expand Down Expand Up @@ -977,7 +977,7 @@ def run_benchmark(
print(f"\n{'=' * 60}\n")

if out_file:
with open(out_file, "w") as f:
with open(out_file, "w", encoding="utf-8") as f:
json.dump(results_log, f, indent=2)
print(f" Results saved to: {out_file}")

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/membench_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def load_membench(data_dir: str, categories=None, topic="movie", limit=0):
fpath = data_dir / fname
if not fpath.exists():
continue
with open(fpath) as f:
with open(fpath, encoding="utf-8") as f:
raw = json.load(f)

# Files have two formats:
Expand Down Expand Up @@ -321,7 +321,7 @@ def run_membench(
print(f" Items: {len(items)}")
print(f" Top-k: {top_k}")
print(f" Mode: {mode}")
print(f"{'' * 58}\n")
print(f"{'-' * 58}\n")

results = []
by_cat = defaultdict(lambda: {"hit_at_k": 0, "total": 0})
Expand Down Expand Up @@ -419,7 +419,7 @@ def run_membench(
print(f"\n{'=' * 58}\n")

if out_file:
with open(out_file, "w") as f:
with open(out_file, "w", encoding="utf-8") as f:
json.dump(results, f, indent=2)
print(f" Results saved to: {out_file}")

Expand Down
Loading