Views
No views yet

ollama run nxphi47/seallm-7b-v2:q4_0Terms of Use and License: By using our released weights, codes, and demos, you agree to and comply with the terms and conditions specified in our SeaLLMs Terms Of Use.
Disclaimer: We must note that even though the weights, codes, and demos are released in an open manner, similar to other pre-trained language models, and despite our best efforts in red teaming and safety fine-tuning and enforcement, our models come with potential risks, including but not limited to inaccurate, misleading or potentially harmful generation. Developers and stakeholders should perform their own red teaming and provide related security measures before deployment, and they must abide by and comply with local governance and regulations. In no event shall the authors be held liable for any claim, damages, or other liability arising from the use of the released weights, codes, or demos.
The logo was generated by DALL-E 3.

| Model | GSM8K en | MATH en | GSM8K zh | MATH zh | GSM8K vi | MATH vi | GSM8K id | MATH id | GSM8K th | MATH th |
|---|---|---|---|---|---|---|---|---|---|---|
| GPT-3.5 | 80.8 | 34.1 | 48.2 | 21.5 | 55 | 26.5 | 64.3 | 26.4 | 35.8 | 18.1 |
| Qwen-14B-chat | 61.4 | 18.4 | 41.6 | 11.8 | 33.6 | 3.6 | 44.7 | 8.6 | 22 | 6 |
| Vistral-7b-chat | 48.2 | 12.5 | 48.7 | 3.1 | ||||||
| Qwen1.5-7B-chat | 56.8 | 15.3 | 40 | 2.7 | 37.7 | 9 | 36.9 | 7.7 | 21.9 | |
| SeaLLM-7B-v2 | 78.2 | 27.5 | 53.7 | 17.6 | 69.9 | 23.8 | 71.5 | 24.4 | 59.6 | 22.4 |
| Model | MGSM-Zh | MGSM-Th |
|---|---|---|
| ChatGPT (reported) | 61.2 | 47.2 |
| Qwen-14B-chat | 59.6 | 28 |
| SeaLLM-7B-v2 | 64.8 | 62.4 |
| 0-shot reasoning | Arc-Challenge | Winogrande | Hellaswag |
|---|---|---|---|
| ChatGPT (reported) | 84.6* | 66.8* | 72.0* |
| ChatGPT (reproduced) | 84.1 | 63.1 | 79.5 |
| Mistral-7B-Instruct | 68.1 | 56.4 | 45.6 |
| Qwen1.5-7B-chat | 79.3 | 59.4 | 69.3 |
| SeaLLM-7B-v2 | 82.5 | 68.3 | 80.9 |
| Model | Langs | En MMLU | En M3e | Zh M3e | Vi M3e | Vi VMLU | Id M3e | Th M3e |
|---|---|---|---|---|---|---|---|---|
| GPT-3.5 | Multi | 68.90 | 75.46 | 60.20 | 58.64 | 46.32 | 49.27 | 37.41 |
| Vistral-7B-chat | Mono | 56.86 | 67.00 | 44.56 | 54.33 | 50.03 | 36.49 | 25.27 |
| Qwen1.5-7B-chat | Multi | 61.00 | 52.07 | 81.96 | 43.38 | 45.02 | 24.29 | 20.25 |
| SeaLLM-7B-v2 | Multi | 61.89 | 70.91 | 55.43 | 51.15 | 45.74 | 42.25 | 35.52 |
| Model | Access | Langs | MT-Bench |
|---|---|---|---|
| GPT-4-turbo | closed | multi | 9.32 |
| GPT-4-0613 | closed | multi | 9.18 |
| Mixtral-8x7b (46B) | open | multi | 8.3 |
| Starling-LM-7B-alpha | open | mono (en) | 8.0 |
| OpenChat-3.5-7B | open | mono (en) | 7.81 |
| SeaLLM-7B-v2 | open | multi (10+) | 7.54 |
| Qwen-14B | open | multi | 6.96 |
| Llama-2-70B | open | mono (en) | 6.86 |
| Mistral-7B-instuct | open | mono (en) | 6.84 |

