Ahma-7B-Instruct is a instruct/chat-tuned version of
Ahma-7B
trained to follow instructions in Finnish. The base Ahma 7B parameter model is decoder-only transformer model based on Meta's Llama (v1) architecture pretrained from scratch on Finnish language. Original Llama model architecture was introduced in
this paper
and first released at
this page
.
What does Ahma mean? Ahma is the Finnish word for wolverine! In the Finnish Lapland, wolverines are the biggest cause of reindeer damage.
There are two different sized base Ahma models, all pretrained from scratch for 139B tokens:
This model was fine-tuned for instruction following. Instruction-tuned models are intended for assistant-like chat, whereas pretrained models can be adapted for a variety of natural language generation tasks.
How to use
If you want to use this model for instruction-following, you need to use the same prompt format we used in the fine-tuning process (basically the same format what Meta used in their Llama2 models).
Note: do not use "LlamaTokenizer" from transformers library but always use the AutoTokenizer instead, or use the plain sentencepiece tokenizer.
Here is an example using the instruction-following prompt format with the tokenizer's built-in chat template feature which makes it easy to format your potential multi-turn chats too, with some generation arguments you can modify for your use:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
system_prompt = "Olet tekoälyavustaja. Vastaat aina mahdollisimman avuliaasti. Vastauksesi eivät saa sisältää mitään haitallista, epäeettistä, rasistista, seksististä, vaarallista tai laitonta sisältöä. Jos kysymyksessä ei ole mitään järkeä tai se ei ole asiasisällöltään johdonmukainen, selitä miksi sen sijaan, että vastaisit jotain väärin. Jos et tiedä vastausta kysymykseen, älä kerro väärää tietoa."# Check if `torch.bfloat16` is available
dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16
tokenizer = AutoTokenizer.from_pretrained("Finnish-NLP/Ahma-7B-Instruct")
model = AutoModelForCausalLM.from_pretrained("Finnish-NLP/Ahma-7B-Instruct", torch_dtype=dtype, device_map="auto")
model = model.to("cuda")
# use the chat template feature in the tokenizer to format your (multi-turn) inputs
messages = [
{
"role": "system",
"content": system_prompt,
},
{"role": "user", "content": "Kerro kolme hyötyä, joita pienet avoimen lähdekoodin kielimallit tuovat?"},
]
inputs = tokenizer.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True, return_tensors="pt"
)
inputs = inputs.to("cuda")
generated_ids = model.generate(
inputs,
temperature=0.6,
penalty_alpha=0.6,
top_k=4,
do_sample=True,
repetition_penalty=1.2,
min_length=5,
max_length=2048,
)
generated_text = tokenizer.batch_decode(
generated_ids, skip_special_tokens=False
)[0]
'''Pienten avointen kielten mallien käyttöönotolla voi olla useita etuja:1. Lisääntynyt joustavuus ja sopeutumiskyky: Avoimen lähdekoodin mallit mahdollistavat suuremman joustavuuden ja mukauttamisen, jolloin kehittäjät voivat räätälöidä malleja omien tarpeidensa mukaan.2. Lisääntynyt yhteistyö ja avoimuus: Avoimen lähdekoodin mallit helpottavat yhteistyötä kehittäjien välillä, jotka työskentelevät yhdessä mallin parantamiseksi ja päivittämiseksi, mikä edistää avointa ja yhteistyöhön perustuvaa ympäristöä.3. Suurempi kehittäjäyhteisö: Avoimen lähdekoodin mallit tarjoavat mahdollisuuden osallistua laajempaan kehittäjäyhteisöön, joka jakaa ideoita, resursseja ja parhaita käytäntöjä, jolloin kaikki voivat hyötyä muiden kokemuksista ja asiantuntemuksesta.'''
You may experiment with different system prompt instructions too if you like.
Limitations and bias
This model was trained only with Finnish texts excluding code so it should not be used for multilingual and code generation use cases.
The training data used for this model contains a lot of content from the internet, which is far from neutral. Therefore, the model can have biased predictions. This bias will also affect all fine-tuned versions of this model.
Training data
Training data is primarily created from English samples through translation, with multiple methods employed to filter out samples that are overly specific to the U.S., poorly translated, or of low quality. Tools such as LangDetect, KenLM, and Nemotron-70B are utilized to calculate various features that assist in filtering the datasets. For DPO samples, PairRM model predictions are applied to the English samples to identify and remove poor-quality data.
There has also been some indication that gradually increasing the training example lengths during the training could be beneficial. Thus, the training dataset was splitted to 4 bins based on example lengths, and then examples were sampled from the bins so that the example lengths are gradually increasing towards the end of the training while a little amount of the shorter examples are still present too.
This model was first supervised fine-tuned (SFT) on the combination of the following datasets:
Dataset
Dataset type
Upsampling
Words
Ratio
Average words per example
ai2_arc
Translated single-turn
1.0X
1K
0.01%
92
Aya
Finnish and translated
1.0X
216K
2.63%
120
chatbot_arena
Translated single-turn
1.0X
212K
2.58%
212
dibt10k
Translated single-turn
1.0X
219K
2.67%
332
dolly
Translated single-turn
1.0X
430K
5.23%
186
extraction_llama
Synthetic single-turn
1.0X
6K
0.07%
287
extraction_llama_nemotron_70b_synthetic
Synthetic single-turn
1.0X
5K
0.06%
291
antropic_hhrlhf
Translated single-turn
1.0X
119K
1.45%
121
intel
Translated single-turn
1.0X
305K
3.71%
233
lm_sys_multiturn
Translated multi-turn
1.0X
668K
8.13%
401
lmsys_1m
Translated single-turn
1.0X
1490K
18.14%
223
magpie_ultra
Translated single-turn
1.0X
1116K
13.58%
279
news_qa
Translated single-turn
1.0X
11K
0.13%
196
oasst_multiturn
Translated multi-turn
1.0X
497K
6.05%
347
orca_math
Translated single-turn
1.0X
493K
6.00%
224
person_discussions_multiturn
Synthetic multi-turn
1.0X
189K
2.30%
246
rag_datasets
Synthetic single turn
1.0X
780K
9.49%
453
suomitrivia
Translated single-turn
1.0X
3K
0.04%
64
truthy
Translated single-turn
1.0X
15K
0.18%
99
ultrachat
Translated single-turn
1.0X
1360K
16.56%
269
wikipedia_multitask_synthetic_qa
Synthetic single-turn
1.0X
26K
0.32%
526
wikipedia_synthetic_qa_reasoning
Synthetic single-turn
1.0X
53K
0.65%
472
TOTAL
8215K
100%
257
After tokenization, the SFT training dataset had 14.3 million tokens and 2% of the dataset was splitted for evaluation during the training.
The SFT model was then further fine-tuned with Direct Preference Optimization (DPO) on the combination of the following datasets:
Dataset
Dataset type
Upsampling
Words
Ratio
Average words per example
intel_dpo
Translated single-turn
1.0X
373K
14.78%
217
ultrachat_dpo
Translated single-turn
1.0X
1368K
54.20%
245
suomitrivia_dpo
Synthetic single-turn
1.0X
3K
0.12%
64
chatbot_arena
Translated single-turn
1.0X
57K
2.26%
198
antropic_hhrlhf
Translated single-turn
1.0X
89K
3.53%
156
truthy_dpo
Translated single-turn
1.0X
19K
0.75%
100
orca_math_5k
Translated single-turn
1.0X
614K
24.33%
229
TOTAL
2524K
100%
172
After tokenization, the DPO training dataset had 4.4 million tokens and 5% of the dataset was splitted for evaluation during the training.
Training procedure
Preprocessing
Texts are tokenized using Byte Pair Encoding (BPE) using the implementation from SentencePiece splitting all numbers into individual digits and using bytes to decompose unknown UTF-8 characters. The total
vocabulary size is 64k tokens. Inputs are sequences of 2048 consecutive tokens. Texts are not lower cased so this model is case-sensitive: it makes a difference between finnish and Finnish. Both BOS and EOS tokens were used in the fine-tuning.
Supervised fine-tuning (SFT)
This model was first supervised fine-tuned (SFT) using the
unsloth
framework with a single NVIDIA GeForce RTX 4090 GPU.
The model was fine-tuned for 2 epoch with a learning rate of 2e-05, weight decay of 5e-03,
learning rate scheduling using WSD (Warmup-Stable-Decay) warmup and decay ratios being 0.1, batch size of 4 and gradient accumulation of 8 totalling the batch size to 32, max sequence lenght of 2048, and with NEFTune noise alpha of 5.
The used optimizer was AdamW and the model was loaded with 4bit quantization.
Training was done using the Rank-Stabilized LoRA (RSLora) with a rank of 128 and alpha of 256, LoRA dropout of 0.05, target modules of "q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj" and modules_to_save "lm_head", "embed_tokens".
Loss in training was only calculated for the completion tokens.
Direct Preference Optimization (DPO) fine-tuning
The SFT model was then further fine-tuned with Direct Preference Optimization (DPO) using the
unsloth
framework with a single NVIDIA GeForce RTX 4090 GPU. The model was fine-tuned for 1 epoch with a learning rate of 2e-05, weight decay of 0.0, learning rate warmup ratio of 0.1 with cosine decay, batch size of 2 and gradient accumulation of 8 totalling the batch size to 16, and with max sequence lenght of 2048. The used optimizer was "paged_adamw_8bit". Training was done using the Rank-Stabilized LoRA (RSLora) with a rank of 32 and alpha of 32, LoRA dropout of 0.02, and target modules of "q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj".
As we can see, Ahma-7B-Instruct model has better 3-shot performance compared to its base 7B version, showcasing better few-shot prompting capability. That might be due to having multi-turn instruction-following training examples, demonstrating the value of the fine-tuning.
MTBench Finnish
This Ahma-7B-Instruct model was primarily evaluated using
MTBench Finnish by LumiOpen
since this model is fine-tuned for chat and instruction following. Since the MTBench evaluates also multi-turn chats while Ahma base models were only pretrained with single-turn instruction following examples, we have reported MTBench Finnish results separately for their single-turn and multi-turn evaluation examples. This enables us to evaluate how well this Ahma-7B-Instruct model improves on multi-turn chats since its fine-tuning dataset included some multi-turn examples too.
Poro 34B Chat by SiloGen, TurkuNLP and HPLT
model's presumably multi-turn results are copied from their model card for the comparison.
Single-turn results:
Benchmark
Ahma 3B base (instruct prompt format)
Ahma 3B Instruct (instruct prompt format)
Ahma 7B base (instruct prompt format)
Ahma 7B Instruct (instruct prompt format)
Coding
1.00
1.00
1.70
1.10
Extraction
2.00
1.30
3.10
3.00
Humanities
4.05
6.20
6.60
8.00
Math
3.00
3.20
3.90
2.90
Reasoning
2.90
4.60
3.70
5.70
Roleplay
4.80
6.50
6.60
7.20
STEM
5.10
5.95
6.75
7.30
Writing
6.60
9.00
7.10
8.80
Overall Average
3.68
4.72
4.93
5.50
Multi-turn results:
Benchmark
Ahma 3B base (instruct prompt format)
Ahma 3B Instruct (instruct prompt format)
Ahma 7B base (instruct prompt format)
Ahma 7B Instruct (instruct prompt format)
Poro 34B Chat
Coding
1.00
1.00
1.40
1.05
3.70
Extraction
1.55
1.15
2.05
2.65
6.37
Humanities
3.25
6.20
4.95
7.85
9.25
Math
2.20
2.70
2.50
2.40
1.20
Reasoning
2.45
3.50
2.55
4.50
4.35
Roleplay
4.90
6.40
6.35
6.60
7.35
STEM
4.20
4.78
4.28
5.40
7.80
Writing
3.80
6.65
4.10
6.25
8.50
Overall Average
2.92
4.05
3.52
4.59
6.06
As we can see, the Ahma-7B-Instruct model improves upon the base Ahma-7B model, especially in tasks like writing. It's also worth noting that the Ahma-7B-Instruct model shows enhanced performance in multi-turn tasks compared to the base model, which highlights the value of the multi-turn training examples used in the fine-tuning process. The Ahma-7B-Instruct model lost 17% of its single-turn overall score in a multi-turn setting, while the base Ahma-7B model lost 29%. Therefore, this instruct model might be better suited for chat use cases as well. As expected, coding performance was poor since the Ahma models aren't trained on code data and extraction and math scores suffered a bit as those were not in primary focus for this model.
Ahma models also seemed to have problems with the fact that they started to constantly repeat the generated text in some evaluation examples, which affected the scoring. With the addition of a repetition penalty setting to the evaluation script generation method, the scores already improved significantly, so Ahma models should be used with better generation settings in real-world use compared to the settings used in this benchmark.
Acknowledgements
This project would not have been possible without compute generously provided by Google through the
TPU Research Cloud
.
Ahma-7B-Instruct huggingface.co is an AI model on huggingface.co that provides Ahma-7B-Instruct's model effect (), which can be used instantly with this Finnish-NLP Ahma-7B-Instruct model. huggingface.co supports a free trial of the Ahma-7B-Instruct model, and also provides paid use of the Ahma-7B-Instruct. Support call Ahma-7B-Instruct model through api, including Node.js, Python, http.
Ahma-7B-Instruct huggingface.co is an online trial and call api platform, which integrates Ahma-7B-Instruct's modeling effects, including api services, and provides a free online trial of Ahma-7B-Instruct, you can try Ahma-7B-Instruct online for free by clicking the link below.
Finnish-NLP Ahma-7B-Instruct online free url in huggingface.co:
Ahma-7B-Instruct is an open source model from GitHub that offers a free installation service, and any user can find Ahma-7B-Instruct on GitHub to install. At the same time, huggingface.co provides the effect of Ahma-7B-Instruct install, users can directly use Ahma-7B-Instruct installed effect in huggingface.co for debugging and trial. It also supports api for free installation.