Fix small bugs in max time limit setting
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import os
|
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
from wrapt_timeout_decorator import *
|
from wrapt_timeout_decorator import *
|
||||||
|
|
||||||
logger = logging.getLogger("desktopenv.experiment")
|
logger = logging.getLogger("desktopenv.experiment")
|
||||||
|
|
||||||
# Open the JSON file
|
# Open the JSON file
|
||||||
@@ -11,6 +13,7 @@ with open("./settings.json", "r") as file:
|
|||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
time_limit = data["time_limit"]
|
time_limit = data["time_limit"]
|
||||||
|
|
||||||
|
|
||||||
@timeout(time_limit, use_signals=False)
|
@timeout(time_limit, use_signals=False)
|
||||||
def run_single_example(agent, env, example, max_steps, instruction, args, example_result_dir, scores):
|
def run_single_example(agent, env, example, max_steps, instruction, args, example_result_dir, scores):
|
||||||
agent.reset()
|
agent.reset()
|
||||||
@@ -37,7 +40,7 @@ def run_single_example(agent, env, example, max_steps, instruction, args, exampl
|
|||||||
|
|
||||||
# Save screenshot and trajectory information
|
# Save screenshot and trajectory information
|
||||||
with open(os.path.join(example_result_dir, f"step_{step_idx + 1}_{action_timestamp}.png"),
|
with open(os.path.join(example_result_dir, f"step_{step_idx + 1}_{action_timestamp}.png"),
|
||||||
"wb") as _f:
|
"wb") as _f:
|
||||||
with open(obs['screenshot'], "rb") as __f:
|
with open(obs['screenshot'], "rb") as __f:
|
||||||
screenshot = __f.read()
|
screenshot = __f.read()
|
||||||
_f.write(screenshot)
|
_f.write(screenshot)
|
||||||
|
|||||||
47
run.py
47
run.py
@@ -9,11 +9,11 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import time
|
|
||||||
|
|
||||||
|
import lib_run_single
|
||||||
from desktop_env.envs.desktop_env import DesktopEnv
|
from desktop_env.envs.desktop_env import DesktopEnv
|
||||||
from mm_agents.agent import PromptAgent
|
from mm_agents.agent import PromptAgent
|
||||||
import lib_run_single
|
|
||||||
# Logger Configs {{{ #
|
# Logger Configs {{{ #
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
@@ -48,6 +48,7 @@ logger.addHandler(sdebug_handler)
|
|||||||
|
|
||||||
logger = logging.getLogger("desktopenv.experiment")
|
logger = logging.getLogger("desktopenv.experiment")
|
||||||
|
|
||||||
|
|
||||||
def config() -> argparse.Namespace:
|
def config() -> argparse.Namespace:
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Run end-to-end evaluation on the benchmark"
|
description="Run end-to-end evaluation on the benchmark"
|
||||||
@@ -79,7 +80,6 @@ def config() -> argparse.Namespace:
|
|||||||
# agent config
|
# agent config
|
||||||
parser.add_argument("--max_trajectory_length", type=int, default=3)
|
parser.add_argument("--max_trajectory_length", type=int, default=3)
|
||||||
parser.add_argument("--test_config_base_dir", type=str, default="evaluation_examples")
|
parser.add_argument("--test_config_base_dir", type=str, default="evaluation_examples")
|
||||||
parser.add_argument("--example_time_limit", type=int, default=1200)
|
|
||||||
|
|
||||||
# lm config
|
# lm config
|
||||||
parser.add_argument("--model", type=str, default="gpt-4-vision-preview")
|
parser.add_argument("--model", type=str, default="gpt-4-vision-preview")
|
||||||
@@ -101,7 +101,6 @@ def test(
|
|||||||
) -> None:
|
) -> None:
|
||||||
scores = []
|
scores = []
|
||||||
max_steps = args.max_steps
|
max_steps = args.max_steps
|
||||||
time_limit = args.example_time_limit
|
|
||||||
|
|
||||||
# log args
|
# log args
|
||||||
logger.info("Args: %s", args)
|
logger.info("Args: %s", args)
|
||||||
@@ -146,7 +145,8 @@ def test(
|
|||||||
os.makedirs(example_result_dir, exist_ok=True)
|
os.makedirs(example_result_dir, exist_ok=True)
|
||||||
# example start running
|
# example start running
|
||||||
try:
|
try:
|
||||||
lib_run_single.run_single_example(agent, env, example, max_steps, instruction, args, example_result_dir, scores)
|
lib_run_single.run_single_example(agent, env, example, max_steps, instruction, args, example_result_dir,
|
||||||
|
scores)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
env.controller.end_recording(os.path.join(example_result_dir, "recording.mp4"))
|
env.controller.end_recording(os.path.join(example_result_dir, "recording.mp4"))
|
||||||
logger.error(f"Time limit exceeded in {domain}/{example_id}")
|
logger.error(f"Time limit exceeded in {domain}/{example_id}")
|
||||||
@@ -168,11 +168,10 @@ def get_unfinished(action_space, use_model, observation_type, result_dir, total_
|
|||||||
|
|
||||||
finished = {}
|
finished = {}
|
||||||
for domain in os.listdir(target_dir):
|
for domain in os.listdir(target_dir):
|
||||||
finished[domain] = []
|
|
||||||
finished[domain] = []
|
finished[domain] = []
|
||||||
domain_path = os.path.join(target_dir, domain)
|
domain_path = os.path.join(target_dir, domain)
|
||||||
if os.path.isdir(domain_path):
|
if os.path.isdir(domain_path):
|
||||||
for example_id in os.listdir(domain_path):
|
for example_id in os.listdir(domain_path):
|
||||||
example_path = os.path.join(domain_path, example_id)
|
example_path = os.path.join(domain_path, example_id)
|
||||||
if os.path.isdir(example_path):
|
if os.path.isdir(example_path):
|
||||||
if "result.txt" not in os.listdir(example_path):
|
if "result.txt" not in os.listdir(example_path):
|
||||||
@@ -192,6 +191,30 @@ def get_unfinished(action_space, use_model, observation_type, result_dir, total_
|
|||||||
return total_file_json
|
return total_file_json
|
||||||
|
|
||||||
|
|
||||||
|
def get_result(action_space, use_model, observation_type, result_dir, total_file_json):
|
||||||
|
target_dir = os.path.join(result_dir, action_space, observation_type, use_model)
|
||||||
|
|
||||||
|
all_result = []
|
||||||
|
|
||||||
|
if not os.path.exists(target_dir):
|
||||||
|
return total_file_json
|
||||||
|
|
||||||
|
finished = {}
|
||||||
|
for domain in os.listdir(target_dir):
|
||||||
|
finished[domain] = []
|
||||||
|
domain_path = os.path.join(target_dir, domain)
|
||||||
|
if os.path.isdir(domain_path):
|
||||||
|
for example_id in os.listdir(domain_path):
|
||||||
|
example_path = os.path.join(domain_path, example_id)
|
||||||
|
if os.path.isdir(example_path):
|
||||||
|
if "result.txt" in os.listdir(example_path):
|
||||||
|
# empty all files under example_id
|
||||||
|
all_result.append(float(open(os.path.join(example_path, "result.txt"), "r").read()))
|
||||||
|
|
||||||
|
print("Success Rate:", sum(all_result) / len(all_result) * 100, "%")
|
||||||
|
return all_result
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
####### The complete version of the list of examples #######
|
####### The complete version of the list of examples #######
|
||||||
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
||||||
@@ -211,4 +234,12 @@ if __name__ == '__main__':
|
|||||||
for domain in test_file_list:
|
for domain in test_file_list:
|
||||||
left_info += f"{domain}: {len(test_file_list[domain])}\n"
|
left_info += f"{domain}: {len(test_file_list[domain])}\n"
|
||||||
logger.info(f"Left tasks:\n{left_info}")
|
logger.info(f"Left tasks:\n{left_info}")
|
||||||
test(args, test_all_meta)
|
|
||||||
|
get_result(args.action_space,
|
||||||
|
args.model,
|
||||||
|
args.observation_type,
|
||||||
|
args.result_dir,
|
||||||
|
test_all_meta
|
||||||
|
)
|
||||||
|
|
||||||
|
# test(args, test_all_meta)
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"time_limit": "60"
|
"time_limit": "1200"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user