File size: 7,937 Bytes
75a38ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
626fda7
 
 
 
 
 
75a38ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
---
base_model: mesolitica/malaysian-tinyllama-1.1b-16k-instructions
inference: false
language:
- ms
model_creator: mesolitica
model_name: malaysian-tinyllama-1.1b-16k-instructions
pipeline_tag: text-generation
quantized_by: afrideva
tags:
- gguf
- ggml
- quantized
- q2_k
- q3_k_m
- q4_k_m
- q5_k_m
- q6_k
- q8_0
---
# mesolitica/malaysian-tinyllama-1.1b-16k-instructions-GGUF

Quantized GGUF model files for [malaysian-tinyllama-1.1b-16k-instructions](https://huggingface.co/mesolitica/malaysian-tinyllama-1.1b-16k-instructions) from [mesolitica](https://huggingface.co/mesolitica)


| Name | Quant method | Size |
| ---- | ---- | ---- |
| [malaysian-tinyllama-1.1b-16k-instructions.q2_k.gguf](https://huggingface.co/afrideva/malaysian-tinyllama-1.1b-16k-instructions-GGUF/resolve/main/malaysian-tinyllama-1.1b-16k-instructions.q2_k.gguf) | q2_k | 482.14 MB  |
| [malaysian-tinyllama-1.1b-16k-instructions.q3_k_m.gguf](https://huggingface.co/afrideva/malaysian-tinyllama-1.1b-16k-instructions-GGUF/resolve/main/malaysian-tinyllama-1.1b-16k-instructions.q3_k_m.gguf) | q3_k_m | 549.85 MB  |
| [malaysian-tinyllama-1.1b-16k-instructions.q4_k_m.gguf](https://huggingface.co/afrideva/malaysian-tinyllama-1.1b-16k-instructions-GGUF/resolve/main/malaysian-tinyllama-1.1b-16k-instructions.q4_k_m.gguf) | q4_k_m | 667.81 MB  |
| [malaysian-tinyllama-1.1b-16k-instructions.q5_k_m.gguf](https://huggingface.co/afrideva/malaysian-tinyllama-1.1b-16k-instructions-GGUF/resolve/main/malaysian-tinyllama-1.1b-16k-instructions.q5_k_m.gguf) | q5_k_m | 782.04 MB  |
| [malaysian-tinyllama-1.1b-16k-instructions.q6_k.gguf](https://huggingface.co/afrideva/malaysian-tinyllama-1.1b-16k-instructions-GGUF/resolve/main/malaysian-tinyllama-1.1b-16k-instructions.q6_k.gguf) | q6_k | 903.41 MB  |
| [malaysian-tinyllama-1.1b-16k-instructions.q8_0.gguf](https://huggingface.co/afrideva/malaysian-tinyllama-1.1b-16k-instructions-GGUF/resolve/main/malaysian-tinyllama-1.1b-16k-instructions.q8_0.gguf) | q8_0 | 1.17 GB  |



## Original Model Card:
# Full Parameter Finetuning TinyLlama 16384 context length on Malaysian instructions dataset

README at https://github.com/mesolitica/malaya/tree/5.1/session/tiny-llama#instructions-7b-16384-context-length

We use exact Llama2 Instruct chat template, added with function call

WandB, https://wandb.ai/mesolitica/fpf-tinyllama-1.1b-hf-instructions-16k-function-call?workspace=user-husein-mesolitica

## how-to

```python
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
import torch

def parse_llama_chat(messages, function_call = None):

    system = messages[0]['content']
    user_query = messages[-1]['content']

    users, assistants = [], []
    for q in messages[1:-1]:
        if q['role'] == 'user':
            users.append(q['content'])
        elif q['role'] == 'assistant':
            assistants.append(q['content'])

    texts = [f'<s>[INST] <<SYS>>\n{system}\n<</SYS>>\n\n']
    if function_call:
        fs = []
        for f in function_call:
            f = json.dumps(f, indent=4)
            fs.append(f)
        fs = '\n\n'.join(fs)
        texts.append(f'\n[FUNCTIONCALL]\n{fs}\n')
    for u, a in zip(users, assistants):
        texts.append(f'{u.strip()} [/INST] {a.strip()} </s><s>[INST] ')
    texts.append(f'{user_query.strip()} [/INST]')
    prompt = ''.join(texts).strip()
    return prompt

TORCH_DTYPE = 'bfloat16'
nf4_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type='nf4',
    bnb_4bit_use_double_quant=True,
    bnb_4bit_compute_dtype=getattr(torch, TORCH_DTYPE)
)

tokenizer = AutoTokenizer.from_pretrained('mesolitica/malaysian-tinyllama-1.1b-16k-instructions')
model = AutoModelForCausalLM.from_pretrained(
    'mesolitica/malaysian-tinyllama-1.1b-16k-instructions',
    use_flash_attention_2 = True,
    quantization_config = nf4_config
)

messages = [
    {'role': 'system', 'content': 'awak adalah AI yang mampu jawab segala soalan'},
    {'role': 'user', 'content': 'kwsp tu apa'}
]
prompt = parse_llama_chat(messages)
inputs = tokenizer([prompt], return_tensors='pt', add_special_tokens=False).to('cuda')
generate_kwargs = dict(
    inputs,
    max_new_tokens=1024,
    top_p=0.95,
    top_k=50,
    temperature=0.9,
    do_sample=True,
    num_beams=1,
)
r = model.generate(**generate_kwargs)
print(tokenizer.decode(r[0]))
```

```text
'<s> [INST] <<SYS>>
awak adalah AI yang mampu jawab segala soalan
<</SYS>>

kwsp tu apa [/INST] KWSP bermaksud Kumpulan Wang Persaraan. </s>'
```

```python
messages = [
    {'role': 'system', 'content': 'awak adalah AI yang mampu jawab segala soalan'},
    {'role': 'user', 'content': 'awat malaysia ada jabatan koko, malaysia bukan buat keluaq koko banyak pun'}
]
prompt = parse_llama_chat(messages)
inputs = tokenizer([prompt], return_tensors='pt', add_special_tokens=False).to('cuda')
generate_kwargs = dict(
    inputs,
    max_new_tokens=1024,
    top_p=0.95,
    top_k=50,
    temperature=0.9,
    do_sample=True,
    num_beams=1,
)
r = model.generate(**generate_kwargs)
print(tokenizer.decode(r[0]))
```

```text
<s> [INST] <<SYS>>
awak adalah AI yang mampu jawab segala soalan
<</SYS>>

awat malaysia ada jabatan koko, malaysia bukan buat keluaq koko banyak pun [/INST] Jabatan ini bertanggungjawab untuk mengeluarkan dan mengagihkan produk koko ke pasaran tempatan dan antarabangsa. Mereka juga menyumbang kepada pembangunan industri koko dan memastikan penggunaan sumber asli yang bertanggungjawab. Selain itu, mereka menjalankan penyelidikan dan inovasi untuk meningkatkan proses pengeluaran dan meningkatkan daya saing produk koko. </s>
```

```python
f2 = {
    'name': 'parse_entities',
    'description': 'extract entities from the text',
    'parameters': {
        'type': 'object',
        'properties': {
            'drink': {
                'type': 'string',
                'description': 'drink name',
            },
            'event': {
                'type': 'string',
                'description': 'event name',
            },
            'person_name': {
                'type': 'string',
                'description': 'person name',
            }
        },
        'required': [
            'drink',
            'event',
            'person_name'
        ]
    }
}
messages = [
    {'role': 'system', 'content': 'awak adalah AI yang mampu jawab segala soalan'},
    {'role': 'user', 'content': 'nama saya husein bin zolkepli, saya sekarang berada di putrajaya merdeka 2023 sambil minum teh o ais'}
]
prompt = parse_llama_chat(messages, function_call = [f2])
inputs = tokenizer([prompt], return_tensors='pt', add_special_tokens=False).to('cuda')
generate_kwargs = dict(
    inputs,
    max_new_tokens=128,
    top_p=0.95,
    top_k=50,
    temperature=0.9,
    do_sample=True,
    num_beams=1,
)
r = model.generate(**generate_kwargs)
print(tokenizer.decode(r[0]))
```

```text
<s> [INST] <<SYS>>
awak adalah AI yang mampu jawab segala soalan
<</SYS>>


[FUNCTIONCALL]
{
    "name": "parse_entities",
    "description": "extract entities from the text",
    "parameters": {
        "type": "object",
        "properties": {
            "drink": {
                "type": "string",
                "description": "drink name"
            },
            "event": {
                "type": "string",
                "description": "event name"
            },
            "person_name": {
                "type": "string",
                "description": "person name"
            }
        },
        "required": [
            "drink",
            "event",
            "person_name"
        ]
    }
}
nama saya husein bin zolkepli, saya sekarang berada di putrajaya merdeka 2023 sambil minum teh o ais [/INST] <functioncall> {"name": "parse_entities", "arguments": '{"drink": "teh o ais", "event": "Merdeka 2023", "person_name": "Husein bin Zolkepli"}'} 


<functioncall> {"entities": [{"name": "Husein bin Zolkepli", "confidence": 0.95}]} </s>
```