Commit
·
78bb3c5
1
Parent(s):
f37e0e8
Add usage
Browse files- README.md +35 -0
- do_request.py +55 -0
README.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
+
|
5 |
+
## Usage
|
6 |
+
|
7 |
+
We use FastChat and vllm worker to host the model. Run these following commands in seperate terminals, such as `tmux`.
|
8 |
+
|
9 |
+
```shell
|
10 |
+
LOGDIR="" python3 -m fastchat.serve.openai_api_server \
|
11 |
+
--host 0.0.0.0 --port 8080 \
|
12 |
+
--controller-address http://localhost:21000
|
13 |
+
|
14 |
+
LOGDIR="" python3 -m fastchat.serve.controller \
|
15 |
+
--host 0.0.0.0 --port 21000
|
16 |
+
|
17 |
+
LOGDIR="" RAY_LOG_TO_STDERR=1 \
|
18 |
+
python3 -m fastchat.serve.vllm_worker \
|
19 |
+
--model-path ./VirtualCompiler \
|
20 |
+
--num-gpus 8 \
|
21 |
+
--controller http://localhost:21000 \
|
22 |
+
--max-num-batched-tokens 40960 \
|
23 |
+
--disable-log-requests \
|
24 |
+
--host 0.0.0.0 --port 22000 \
|
25 |
+
--worker-address http://localhost:22000 \
|
26 |
+
--model-names "VirtualCompiler"
|
27 |
+
```
|
28 |
+
|
29 |
+
Then with the model hosted, use `do_request.py` to make request to the model.
|
30 |
+
|
31 |
+
```shell
|
32 |
+
~/C/VirtualCompiler (main)> python3 do_request.py
|
33 |
+
test rdx, rdx
|
34 |
+
setz al
|
35 |
+
movzx eax, al
|
36 |
+
neg eax
|
37 |
+
retn
|
38 |
+
```
|
do_request.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import random
|
3 |
+
|
4 |
+
CL = ['clang-11', 'clang-12', 'clang-9', 'gcc-11', 'gcc-7', 'gcc-9']
|
5 |
+
OP = ['O0', 'O1', 'O2', 'O3', 'Os']
|
6 |
+
ST = ['stripped', 'unstripped']
|
7 |
+
|
8 |
+
|
9 |
+
def process(source_code):
|
10 |
+
compiler = random.choice(CL)
|
11 |
+
optimizer = random.choice(OP)
|
12 |
+
strip_type = random.choice(ST)
|
13 |
+
prompt = f'Please compile this source code using {compiler} with optimization level {optimizer} into assembly code.'
|
14 |
+
if strip_type == 'stripped':
|
15 |
+
prompt += ' Strip the assembly code.'
|
16 |
+
else:
|
17 |
+
prompt += ' No strip the assembly code.'
|
18 |
+
query_prompt = "<s>system\n" + prompt + \
|
19 |
+
"</s>\n<s>user\n" + source_code + "</s>\n<s>assistant\n"
|
20 |
+
return query_prompt, compiler, optimizer, strip_type
|
21 |
+
|
22 |
+
|
23 |
+
def do_request(src):
|
24 |
+
url = "http://localhost:8080/v1/completions"
|
25 |
+
|
26 |
+
query_prompt, _, _, _ = process(src)
|
27 |
+
|
28 |
+
model_name = "VirtualCompiler"
|
29 |
+
|
30 |
+
ret = requests.post(url, json={
|
31 |
+
"prompt": query_prompt,
|
32 |
+
"max_tokens": 4096,
|
33 |
+
"temperature": 0.3,
|
34 |
+
"stop": ["</s>"],
|
35 |
+
"model": model_name,
|
36 |
+
"echo": False,
|
37 |
+
"logprobs": True,
|
38 |
+
})
|
39 |
+
|
40 |
+
return ret.json()
|
41 |
+
|
42 |
+
|
43 |
+
src = '''static int
|
44 |
+
layout_append(struct layout_cell *lc, char *buf, size_t len)
|
45 |
+
{
|
46 |
+
if (len == 0)
|
47 |
+
return (-1);
|
48 |
+
|
49 |
+
return (0);
|
50 |
+
}
|
51 |
+
'''
|
52 |
+
|
53 |
+
ret = do_request(src)
|
54 |
+
|
55 |
+
print(ret['choices'][0]['text'])
|