1prompt = """<|im_start|>system
2You are a helpful assistant.</s><|im_start|>user
3Hello world</s><|im_start|>assistant
4Hi there, how can I help?</s>"""
5
6# NOTE: previous commit has \n between </s> and <|im_start|>, that was incorrect!
7# <|im_start|> is not a special token.
8# Transformers chat_template should be consistent with vLLM format below.
9
10# ! ENSURE 1 and only 1 bos `<s>` at the beginning of sequence
11print(tokenizer.convert_ids_to_tokens(tokenizer.encode(prompt)))
12
13'<s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'system', '<0x0A>', 'You', '▁are', '▁a', '▁helpful', '▁assistant', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Hello', '▁world', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Hi', '▁there', ',', '▁how', '▁can', '▁I', '▁help', '?', '</s>']
14"""1
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4device = "cuda" # the device to load the model onto
5
6# use bfloat16 to ensure the best performance.
7model = AutoModelForCausalLM.from_pretrained("SeaLLMs/SeaLLM-7B-v2", torch_dtype=torch.bfloat16, device_map=device)
8tokenizer = AutoTokenizer.from_pretrained("SeaLLMs/SeaLLM-7B-v2")
9
10messages = [
11 {"role": "system", "content": "You are a helpful assistant."},
12 {"role": "user", "content": "Hello world"},
13 {"role": "assistant", "content": "Hi there, how can I help you today?"},
14 {"role": "user", "content": "Explain general relativity in details."}
15]
16
17encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
18print(tokenizer.convert_ids_to_tokens(encodeds[0]))
19# ['<s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'system', '<0x0A>', 'You', '▁are', '▁a', '▁helpful', '▁assistant', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Hello', '▁world', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Hi', '▁there', ',', '▁how', '▁can', '▁I', '▁help', '▁you', '▁today', '?', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Ex', 'plain', '▁general', '▁rel', 'ativity', '▁in', '▁details', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>']
20
21model_inputs = encodeds.to(device)
22model.to(device)
23
24generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True, pad_token_id=tokenizer.pad_token_id)
25decoded = tokenizer.batch_decode(generated_ids)
26print(decoded[0])
271from vllm import LLM, SamplingParams
2TURN_TEMPLATE = "<|im_start|>{role}\n{content}</s>"
3TURN_PREFIX = "<|im_start|>{role}\n"
4
5# There is no \n between </s> and <|im_start|>.
6
7def seallm_chat_convo_format(conversations, add_assistant_prefix: bool, system_prompt=None):
8 # conversations: list of dict with key `role` and `content` (openai format)
9 if conversations[0]['role'] != 'system' and system_prompt is not None:
10 conversations = [{"role": "system", "content": system_prompt}] + conversations
11 text = ''
12 for turn_id, turn in enumerate(conversations):
13 prompt = TURN_TEMPLATE.format(role=turn['role'], content=turn['content'])
14 text += prompt
15 if add_assistant_prefix:
16 prompt = TURN_PREFIX.format(role='assistant')
17 text += prompt
18 return text
19
20sparams = SamplingParams(temperature=0.1, max_tokens=1024, stop=['</s>', '<|im_start|>'])
21llm = LLM("SeaLLMs/SeaLLM-7B-v2", dtype="bfloat16")
22
23message = "Explain general relativity in details."
24prompt = seallm_chat_convo_format(message, True)
25gen = llm.generate(prompt, sampling_params)
26
27print(gen[0].outputs[0].text)1conversations = [
2 {"role": "system", "content": "You are helful assistant."},
3 {"role": "user", "content": "Hello world."},
4 {"role": "assistant", "content": "Hi there, how can I help?"},
5 {"role": "user", "content": "Tell me a joke."},
6 {"role": "assistant", "content": "Why don't scientists trust atoms? Because they make up everything."},
7]
8def seallm_7b_v2_tokenize_multi_turns(tokenizer, conversations, add_assistant_prefix=False):
9 """
10 Inputs:
11 conversations: list of dict following openai format, eg
12 conversations = [
13 {"role": "system", "content": "You are helful assistant."},
14 {"role": "user", "content": "Hello world."},
15 {"role": "assistant", "content": "Hi there, how can I help?"},
16 {"role": "user", "content": "Tell me a joke."},
17 {"role": "assistant", "content": "Why don't scientists trust atoms? Because they make up everything."},
18 ]
19 add_assistant_prefix: whether to add assistant_prefix, only for inference decoding
20 Outputs:
21 tokenize_output_sample, {
22 "input_ids": ...
23 "token_type_ids": 1 if train and 0 if masked out (not train)
24 }
25 During training, need to create a labels, with masked-out tokens = -100 to avoid loss computations.
26 labels = sample['input_ids'].clone()
27 labels[sample['token_type_ids'] == 0] = -100
28 """
29 TURN_TEMPLATE = "<|im_start|>{role}\n{content}</s>"
30 TURN_PREFIX = "<|im_start|>{role}\n"
31 sample = None
32 assistant_prefix_len = None
33 for turn_id, turn in enumerate(conversations):
34 prompt = TURN_TEMPLATE.format(role=turn['role'], content=turn['content'])
35 turn_sample = tokenizer(
36 prompt, padding=False, truncation=False, verbose=False, add_special_tokens=False,
37 return_token_type_ids=True,
38 )
39 if turn['role'] == 'assistant':
40 if assistant_prefix_len is None:
41 assistant_prefix_len = len(tokenizer.encode(TURN_PREFIX.format(role=turn['role']), add_special_tokens=False))
42 turn_sample['token_type_ids'][assistant_prefix_len:] = [1] * (len(turn_sample['input_ids']) - assistant_prefix_len)
43 if sample is None:
44 sample = turn_sample
45 else:
46 for k in turn_sample.keys():
47 sample[k].extend(turn_sample[k])
48 if add_assistant_prefix:
49 assistant_prefix_sample = tokenizer(
50 TURN_PREFIX.format(role="assistant"), padding=False, truncation=False, verbose=False, add_special_tokens=False,
51 return_token_type_ids=True,
52 )
53 for k in sample.keys():
54 sample[k].extend(assistant_prefix_sample[k])
55 if tokenizer.add_bos_token:
56 sample['input_ids'] = [tokenizer.bos_token_id] + sample['input_ids']
57 sample['attention_mask'] = [1] + sample['attention_mask']
58 sample['token_type_ids'] = [sample['token_type_ids'][0]] + sample['token_type_ids']
59 return sample
60
61# ! testing
62sample = seallm_7b_v2_tokenize_multi_turns(tokenizer, conversations)
63print(tokenizer.convert_ids_to_tokens(sample['input_ids']))
64print(sample['token_type_ids'])
65# ['<s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'system', '<0x0A>', 'You', '▁are', '▁hel', 'ful', '▁assistant', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Hello', '▁world', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Hi', '▁there', ',', '▁how', '▁can', '▁I', '▁help', '?', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Tell', '▁me', '▁a', '▁joke', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Why', '▁don', "'", 't', '▁scientists', '▁trust', '▁atoms', '?', '▁Because', '▁they', '▁make', '▁up', '▁everything', '.', '</s>']
66# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
67
68
69* and ^ are equal contributions.@article{damonlpsg2023seallm,
author = {Xuan-Phi Nguyen*, Wenxuan Zhang*, Xin Li*, Mahani Aljunied*,
Zhiqiang Hu, Chenhui Shen^, Yew Ken Chia^, Xingxuan Li, Jianyu Wang,
Qingyu Tan, Liying Cheng, Guanzheng Chen, Yue Deng, Sen Yang,
Chaoqun Liu, Hang Zhang, Lidong Bing},
title = {SeaLLMs - Large Language Models for Southeast Asia},
year = 2023,
Eprint = {arXiv:2312.00738},
}