(args, datasets)
| 358 | |
| 359 | return (episode,image_path,history_list,use_low_instruction) |
| 360 | def predict(args, datasets): |
| 361 | # set global variable |
| 362 | global USE_LOW_INSTRUCTION |
| 363 | USE_LOW_INSTRUCTION = (args.data_name == 'android_control_low_test') |
| 364 | data_dir = args.data_dir |
| 365 | split_type = args.split |
| 366 | print("Predicting on:",datasets) |
| 367 | |
| 368 | |
| 369 | if multiprocessing.get_start_method(allow_none=True) != "spawn": |
| 370 | multiprocessing.set_start_method("spawn", force=True) |
| 371 | |
| 372 | with ProcessPoolExecutor(max_workers=len(DEVICES),initializer=_init_llm,initargs=(args.model_path,)) as poolexec: |
| 373 | tasks = [] |
| 374 | print("Moving model to devices") |
| 375 | for device in DEVICES: |
| 376 | tasks.append(poolexec.submit(move_to, device)) |
| 377 | for t in tasks: |
| 378 | print(t.result()) |
| 379 | |
| 380 | for dataset in datasets: |
| 381 | save_dir = os.path.join(args.output_dir, dataset) |
| 382 | if not os.path.exists(save_dir): |
| 383 | os.makedirs(save_dir) |
| 384 | |
| 385 | episode_dir = os.path.join(data_dir, split_type, dataset) |
| 386 | |
| 387 | # Use predict.jsonl file to store results (write line by line) |
| 388 | output_file = os.path.join(save_dir, "predict.jsonl") |
| 389 | |
| 390 | # Get the list of all episodes files |
| 391 | if os.path.exists(episode_dir): |
| 392 | episodes_files = os.listdir(episode_dir) |
| 393 | else: |
| 394 | continue |
| 395 | |
| 396 | future = [] |
| 397 | all_tasks = [] |
| 398 | print("Loading episodes") |
| 399 | with ThreadPoolExecutor(max_workers=16) as executor: |
| 400 | for episodes_file in episodes_files: |
| 401 | |
| 402 | episodes_path = os.path.join(episode_dir, episodes_file, f"{episodes_file}.json") |
| 403 | try: |
| 404 | with open(episodes_path, 'r', encoding='utf-8') as f: |
| 405 | episodes = json.load(f) |
| 406 | except Exception as e: |
| 407 | print(f"Failed to load {episodes_path}: {e}") |
| 408 | continue |
| 409 | # Skip this file on error |
| 410 | for index,episode in enumerate(episodes): |
| 411 | episode_history = [] # Create a separate history for each episode |
| 412 | for prev_episode in episodes[:index]: |
| 413 | #for prev_episode in episodes[:episode['step_id']-1]: # Only get history before current step |
| 414 | image_path = os.path.join(episode_dir, episodes_file, f"{episodes_file}_{prev_episode['step_id']}.jpeg") |
| 415 | if not os.path.exists(image_path): |
| 416 | image_path = image_path.replace(".jpeg", ".png") |
| 417 | if not os.path.exists(image_path): |
no outgoing calls
no test coverage detected