Views
No views yet
vllm_deploy.sh:vllm serve path-to-the-checkpoint --dtype auto --api-key token-abc123 --chat-template template.jinja1import os
2import re
3import json
4import time
5import random
6import argparse
7
8from decimal import Decimal
9from openai import OpenAI
10
11from utils import generate_random_cell, sample_new_cell
12
13# -----------------------------
14# Argument parser configuration
15# -----------------------------
16parser = argparse.ArgumentParser()
17parser.add_argument('--output_dir', type=str, default='history', help="Directory to save search results.")
18parser.add_argument('--chat_model', type=str, default='path-to-the-checkpoint', help="LLM model used for sampling new cells.")
19parser.add_argument('--trial_num', type=int, default=192, help="Number of search trials to run.")
20args = parser.parse_args()
21print(args)
22
23# -----------------------------
24# Define the search space here
25# (Customize according to your task)
26# -----------------------------
27search_space = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5] # Search space with 5^10 solutions
28
29performance_history = []
30trial_dict = {}
31
32# -----------------------------
33# Create output directory if it doesn’t exist
34# -----------------------------
35if not os.path.exists(args.output_dir):
36 os.makedirs(args.output_dir)
37
38num_iters = 0
39for iteration in range(num_iters, args.trial_num):
40 # Control number of previous trials referenced by the model
41 if iteration <= 200:
42 output_num = iteration
43 else:
44 output_num = 200
45
46 # First few trials are random
47 if iteration <= 4:
48 cell = generate_random_cell(search_space, trial_dict)
49 # Later trials sample based on history
50 else:
51 cell = sample_new_cell(trial_dict, output_num, args.chat_model)
52
53 # -----------------------------
54 # Here the "reward function" is defined.
55 # Replace this with your custom evaluation metric.
56 # -----------------------------
57 val_acc = random.uniform(0, 100)
58
59 # Record results for the current trial
60 trial_dict[f"Trial{iteration+1}"] = {}
61 trial_dict[f"Trial{iteration+1}"]["cell"] = cell
62 trial_dict[f"Trial{iteration+1}"]["prediction"] = val_acc
63
64 # Save all historical results to file
65 with open('{}/historical_results.json'.format(args.output_dir), 'w') as f:
66 json.dump(trial_dict, f)