Views
No views yet

google/gemma-2-2b-it using llama.cpp via the ggml.ai's GGUF-my-repo space.
Refer to the original model card for more details on the model.1architecture str = gemma2
2 type str = model
3 name str = Gemma 2 2b It
4 finetune str = it
5 basename str = gemma-2
6 size_label str = 2B
7 license str = gemma
8 count u32 = 1
9model.0.name str = Gemma 2 2b
10organization str = Google
11format = GGUF V3 (latest)
12arch = gemma2
13vocab type = SPM
14n_vocab = 256000
15n_merges = 0
16vocab_only = 0
17n_ctx_train = 8192
18n_embd = 2304
19n_layer = 26
20n_head = 8
21n_head_kv = 4
22model type = 2B
23model ftype = Q5_K - Medium
24model params = 2.61 B
25model size = 1.79 GiB (5.87 BPW)
26general.name = Gemma 2 2b It
27BOS token = 2 '<bos>'
28EOS token = 1 '<eos>'
29UNK token = 3 '<unk>'
30PAD token = 0 '<pad>'
31LF token = 227 '<0x0A>'
32EOT token = 107 '<end_of_turn>'
33EOG token = 1 '<eos>'
34EOG token = 107 '<end_of_turn>'
35
36>>> System role not supported
37Available chat formats from metadata: chat_template.default
38Using gguf chat template: {{ bos_token }}{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '<start_of_turn>' + role + '
39' + message['content'] | trim + '<end_of_turn>
40' }}{% endfor %}{% if add_generation_prompt %}{{'<start_of_turn>model
41'}}{% endif %}
42Using chat eos_token: <eos>
43Using chat bos_token: <bos>
441<bos><start_of_turn>user
2{prompt}<end_of_turn>
3<start_of_turn>model
4<end_of_turn>1messages = [
2 {"role": "user", "content": "Write me a poem about Machine Learning."},
3]1pip install llama-cpp-python
21wget https://huggingface.co/FM-1976/gemma-2-2b-it-Q5_K_M-GGUF/resolve/main/gemma-2-2b-it-q5_k_m.gguf -OutFile gemma-2-2b-it-q5_k_m.gguf
21from llama_cpp import Llama
2nCTX = 8192
3sTOPS = ['<eos>']
4llm = Llama(
5 model_path='gemma-2-2b-it-q5_k_m.gguf',
6 temperature=0.24,
7 n_ctx=nCTX,
8 max_tokens=600,
9 repeat_penalty=1.176,
10 stop=sTOPS,
11 verbose=False,
12 )
13messages = [
14 {"role": "user", "content": "Write me a poem about Machine Learning."},
15]
16response = llm.create_chat_completion(
17 messages=messages,
18 temperature=0.15,
19 repeat_penalty= 1.178,
20 stop=sTOPS,
21 max_tokens=500)
22print(response['choices'][0]['message']['content'])1from llama_cpp import Llama
2nCTX = 8192
3sTOPS = ['<eos>']
4llm = Llama(
5 model_path='gemma-2-2b-it-q5_k_m.gguf',
6 temperature=0.24,
7 n_ctx=nCTX,
8 max_tokens=600,
9 repeat_penalty=1.176,
10 stop=sTOPS,
11 verbose=False,
12 )
13prompt = 'Explain Science in one sentence.'
14template = f'''<bos><start_of_turn>user
15{prompt}<end_of_turn>
16<start_of_turn>model
17<end_of_turn>'''
18res = llm.create_completion(prompt,temperature=0.15, max_tokens=500,repeat_penalty=1.178, stop=['<eos>'])
19print(res['choices'][0]['text'])create_chat_completion() and create_completion() methods.
create_chat_completion() method1import datetime
2from llama_cpp import Llama
3nCTX = 8192
4sTOPS = ['<eos>']
5llm = Llama(
6 model_path='gemma-2-2b-it-q5_k_m.gguf',
7 temperature=0.24,
8 n_ctx=nCTX,
9 max_tokens=600,
10 repeat_penalty=1.176,
11 stop=sTOPS,
12 verbose=False,
13 )
14fisrtround=0
15full_response = ''
16message = [{'role':'user','content':'what is science?'}]
17start = datetime.datetime.now()
18for chunk in llm.create_chat_completion(
19 messages=message,
20 temperature=0.15,
21 repeat_penalty= 1.31,
22 stop=['<eos>'],
23 max_tokens=500,
24 stream=True,):
25 try:
26 if chunk["choices"][0]["delta"]["content"]:
27 if fisrtround==0:
28 print(chunk["choices"][0]["delta"]["content"], end="", flush=True)
29 full_response += chunk["choices"][0]["delta"]["content"]
30 ttftoken = datetime.datetime.now() - start
31 fisrtround = 1
32 else:
33 print(chunk["choices"][0]["delta"]["content"], end="", flush=True)
34 full_response += chunk["choices"][0]["delta"]["content"]
35 except:
36 pass
37first_token_time = ttftoken.total_seconds()
38print(f'Time to first token: {first_token_time:.2f} seconds')create_completion() method1import datetime
2from llama_cpp import Llama
3nCTX = 8192
4sTOPS = ['<eos>']
5llm = Llama(
6 model_path='gemma-2-2b-it-q5_k_m.gguf',
7 temperature=0.24,
8 n_ctx=nCTX,
9 max_tokens=600,
10 repeat_penalty=1.176,
11 stop=sTOPS,
12 verbose=False,
13 )
14fisrtround=0
15full_response = ''
16prompt = 'Explain Science in one sentence.'
17template = f'''<bos><start_of_turn>user
18{prompt}<end_of_turn>
19<start_of_turn>model
20<end_of_turn>'''
21start = datetime.datetime.now()
22for chunk in llm.create_completion(
23 prompt,
24 temperature=0.15,
25 repeat_penalty= 1.78,
26 stop=['<eos>'],
27 max_tokens=500,
28 stream=True,):
29 if fisrtround==0:
30 print(chunk["choices"][0]["text"], end="", flush=True)
31 full_response += chunk["choices"][0]["text"]
32 ttftoken = datetime.datetime.now() - start
33 fisrtround = 1
34 else:
35 print(chunk["choices"][0]["text"], end="", flush=True)
36 full_response += chunk["choices"][0]["text"]
37
38first_token_time = ttftoken.total_seconds()
39print(f'Time to first token: {first_token_time:.2f} seconds')llama-cpp-python[server] and llamafile.