File size: 4,530 Bytes
86f57cc
 
 
 
 
 
 
 
 
 
 
 
 
f9576fb
 
86f57cc
 
5dc5787
86f57cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bb5fc0
86f57cc
 
 
 
4bb5fc0
86f57cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
datasets:
- Egor-AI/Russian_thinking_dataset
language:
- ru
- en
base_model:
- ai-sage/GigaChat-20B-A3B-instruct-bf16
pipeline_tag: text-generation
library_name: peft
tags:
- o1
- thinking
- reflection
---

# Russian o1 / GigaChat 20B-A3B Instruct

LoRA-адаптер для модели [GigaChat-20B-A3B](https://huggingface.co/ai-sage/GigaChat-20B-A3B-instruct-bf16) обученный на
датасете [Egor-AI/Russian_thinking_dataset](https://huggingface.co/datasets/Egor-AI/Russian_thinking_dataset) (машинный
перевод на русский язык
датасета [BintangFortuna/OpenO1-SFT-EN-SY](https://huggingface.co/datasets/BintangFortuna/OpenO1-SFT-EN-SY)).

Обученная модель способна имитировать логические размышлению на русском языке по аналогии с тем, как
это делает `o1` от `OpenAI`.

Необходимо использовать следующего вида системный промт:

```
Вы — ИИ-помощник. Отформатируйте свои ответы следующим образом: <Thought> Ваши мысли (понимание, рассуждения) </Thought> <output> Ваш ответ </output>
```

W&B отчёт: https://api.wandb.ai/links/evilfreelancer/nlec8bt8

Обучение производилось при помощи утилиты [impruver](https://github.com/EvilFreelancer/impruver) используя конфигурацию
[GigaChat/20B-A3B_lora_o1](https://github.com/EvilFreelancer/impruver/blob/main/recipes/configs/GigaChat/20B-A3B_lora_o1.yaml).

На всё про всё ушло примерно 117 часов на RTX 4090, при этом понадобилось 23Гб видеопамяти.

```yaml
output_dir: ./models/GigaChat_20B-A3B_lora_thinking
train_path: ./train.GigaChat_20B-A3B_lora_thinking.jsonl
val_path: ./val.GigaChat_20B-A3B_lora_thinking.jsonl

datasets:
  - name: Egor-AI/Russian_thinking_dataset
    converter: impruver.instruction_to_messages
    mapping:
      system: system
      instruction: prompt
      output: response

model:
  class: custom.gigachat.DeepseekForCausalLM
  name: ai-sage/GigaChat-20B-A3B-instruct-bf16
  attn_implementation: flash_attention_2
  load_in_4bit: true
  load_in_8bit: false
  dtype: bf16

lora:
  r: 8
  lora_alpha: 32
  lora_dropout: 0.1
  bias: none
  target_modules: [ q_proj, v_proj, k_proj, o_proj, gate_proj, down_proj, up_proj ]
  task_type: CAUSAL_LM

tokenizer:
  class: transformers.AutoTokenizer
  name: ai-sage/GigaChat-20B-A3B-instruct
  max_tokens_count: 1500
  special_tokens:
    pad_token_id: 1
    pad_token: <s>
    bos_token_id: 1
    bos_token: <s>
    eos_token_id: 128001
    eos_token: <|message_sep|>
  chat_template: >
    {% if messages[0]['role'] == 'system' -%}
        {%- set loop_messages = messages[1:] -%}
        {%- set system_message = bos_token + messages[0]['content'] + additional_special_tokens[1] -%}
    {%- else -%}
        {%- set loop_messages = messages -%}
        {%- set system_message = bos_token + '' -%}
    {%- endif -%}
    {%- for message in messages %}
        {%- if message['role'] == 'system' -%}
            {{ system_message -}}
        {%- endif -%}
        {%- if message['role'] == 'user' -%}
            {{ message['role'] + additional_special_tokens[0] + message['content'] + additional_special_tokens[1] -}}
            {{ 'available functions' + additional_special_tokens[0] + additional_special_tokens[2] + additional_special_tokens[3]  + additional_special_tokens[1] -}}
        {%- endif -%}
        {%- if message['role'] == 'assistant' -%}
            {{ message['role'] + additional_special_tokens[0] + message['content'] + additional_special_tokens[1] -}}
        {%- endif -%}
        {%- if loop.last and add_generation_prompt -%}
            {{ 'assistant' + additional_special_tokens[0] -}}
        {%- endif -%}
    {%- endfor %}

trainer:
  eval_strategy: steps
  save_strategy: steps
  eval_steps: 100
  save_steps: 100
  per_device_train_batch_size: 1
  per_device_eval_batch_size: 1
  gradient_accumulation_steps: 8
  logging_steps: 1
  learning_rate: 0.0004
  num_train_epochs: 2
  lr_scheduler_type: cosine
  warmup_steps: 16
  optim: adamw_torch_4bit
  metric_for_best_model: eval_loss
  load_best_model_at_end: true
  save_total_limit: 2
  seed: 42
  remove_unused_columns: false
  max_grad_norm: 1.0
  weight_decay: 0.08
  torch_compile: false
```