Views
No views yet

<|start_header_id|>system<|end_header_id|>
{ SYS Prompt }<|eot_id|><|start_header_id|>user<|end_header_id|>
{ USER Prompt }<|eot_id|><|start_header_id|>assistant<|end_header_id|>
{ ASSIST Prompt }<|eot_id|>transformers, you can easily get started with the following steps.pip.pip install -U transformers trl peft accelerate bitsandbytes1import torch
2from transformers import (
3 AutoModelForCausalLM,
4 AutoTokenizer,
5)
6
7base_model = "swap-uniba/LLaMAntino-3-ANITA-8B-Inst-DPO-ITA"
8model = AutoModelForCausalLM.from_pretrained(
9 base_model,
10 torch_dtype=torch.bfloat16,
11 device_map="auto",
12)
13tokenizer = AutoTokenizer.from_pretrained(base_model)
14
15sys = "Sei un an assistente AI per la lingua Italiana di nome LLaMAntino-3 ANITA " \
16 "(Advanced Natural-based interaction for the ITAlian language)." \
17 " Rispondi nella lingua usata per la domanda in modo chiaro, semplice ed esaustivo."
18
19messages = [
20 {"role": "system", "content": sys},
21 {"role": "user", "content": "Chi è Carlo Magno?"}
22]
23
24#Method 1
25prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
26inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
27for k,v in inputs.items():
28 inputs[k] = v.cuda()
29outputs = model.generate(**inputs, max_new_tokens=512, do_sample=True, top_p=0.9, temperature=0.6)
30results = tokenizer.batch_decode(outputs)[0]
31print(results)
32
33#Method 2
34import transformers
35pipe = transformers.pipeline(
36 model=model,
37 tokenizer=tokenizer,
38 return_full_text=False, # langchain expects the full text
39 task='text-generation',
40 max_new_tokens=512, # max number of tokens to generate in the output
41 temperature=0.6, #temperature for more or less creative answers
42 do_sample=True,
43 top_p=0.9,
44)
45
46sequences = pipe(messages)
47for seq in sequences:
48 print(f"{seq['generated_text']}")
491import torch
2from transformers import (
3 AutoModelForCausalLM,
4 AutoTokenizer,
5 BitsAndBytesConfig,
6)
7
8base_model = "swap-uniba/LLaMAntino-3-ANITA-8B-Inst-DPO-ITA"
9bnb_config = BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_quant_type="nf4",
12 bnb_4bit_compute_dtype=torch.bfloat16,
13 bnb_4bit_use_double_quant=False,
14)
15model = AutoModelForCausalLM.from_pretrained(
16 base_model,
17 quantization_config=bnb_config,
18 device_map="auto",
19)
20tokenizer = AutoTokenizer.from_pretrained(base_model)
21
22sys = "Sei un an assistente AI per la lingua Italiana di nome LLaMAntino-3 ANITA " \
23 "(Advanced Natural-based interaction for the ITAlian language)." \
24 " Rispondi nella lingua usata per la domanda in modo chiaro, semplice ed esaustivo."
25
26messages = [
27 {"role": "system", "content": sys},
28 {"role": "user", "content": "Chi è Carlo Magno?"}
29]
30
31#Method 1
32prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
33inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
34for k,v in inputs.items():
35 inputs[k] = v.cuda()
36outputs = model.generate(**inputs, max_new_tokens=512, do_sample=True, top_p=0.9, temperature=0.6)
37results = tokenizer.batch_decode(outputs)[0]
38print(results)
39
40#Method 2
41import transformers
42pipe = transformers.pipeline(
43 model=model,
44 tokenizer=tokenizer,
45 return_full_text=False, # langchain expects the full text
46 task='text-generation',
47 max_new_tokens=512, # max number of tokens to generate in the output
48 temperature=0.6, #temperature for more or less creative answers
49 do_sample=True,
50 top_p=0.9,
51)
52
53sequences = pipe(messages)
54for seq in sequences:
55 print(f"{seq['generated_text']}")
56 lm_eval --model hf --model_args pretrained=HUGGINGFACE_MODEL_ID --tasks hellaswag_it,arc_it --device cuda:0 --batch_size auto:2
lm_eval --model hf --model_args pretrained=HUGGINGFACE_MODEL_ID --tasks m_mmlu_it --num_fewshot 5 --device cuda:0 --batch_size auto:2 | Metric | Value |
|---|---|
| Avg. | 0.6160 |
| Arc_IT | 0.5714 |
| Hellaswag_IT | 0.7093 |
| MMLU_IT | 0.5672 |

1@misc{polignano2024advanced,
2 title={Advanced Natural-based interaction for the ITAlian language: LLaMAntino-3-ANITA},
3 author={Marco Polignano and Pierpaolo Basile and Giovanni Semeraro},
4 year={2024},
5 eprint={2405.07101},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}1@misc{basile2023llamantino,
2 title={LLaMAntino: LLaMA 2 Models for Effective Text Generation in Italian Language},
3 author={Pierpaolo Basile and Elio Musacchio and Marco Polignano and Lucia Siciliani and Giuseppe Fiameni and Giovanni Semeraro},
4 year={2023},
5 eprint={2312.09993},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}1@article{llama3modelcard,
2 title={Llama 3 Model Card},
3 author={AI@Meta},
4 year={2024},
5 url = {https://github.com/meta-llama/llama3/blob/main/MODEL_CARD.md}
6}
| Metric | Value |
|---|---|
| Avg. | 75.12 |
| AI2 Reasoning Challenge (25-Shot) | 74.57 |
| HellaSwag (10-Shot) | 92.75 |
| MMLU (5-Shot) | 66.85 |
| TruthfulQA (0-shot) | 75.93 |
| Winogrande (5-shot) | 82.00 |
| GSM8k (5-shot) | 58.61 |