(args, datasets)
| 299 | return (episode,image_path,history_list,use_low_instruction) |
| 300 | |
| 301 | def predict(args, datasets): |
| 302 | # set global variable |
| 303 | global USE_LOW_INSTRUCTION |
| 304 | USE_LOW_INSTRUCTION = (args.data_name == 'android_control_low_test') |
| 305 | data_dir = args.data_dir |
| 306 | split_type = args.split |
| 307 | print("Predicting on:",datasets) |
| 308 | |
| 309 | |
| 310 | if multiprocessing.get_start_method(allow_none=True) != "spawn": |
| 311 | multiprocessing.set_start_method("spawn", force=True) |
| 312 | |
| 313 | with ProcessPoolExecutor(max_workers=len(DEVICES),initializer=_init_llm,initargs=(args.model_path,)) as poolexec: |
| 314 | tasks = [] |
| 315 | print("Moving model to devices") |
| 316 | for device in DEVICES: |
| 317 | tasks.append(poolexec.submit(move_to, device)) |
| 318 | for t in tasks: |
| 319 | print(t.result()) |
| 320 | |
| 321 | for dataset in datasets: |
| 322 | save_dir = os.path.join(args.output_dir, dataset) |
| 323 | if not os.path.exists(save_dir): |
| 324 | os.makedirs(save_dir) |
| 325 | |
| 326 | episode_dir = os.path.join(data_dir, split_type, dataset) |
| 327 | |
| 328 | # Use predict.jsonl file to store results (write line by line) |
| 329 | output_file = os.path.join(save_dir, "predict.jsonl") |
| 330 | |
| 331 | # Get the list of all episodes files |
| 332 | if os.path.exists(episode_dir): |
| 333 | episodes_files = os.listdir(episode_dir) |
| 334 | else: |
| 335 | continue |
| 336 | |
| 337 | future = [] |
| 338 | all_tasks = [] |
| 339 | print("Loading episodes") |
| 340 | with ThreadPoolExecutor(max_workers=16) as executor: |
| 341 | for episodes_file in episodes_files: |
| 342 | |
| 343 | episodes_path = os.path.join(episode_dir, episodes_file, f"{episodes_file}.json") |
| 344 | try: |
| 345 | with open(episodes_path, 'r', encoding='utf-8') as f: |
| 346 | episodes = json.load(f) |
| 347 | except Exception as e: |
| 348 | print(f"Failed to load {episodes_path}: {e}") |
| 349 | continue |
| 350 | # Skip this file on error |
| 351 | for index,episode in enumerate(episodes): |
| 352 | episode_history = [] # Create a separate history for each episode |
| 353 | for prev_episode in episodes[:index]: |
| 354 | #for prev_episode in episodes[:episode['step_id']-1]: # Only get history before current step |
| 355 | image_path = os.path.join(episode_dir, episodes_file, f"{episodes_file}_{prev_episode['step_id']}.jpeg") |
| 356 | if not os.path.exists(image_path): |
| 357 | image_path = image_path.replace(".jpeg", ".png") |
| 358 | if not os.path.exists(image_path): |
no outgoing calls
no test coverage detected