File size: 2,451 Bytes
f817b34
 
 
 
 
 
 
 
30af980
c3adcbb
03f0cb4
c3adcbb
 
 
 
c0ab2b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3adcbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03f0cb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d4f6c3c
03f0cb4
 
c3adcbb
 
 
 
 
 
 
 
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
---
license: apache-2.0
datasets:
- GAIR/lima
language:
- en
pipeline_tag: text-generation
---
# LIMSTRAL 🇲🍋

## Mistral 7B fine-tuned on LIMA
This model is a fine-tuned version of [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) on the LIMA dataset.

## Training procedure

The model was loaded on **8 bits** and fine-tuned on the LIMA dataset using the **LoRA** PEFT technique with the `huggingface/peft` library and `trl/sft` for 2 epochs on 1 x A100 (40GB) GPU.

SFT Trainer params:
```
trainer = SFTTrainer(
    model=model,
    train_dataset=train_ds,
    eval_dataset=test_ds,
    peft_config=peft_config,
    dataset_text_field="text",
    max_seq_length=2048,
    tokenizer=tokenizer,
    args=training_arguments,
    packing=False
)
```

LoRA config:
```
config = LoraConfig(
        lora_alpha=16,
        lora_dropout=0.1,
        r=64,
        bias="none",
        task_type="CAUSAL_LM",
        target_modules = ['q_proj', 'k_proj', 'down_proj', 'v_proj', 'o_proj', 'gate_proj', 'up_proj']
    )
```

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 0.0002
- train_batch_size: 2
- eval_batch_size: 8
- seed: 66
- gradient_accumulation_steps: 64
- total_train_batch_size: 128
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: constant
- lr_scheduler_warmup_ratio: 0.03
- num_epochs: 2
- mixed_precision_training: Native AMP

### Training results

| Training Loss | Epoch | Step | Validation Loss |
|:-------------:|:-----:|:----:|:---------------:|
| 1.7917        | 0.72  | 5    | 1.7604          |
| 1.7743        | 1.44  | 10   | 1.7217          |


### Usage
```py
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

model_id = "mrm8488/limstral-7B-v0.1"
tokenizer = "mrm8488/limstral-7B-v0.1"

model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(model_id)

model.resize_token_embeddings(len(tokenizer))

gen = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0)

instruction = "[INST] Write a email to day goodbye to me boss [\INST]"
res = gen(instruction, max_new_tokens=512, temperature=0.3, top_p=0.75, top_k=40, repetition_penalty=1.2)
print(res[0]['generated_text'])
```

### Framework versions

- Transformers 4.35.0.dev0
- Pytorch 2.1.0+cu118
- Datasets 2.14.6
- Tokenizers 0.14.1