Skip to content

Commit 28b5cdb

Browse files
committed
update
1 parent 67d1c9d commit 28b5cdb

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

tools/llm_bench/task/pipeline_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from llm_bench_utils.memory_monitor import MemMonitorWrapper
88
from pathlib import Path
99
from typing import Any
10+
from abc import ABC, abstractmethod
1011

1112

1213
def execution_time_in_sec(func):
@@ -20,7 +21,7 @@ def time_wrapper(self, args, **kwargs):
2021
return time_wrapper
2122

2223

23-
class CommonPipeline:
24+
class CommonPipeline(ABC):
2425
DEFAULT_OUTPUT_TOKEN_SIZE = 512
2526

2627
def __init__(self, model, tokenizer, model_args: dict, model_path: Path, mem_consumption_meter: MemMonitorWrapper):
@@ -108,8 +109,9 @@ def print_generated(self, iter_num: int, generation_result: Any, prompt_idx: int
108109
generation_result (Any): Output of generation.
109110
prompt_idx (int): Number of the prompt being processed.
110111
"""
111-
pass
112+
raise NotImplementedError
112113

114+
@abstractmethod
113115
def gen_iterate_data(
114116
self,
115117
input_token_size: int,
@@ -143,6 +145,7 @@ def gen_iterate_data(
143145
"""
144146
return {}
145147

148+
@abstractmethod
146149
def postprocess_output_info(
147150
self,
148151
generation_result: Any,
@@ -184,6 +187,7 @@ def postprocess_output_info(
184187
"""
185188
return {}, []
186189

190+
@abstractmethod
187191
def run(self, input_text: str, iter_num: int, prompt_index: int, proc_id: int, bench_hook: object | None) -> tuple[dict, list]:
188192
"""Run pipeline.
189193

tools/llm_bench/task/text_reranker.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -388,21 +388,19 @@ def launch(pipeline: CommonPipeline, iter_num: int, prompt_idx: int, iter_timest
388388
def get_texts_from_file(args: dict) -> list:
389389
texts_list = []
390390
if args["rerank_texts_file"] is not None and args["rerank_texts"] is not None:
391-
log.warning("--texts and --texts_file are set, they are conflict options, it will be used texts from --texts_file")
391+
raise RuntimeError("== --texts and --texts_file are set together, they define lists of texts both, please choose one of them ==")
392392

393393
if args["rerank_texts_file"] is not None:
394394
for input_texts_file in args["rerank_texts_file"]:
395-
if input_texts_file.endswith(".jsonl"):
396-
if os.path.exists(input_texts_file):
397-
log.info(f"Read texts from {input_texts_file}")
398-
with open(input_texts_file, "r", encoding="utf-8") as f:
399-
for line in f:
400-
data = json.loads(line)
401-
texts_list.append(data["text"])
402-
else:
403-
raise RuntimeError(f"== The texts file:{input_texts_file} does not exist ==")
404-
else:
395+
if not input_texts_file.endswith(".jsonl"):
405396
raise RuntimeError(f"== The texts file:{input_texts_file} should be ended with .jsonl ==")
397+
if not os.path.exists(input_texts_file):
398+
raise RuntimeError(f"== The texts file:{input_texts_file} does not exist ==")
399+
log.info(f"Read texts from {input_texts_file}")
400+
with open(input_texts_file, "r", encoding="utf-8") as f:
401+
for line in f:
402+
data = json.loads(line)
403+
texts_list.append(data["text"])
406404
else:
407405
if args["rerank_texts"] is not None:
408406
texts_list = args["rerank_texts"]

0 commit comments

Comments
 (0)