MCPcopy Create free account
hub / github.com/OpenBMB/AgentCPM-GUI / predict

Function predict

eval/run_predict_qwen2_5VL.py:397–497  ·  view source on GitHub ↗
(args, datasets)

Source from the content-addressed store, hash-verified

395 return (episode,image_path,history_list,use_low_instruction)
396
397def predict(args, datasets):
398 # set global variable
399 global USE_LOW_INSTRUCTION
400 USE_LOW_INSTRUCTION = (args.data_name == 'android_control_low_test')
401 data_dir = args.data_dir
402 split_type = args.split
403 print("Predicting on:",datasets)
404
405
406 if multiprocessing.get_start_method(allow_none=True) != "spawn":
407 multiprocessing.set_start_method("spawn", force=True)
408
409 with ProcessPoolExecutor(max_workers=len(DEVICES),initializer=_init_llm,initargs=(args.model_path,)) as poolexec:
410 tasks = []
411 print("Moving model to devices")
412 for device in DEVICES:
413 tasks.append(poolexec.submit(move_to, device))
414 for t in tasks:
415 print(t.result())
416
417 for dataset in datasets:
418 save_dir = os.path.join(args.output_dir, dataset)
419 if not os.path.exists(save_dir):
420 os.makedirs(save_dir)
421
422 episode_dir = os.path.join(data_dir, split_type, dataset)
423
424 # Use predict.jsonl file to store results (write line by line)
425 output_file = os.path.join(save_dir, "predict.jsonl")
426
427 # Get the list of all episodes files
428 if os.path.exists(episode_dir):
429 episodes_files = os.listdir(episode_dir)
430 else:
431 continue
432
433 future = []
434 all_tasks = []
435 print("Loading episodes")
436 with ThreadPoolExecutor(max_workers=16) as executor:
437 for episodes_file in episodes_files:
438
439 episodes_path = os.path.join(episode_dir, episodes_file, f"{episodes_file}.json")
440 try:
441 with open(episodes_path, 'r', encoding='utf-8') as f:
442 episodes = json.load(f)
443 except Exception as e:
444 print(f"Failed to load {episodes_path}: {e}")
445 continue
446 # Skip this file on error
447 for index,episode in enumerate(episodes):
448 episode_history = [] # Create a separate history for each episode
449 for prev_episode in episodes[:index]:
450 #for prev_episode in episodes[:episode['step_id']-1]: # Only get history before current step
451 image_path = os.path.join(episode_dir, episodes_file, f"{episodes_file}_{prev_episode['step_id']}.jpeg")
452 if not os.path.exists(image_path):
453 image_path = image_path.replace(".jpeg", ".png")
454 if not os.path.exists(image_path):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected