Ashenone3 commited on
Commit
31d41d7
·
verified ·
1 Parent(s): cbd9d3e

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +102 -0
README.md ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - Ashenone3/LM-Searcher-Trajectory-228K
5
+ language:
6
+ - en
7
+ metrics:
8
+ - accuracy
9
+ base_model:
10
+ - meta-llama/Llama-3.1-8B
11
+ pipeline_tag: text-generation
12
+ tags:
13
+ - nas
14
+ - optimization
15
+ - agent
16
+ ---
17
+ # LM-Searcher: Cross-domain Neural Architecture Search with LLMs via Unified Numerical Encoding
18
+
19
+ Repo: [https://github.com/Ashone3/LM-Searcher](https://github.com/Ashone3/LM-Searcher)
20
+
21
+ ## Introduction
22
+ We introduce LM-Searcher, a task-agnostic neural architecture search framework powered by LLMs.
23
+
24
+ ## Usage
25
+
26
+ ### Deployment
27
+ We use [vllm](https://github.com/vllm-project/vllm) to deploy our LM-Searcher for inference.
28
+ After installing the dependencies required by vllm. You can deploy the model using `vllm_deploy.sh`:
29
+ ```shell
30
+ vllm serve path-to-the-checkpoint --dtype auto --api-key token-abc123 --chat-template template.jinja
31
+ ```
32
+
33
+ ### Inference
34
+ An example is provided to show how LM-Searcher can be used to search for the optimal solution to a given problem:
35
+ ```python
36
+ import os
37
+ import re
38
+ import json
39
+ import time
40
+ import random
41
+ import argparse
42
+
43
+ from decimal import Decimal
44
+ from openai import OpenAI
45
+
46
+ from utils import generate_random_cell, sample_new_cell
47
+
48
+ # -----------------------------
49
+ # Argument parser configuration
50
+ # -----------------------------
51
+ parser = argparse.ArgumentParser()
52
+ parser.add_argument('--output_dir', type=str, default='history', help="Directory to save search results.")
53
+ parser.add_argument('--chat_model', type=str, default='path-to-the-checkpoint', help="LLM model used for sampling new cells.")
54
+ parser.add_argument('--trial_num', type=int, default=192, help="Number of search trials to run.")
55
+ args = parser.parse_args()
56
+ print(args)
57
+
58
+ # -----------------------------
59
+ # Define the search space here
60
+ # (Customize according to your task)
61
+ # -----------------------------
62
+ search_space = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5] # Search space with 5^10 solutions
63
+
64
+ performance_history = []
65
+ trial_dict = {}
66
+
67
+ # -----------------------------
68
+ # Create output directory if it doesn’t exist
69
+ # -----------------------------
70
+ if not os.path.exists(args.output_dir):
71
+ os.makedirs(args.output_dir)
72
+
73
+ num_iters = 0
74
+ for iteration in range(num_iters, args.trial_num):
75
+ # Control number of previous trials referenced by the model
76
+ if iteration <= 200:
77
+ output_num = iteration
78
+ else:
79
+ output_num = 200
80
+
81
+ # First few trials are random
82
+ if iteration <= 4:
83
+ cell = generate_random_cell(search_space, trial_dict)
84
+ # Later trials sample based on history
85
+ else:
86
+ cell = sample_new_cell(trial_dict, output_num, args.chat_model)
87
+
88
+ # -----------------------------
89
+ # Here the "reward function" is defined.
90
+ # Replace this with your custom evaluation metric.
91
+ # -----------------------------
92
+ val_acc = random.uniform(0, 100)
93
+
94
+ # Record results for the current trial
95
+ trial_dict[f"Trial{iteration+1}"] = {}
96
+ trial_dict[f"Trial{iteration+1}"]["cell"] = cell
97
+ trial_dict[f"Trial{iteration+1}"]["prediction"] = val_acc
98
+
99
+ # Save all historical results to file
100
+ with open('{}/historical_results.json'.format(args.output_dir), 'w') as f:
101
+ json.dump(trial_dict, f)
102
+ ```