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