Skip to content

Commit 5b337dd

Browse files
[Automated Commit] Format Codebase
1 parent 5d925c7 commit 5b337dd

File tree

6 files changed

+137
-84
lines changed

6 files changed

+137
-84
lines changed

language/qwen2.5-VL-7B-docker/SUT_VLLM.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
PORT = int(os.environ.get("VLLM_PORT", "8000"))
2424
BASE_URL = f"http://{HOST}:{PORT}/v1"
2525

26+
2627
class SUT:
2728
def __init__(
2829
self,
@@ -64,7 +65,7 @@ def __init__(
6465
"temperature": 0.0,
6566
"max_tokens": 1024,
6667
}
67-
68+
6869
if scenario == "offline":
6970
from vllm import SamplingParams
7071
from transformers import AutoProcessor
@@ -109,23 +110,23 @@ def process_queries(self):
109110
prompts = []
110111
for item in qitems:
111112
question = self.data_object.prompts[item.index]
112-
113-
placeholders = [{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{b64img}"}} for b64img in self.data_object.images[item.index]]
113+
114+
placeholders = [{"type": "image_url", "image_url": {
115+
"url": f"data:image/png;base64,{b64img}"}} for b64img in self.data_object.images[item.index]]
114116
messages = [
115117
{"role": "system", "content": "You are a helpful assistant."},
116-
{"role": "user", "content": [*placeholders, {"type": "text", "text": question}]},
118+
{"role": "user", "content": [
119+
*placeholders, {"type": "text", "text": question}]},
117120
]
118-
121+
119122
prompt = self.processor.apply_chat_template(
120123
messages, tokenize=False, add_generation_prompt=True
121124
)
122125
prompts.append({
123126
"prompt": prompt,
124127
"multi_modal_data": {"image": self.data_object.images[item.index]}
125128
})
126-
127-
128-
129+
129130
tik2 = time.time()
130131
outputs = self.model.generate(
131132
prompts=prompts, sampling_params=self.sampling_params
@@ -168,10 +169,10 @@ def load_model(self):
168169
from vllm import LLM
169170
log.info("Loading model...")
170171
self.model = LLM(
171-
self.model_path,
172-
dtype=self.dtype,
173-
tensor_parallel_size=self.tensor_parallel_size,
174-
)
172+
self.model_path,
173+
dtype=self.dtype,
174+
tensor_parallel_size=self.tensor_parallel_size,
175+
)
175176
log.info("Loaded model")
176177

177178
def get_sut(self):
@@ -199,7 +200,6 @@ def issue_queries(self, query_samples):
199200
def flush_queries(self):
200201
pass
201202

202-
203203
def __del__(self):
204204
pass
205205

@@ -231,11 +231,9 @@ def __init__(
231231
api_key="EMPTY"
232232
)
233233

234-
235234
def start(self):
236235
pass
237236

238-
239237
async def _issue_one(
240238
self,
241239
sample: Dict[str, Any],
@@ -244,7 +242,8 @@ async def _issue_one(
244242
log.info("CALLED _issue_one")
245243
"""Send one streaming chat.completion request and record timings."""
246244

247-
contents = [{"type": "text", "text": self.data_object.prompts[sample.index]}]
245+
contents = [
246+
{"type": "text", "text": self.data_object.prompts[sample.index]}]
248247
for img_b64 in self.data_object.images[sample.index]:
249248
contents.append({
250249
"type": "image_url",
@@ -274,32 +273,40 @@ async def _issue_one(
274273
text = getattr(delta, "content", None)
275274
if text:
276275
if ttft_set is False:
277-
text_int32 = np.array([ord(c) for c in text], dtype=np.int32)
276+
text_int32 = np.array([ord(c)
277+
for c in text], dtype=np.int32)
278278
response_data = array.array("B", text_int32.tobytes())
279279
bi = response_data.buffer_info()
280-
response = [lg.QuerySampleResponse(sample.id, bi[0], bi[1])]
280+
response = [
281+
lg.QuerySampleResponse(
282+
sample.id, bi[0], bi[1])]
281283
lg.FirstTokenComplete(response)
282284
ttft_set = True
283285
out.append(text)
284286

285-
# when the stream ends, total latency
287+
# when the stream ends, total latency
286288
final_tokens = "".join(out)
287-
final_tokens_int32 = np.array([ord(c) for c in final_tokens], dtype=np.int32)
289+
final_tokens_int32 = np.array(
290+
[ord(c) for c in final_tokens], dtype=np.int32)
288291
n_tokens = len(final_tokens_int32)
289292
response_array = array.array("B", final_tokens_int32.tobytes())
290293
bi = response_array.buffer_info()
291-
response = [lg.QuerySampleResponse(sample.id, bi[0], bi[1], n_tokens)]
294+
response = [
295+
lg.QuerySampleResponse(
296+
sample.id,
297+
bi[0],
298+
bi[1],
299+
n_tokens)]
292300
lg.QuerySamplesComplete(response)
293301

294-
295302
async def _issue_queries_async(self, query_samples):
296303
"""Async internal version used by the sync wrapper."""
297-
log.info(f"CALLED _issue_queries_async, num workers: {self.num_workers}")
304+
log.info(
305+
f"CALLED _issue_queries_async, num workers: {self.num_workers}")
298306
semaphore = asyncio.Semaphore(self.num_workers)
299307
tasks = [self._issue_one(s, semaphore) for s in query_samples]
300308
return await asyncio.gather(*tasks)
301309

302-
303310
def issue_queries(self, query_samples):
304311
try:
305312
loop = asyncio.get_running_loop()
@@ -314,4 +321,4 @@ def issue_queries(self, query_samples):
314321
asyncio.run(self._issue_queries_async(query_samples))
315322

316323
def stop(self):
317-
pass
324+
pass

language/qwen2.5-VL-7B-docker/generate_total_val_output.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
filepath = Path(os.getcwd(), "./output/mlperf_log_accuracy.json")
1818
target_path = Path(os.getcwd(), "./datasets/mmmu_data.json")
1919

20+
2021
def main(mode: str):
2122
with open(filepath, "r") as f:
2223
data = json.load(f)
@@ -26,11 +27,18 @@ def main(mode: str):
2627
ids = target.ids
2728
store_data = dict()
2829

29-
decoded_output = [np.frombuffer(bytes.fromhex(sorted_list[i]["data"]), np.int32) for i in range(len(sorted_list))]
30+
decoded_output = [
31+
np.frombuffer(
32+
bytes.fromhex(
33+
sorted_list[i]["data"]),
34+
np.int32) for i in range(
35+
len(sorted_list))]
3036
if mode == "offline":
31-
text_outputs = processor.batch_decode(decoded_output, skip_special_tokens=True)
37+
text_outputs = processor.batch_decode(
38+
decoded_output, skip_special_tokens=True)
3239
else:
33-
text_outputs = ["".join(chr(j) for j in text_integers) for text_integers in decoded_output]
40+
text_outputs = ["".join(chr(j) for j in text_integers)
41+
for text_integers in decoded_output]
3442
for i in range(len(sorted_list)):
3543
pred_txt = text_outputs[i]
3644
qsl_idx = sorted_list[i]["qsl_idx"]
@@ -42,6 +50,7 @@ def main(mode: str):
4250
with open("total_val_output.json", "w") as f:
4351
json.dump(store_data, f, indent=4)
4452

53+
4554
if __name__ == "__main__":
4655
parser = argparse.ArgumentParser()
4756
parser.add_argument("--mode", type=str, default="offline")

language/qwen2.5-VL-7B-docker/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ def main():
169169

170170
sut_cls = sut_map[args.scenario.lower()]
171171

172-
173172
sut = sut_cls(
174173
model_path=args.model_path,
175174
dtype=args.dtype,
@@ -180,7 +179,6 @@ def main():
180179
tensor_parallel_size=args.tensor_parallel_size,
181180
scenario=args.scenario.lower()
182181
)
183-
184182

185183
# Start sut before loadgen starts
186184
sut.start()

language/qwen2.5-VL-7B-docker/main_eval_only.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
"""Parse and Evaluate"""
2+
from utils.eval_utils import evaluate, parse_open_response, calculate_ins_level_acc
3+
from utils.data_utils import CAT_SHORT2LONG, DOMAIN_CAT2SUB_CAT
24
import os
35
import json
46
import sys
57
from argparse import ArgumentParser
68
sys.path.insert(0, os.getcwd())
7-
from utils.data_utils import CAT_SHORT2LONG, DOMAIN_CAT2SUB_CAT
8-
from utils.eval_utils import evaluate, parse_open_response, calculate_ins_level_acc
99

1010

1111
if __name__ == '__main__':
1212

1313
parser = ArgumentParser()
14-
parser.add_argument('--output_path', type=str, default="./example_outputs/qwen_vl/total_val_output.json", help="The path to model output file.")
15-
parser.add_argument('--answer_path', type=str, default="./answer_dict_val.json", help="Answer file path.")
14+
parser.add_argument(
15+
'--output_path',
16+
type=str,
17+
default="./example_outputs/qwen_vl/total_val_output.json",
18+
help="The path to model output file.")
19+
parser.add_argument(
20+
'--answer_path',
21+
type=str,
22+
default="./answer_dict_val.json",
23+
help="Answer file path.")
1624
args = parser.parse_args()
1725

1826
output_dict = json.load(open(args.output_path))
@@ -45,12 +53,13 @@
4553
except KeyError:
4654
print("Skipping {} for not found".format(category))
4755
continue
48-
56+
4957
exampels_to_eval = []
5058
for data_id, parsed_pred in cat_outputs.items():
5159
question_type = cat_answers[data_id]['question_type']
5260
if question_type != 'multiple-choice':
53-
parsed_pred = parse_open_response(parsed_pred) # mainly for type consistency (make it number, etc.)
61+
# mainly for type consistency (make it number, etc.)
62+
parsed_pred = parse_open_response(parsed_pred)
5463
else:
5564
parsed_pred = parsed_pred
5665

@@ -71,13 +80,14 @@
7180
# add domain Subject
7281
for domain, in_domain_cats in DOMAIN_CAT2SUB_CAT.items():
7382
in_domain_cat_results = {}
74-
for cat_name in in_domain_cats: # use the order in DOMAIN_CAT2SUB_CAT
83+
for cat_name in in_domain_cats: # use the order in DOMAIN_CAT2SUB_CAT
7584
if cat_name in evaluation_result.keys():
7685
in_domain_cat_results[cat_name] = evaluation_result[cat_name]
7786
else:
7887
pass
7988
in_domain_ins_acc = calculate_ins_level_acc(in_domain_cat_results)
80-
in_domain_data_num = sum([cat_results['num_example'] for cat_results in in_domain_cat_results.values()])
89+
in_domain_data_num = sum([cat_results['num_example']
90+
for cat_results in in_domain_cat_results.values()])
8191
printable_results['Overall-' + domain] = {"num": int(in_domain_data_num),
8292
"acc": round(in_domain_ins_acc, 3)
8393
}
@@ -86,7 +96,7 @@
8696
printable_results[cat_name] = {"num": int(cat_results['num_example']),
8797
"acc": round(cat_results['acc'], 3)
8898
}
89-
99+
90100
# table.append(["-----------------------------", "-----", "----"])
91101
all_ins_acc = calculate_ins_level_acc(evaluation_result)
92102
printable_results['Overall'] = {"num": sum([cat_results['num_example'] for cat_results in evaluation_result.values()]),
@@ -95,4 +105,4 @@
95105

96106
# print(printable_results)
97107
with open("evaluation_results.json", "w") as f:
98-
json.dump(printable_results, f, indent=4)
108+
json.dump(printable_results, f, indent=4)

0 commit comments

Comments
 (0)