Skip to content

Commit df57c08

Browse files
authored
[Feature] Update Models, Summarizers (#1600)
1 parent d91d667 commit df57c08

11 files changed

+233
-58
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from opencompass.models import HuggingFacewithChatTemplate
2+
3+
models = [
4+
dict(
5+
type=HuggingFacewithChatTemplate,
6+
abbr='llama-3_2-3b-instruct-hf',
7+
path='meta-llama/Llama-3.2-3B-Instruct',
8+
max_out_len=1024,
9+
batch_size=8,
10+
run_cfg=dict(num_gpus=1),
11+
stop_words=['<|end_of_text|>', '<|eot_id|>'],
12+
)
13+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from opencompass.models import TurboMindModelwithChatTemplate
2+
3+
models = [
4+
dict(
5+
type=TurboMindModelwithChatTemplate,
6+
abbr='llama-3_2-3b-instruct-turbomind',
7+
path='meta-llama/Llama-3.2-3B-Instruct',
8+
engine_config=dict(max_batch_size=16, tp=1),
9+
gen_config=dict(top_k=1, temperature=1e-6, top_p=0.9, max_new_tokens=4096),
10+
max_seq_len=16384,
11+
max_out_len=4096,
12+
batch_size=16,
13+
run_cfg=dict(num_gpus=1),
14+
stop_words=['<|end_of_text|>', '<|eot_id|>'],
15+
)
16+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from opencompass.models import HuggingFacewithChatTemplate
2+
3+
models = [
4+
dict(
5+
type=HuggingFacewithChatTemplate,
6+
abbr='mistral-nemo-instruct-2407-hf',
7+
path='mistralai/Mistral-Nemo-Instruct-2407',
8+
max_out_len=1024,
9+
batch_size=8,
10+
run_cfg=dict(num_gpus=1),
11+
)
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from opencompass.models import HuggingFacewithChatTemplate
2+
3+
models = [
4+
dict(
5+
type=HuggingFacewithChatTemplate,
6+
abbr='mistral-small-instruct-2409-hf',
7+
path='mistralai/Mistral-Small-Instruct-2409',
8+
max_out_len=1024,
9+
batch_size=8,
10+
run_cfg=dict(num_gpus=2),
11+
)
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from opencompass.models import TurboMindModelwithChatTemplate
2+
3+
models = [
4+
dict(
5+
type=TurboMindModelwithChatTemplate,
6+
abbr='mistral-nemo-instruct-2407-turbomind',
7+
path='mistralai/Mistral-Nemo-Instruct-2407',
8+
engine_config=dict(session_len=32768, max_batch_size=16, tp=1),
9+
gen_config=dict(top_k=1, temperature=1e-6, top_p=0.9, max_new_tokens=4096),
10+
max_seq_len=32768,
11+
max_out_len=4096,
12+
batch_size=16,
13+
run_cfg=dict(num_gpus=1),
14+
)
15+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from opencompass.models import TurboMindModelwithChatTemplate
2+
3+
models = [
4+
dict(
5+
type=TurboMindModelwithChatTemplate,
6+
abbr="mistral-small-instruct-2409-turbomind",
7+
path="mistralai/Mistral-Small-Instruct-2409",
8+
engine_config=dict(session_len=32768, max_batch_size=16, tp=2),
9+
gen_config=dict(top_k=1, temperature=1e-6, top_p=0.9, max_new_tokens=4096),
10+
max_seq_len=32768,
11+
max_out_len=4096,
12+
batch_size=16,
13+
run_cfg=dict(num_gpus=2),
14+
)
15+
]

opencompass/datasets/compassbench_obj.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def load(path: str, name: str):
2626
circular_patterns = ['ABCD', 'BCDA', 'CDAB', 'DABC']
2727

2828
data = []
29-
with open(path, 'r') as infile:
29+
with open(path, 'r', encoding='utf-8', errors='ignore') as infile:
3030
for id, line in enumerate(infile):
3131
entry = json.loads(line)
3232
if 'cloze' in name:

opencompass/models/bailing_api_oc.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def __init__(
8181
self._headers = {'Authorization': f'Bearer {token}'}
8282

8383
self._headers['Content-Type'] = 'application/json'
84-
self._url = url if url else \
85-
'https://bailingchat.alipay.com/chat/completions'
84+
self._url = (url if url else
85+
'https://bailingchat.alipay.com/chat/completions')
8686
self._model = path
8787
self._sessions = []
8888
self._num = (int(os.environ.get('BAILING_API_PARALLEL_NUM'))
@@ -136,9 +136,9 @@ def generate(
136136
results.append('')
137137
else:
138138
if (result.get('choices')
139-
and result['choices'][0].get('message')
140-
and result['choices'][0]['message'].get(
141-
'content')):
139+
and result['choices'][0].get('message') and
140+
result['choices'][0]['message'].get('content')
141+
is not None):
142142
results.append(
143143
result['choices'][0]['message']['content'])
144144
else:

opencompass/models/openai_api.py

+47-19
Original file line numberDiff line numberDiff line change
@@ -466,25 +466,28 @@ def bin_trim(self, prompt: str, num_token: int) -> str:
466466

467467
class OpenAISDK(OpenAI):
468468

469-
def __init__(self,
470-
path: str = 'gpt-3.5-turbo',
471-
max_seq_len: int = 4096,
472-
query_per_second: int = 1,
473-
rpm_verbose: bool = False,
474-
retry: int = 2,
475-
key: str | List[str] = 'ENV',
476-
org: str | List[str] | None = None,
477-
meta_template: Dict | None = None,
478-
openai_api_base: str = OPENAI_API_BASE,
479-
openai_proxy_url: Optional[str] = None,
480-
mode: str = 'none',
481-
logprobs: bool | None = False,
482-
top_logprobs: int | None = None,
483-
temperature: float | None = None,
484-
tokenizer_path: str | None = None,
485-
extra_body: Dict | None = None,
486-
max_completion_tokens: int = 16384,
487-
verbose: bool = False):
469+
def __init__(
470+
self,
471+
path: str = 'gpt-3.5-turbo',
472+
max_seq_len: int = 4096,
473+
query_per_second: int = 1,
474+
rpm_verbose: bool = False,
475+
retry: int = 2,
476+
key: str | List[str] = 'ENV',
477+
org: str | List[str] | None = None,
478+
meta_template: Dict | None = None,
479+
openai_api_base: str = OPENAI_API_BASE,
480+
openai_proxy_url: Optional[str] = None,
481+
mode: str = 'none',
482+
logprobs: bool | None = False,
483+
top_logprobs: int | None = None,
484+
temperature: float | None = None,
485+
tokenizer_path: str | None = None,
486+
extra_body: Dict | None = None,
487+
max_completion_tokens: int = 16384,
488+
verbose: bool = False,
489+
status_code_mappings: dict = {},
490+
):
488491
super().__init__(path,
489492
max_seq_len,
490493
query_per_second,
@@ -519,9 +522,11 @@ def __init__(self,
519522
http_client=httpx.Client(proxies=proxies))
520523
if self.verbose:
521524
self.logger.info(f'Used openai_client: {self.openai_client}')
525+
self.status_code_mappings = status_code_mappings
522526

523527
def _generate(self, input: PromptList | str, max_out_len: int,
524528
temperature: float) -> str:
529+
from openai import BadRequestError
525530
assert isinstance(input, (str, PromptList))
526531

527532
# max num token for gpt-3.5-turbo is 4097
@@ -605,7 +610,30 @@ def _generate(self, input: PromptList | str, max_out_len: int,
605610
self.logger.info(responses)
606611
except Exception as e: # noqa F841
607612
pass
613+
if not responses.choices:
614+
self.logger.error(
615+
'Response is empty, it is an internal server error \
616+
from the API provider.')
608617
return responses.choices[0].message.content
618+
619+
except BadRequestError as e:
620+
# Handle BadRequest status
621+
# You can specify self.status_code_mappings to bypass \
622+
# API sensitivity blocks
623+
# For example: status_code_mappings={400: 'Input data \
624+
# may contain inappropriate content.'}
625+
status_code = e.status_code
626+
if (status_code is not None
627+
and status_code in self.status_code_mappings):
628+
original_error_message = e.body.get('message')
629+
error_message = self.status_code_mappings[status_code]
630+
self.logger.info(
631+
f'Status Code: {status_code}, '
632+
f'Original Error Message: {original_error_message},'
633+
f'Return Message: {error_message} ')
634+
return error_message
635+
else:
636+
self.logger.error(e)
609637
except Exception as e:
610638
self.logger.error(e)
611639
num_retries += 1

0 commit comments

Comments
 (0)