Skip to content

Commit

Permalink
llm_debug info(for show) using pickle instead of json
Browse files Browse the repository at this point in the history
  • Loading branch information
XianBW committed Dec 23, 2024
1 parent 61f0cb8 commit 6497957
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions rdagent/log/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import sys
import pickle
from contextlib import contextmanager
from datetime import datetime, timezone
from functools import partial
Expand Down Expand Up @@ -115,17 +116,17 @@ def log_object(self, obj: object, *, tag: str = "") -> None:
tag = f"{self._tag}.{tag}.{self.get_pids()}".strip(".")

if "debug_" in tag:
debug_log_path = self.log_trace_path / "debug_llm.json"
debug_log_path = self.log_trace_path / "debug_llm.pkl"
debug_data = {"tag": tag, "obj": obj}
if debug_log_path.exists():
with debug_log_path.open("r+", encoding="utf-8") as f:
existing_data = json.load(f)
with debug_log_path.open("rb+") as f:
existing_data = pickle.load(f)
existing_data.append(debug_data)
f.seek(0)
json.dump(existing_data, f, ensure_ascii=False, indent=4)
pickle.dump(existing_data, f)
else:
with debug_log_path.open("w", encoding="utf-8") as f:
json.dump([debug_data], f, ensure_ascii=False, indent=4)
with debug_log_path.open("wb") as f:
pickle.dump([debug_data], f)
return

logp = self.storage.log(obj, name=tag, save_type="pkl")
Expand Down
5 changes: 3 additions & 2 deletions rdagent/log/ui/llm_st.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import json
import pickle
import re
from pathlib import Path

Expand Down Expand Up @@ -30,8 +31,8 @@

def load_data():
try:
with open(f"{main_log_path}/{session_state.log_path}/debug_llm.json", "r") as f:
session_state.data = json.load(f)
with open(f"{main_log_path}/{session_state.log_path}/debug_llm.pkl", "r") as f:
session_state.data = pickle.load(f)
except Exception as e:
session_state.data = [{"error": str(e)}]

Expand Down

0 comments on commit 6497957

Please sign in to comment.