Nanobit commited on
Commit
1115c50
β€’
1 Parent(s): 7ee3c4c

Feat: Add Qwen (#894)

Browse files

* Feat: Add Qwen

* feat: add qwen lora example

* feat: update matrix

* fix: add trust_remote_code

* fix: disable gradient checkpointing

* chore: add warning about gradient checkpointing

* fix: config

* fix: turn off sample packing for this example and reduce seq len

* chore: add comment on seq len

README.md CHANGED
@@ -77,6 +77,7 @@ Features:
77
  | XGen | βœ… | ❓ | βœ… | ❓ | ❓ | ❓ | βœ… |
78
  | phi | βœ… | βœ… | βœ… | ❓ | ❓ | ❓ | ❓ |
79
  | RWKV | βœ… | ❓ | ❓ | ❓ | ❓ | ❓ | ❓ |
 
80
 
81
 
82
  ## Quickstart ⚑
@@ -499,6 +500,7 @@ is_falcon_derived_model:
499
  is_llama_derived_model:
500
  # Please note that if you set this to true, `padding_side` will be set to "left" by default
501
  is_mistral_derived_model:
 
502
 
503
  # optional overrides to the base model configuration
504
  model_config:
 
77
  | XGen | βœ… | ❓ | βœ… | ❓ | ❓ | ❓ | βœ… |
78
  | phi | βœ… | βœ… | βœ… | ❓ | ❓ | ❓ | ❓ |
79
  | RWKV | βœ… | ❓ | ❓ | ❓ | ❓ | ❓ | ❓ |
80
+ | Qwen | βœ… | βœ… | βœ… | ❓ | ❓ | ❓ | ❓ |
81
 
82
 
83
  ## Quickstart ⚑
 
500
  is_llama_derived_model:
501
  # Please note that if you set this to true, `padding_side` will be set to "left" by default
502
  is_mistral_derived_model:
503
+ is_qwen_derived_model:
504
 
505
  # optional overrides to the base model configuration
506
  model_config:
examples/qwen/lora.yml ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ base_model: Qwen/Qwen-7B
2
+ model_type: AutoModelForCausalLM
3
+ tokenizer_type: AutoTokenizer
4
+
5
+ is_qwen_derived_model: true
6
+ trust_remote_code: true
7
+
8
+ load_in_8bit: true
9
+ load_in_4bit: false
10
+ strict: false
11
+
12
+ datasets:
13
+ - path: mhenrichsen/alpaca_2k_test
14
+ type: alpaca
15
+ dataset_prepared_path:
16
+ val_set_size: 0.05
17
+ output_dir: ./lora-out
18
+
19
+ sequence_len: 2048 # supports up to 8192
20
+ sample_packing: false
21
+ pad_to_sequence_len:
22
+
23
+ adapter: lora
24
+ lora_model_dir:
25
+ lora_r: 32
26
+ lora_alpha: 16
27
+ lora_dropout: 0.05
28
+ lora_target_linear: true
29
+ lora_fan_in_fan_out:
30
+
31
+ wandb_project:
32
+ wandb_entity:
33
+ wandb_watch:
34
+ wandb_run_id:
35
+ wandb_log_model:
36
+
37
+ gradient_accumulation_steps: 4
38
+ micro_batch_size: 2
39
+ num_epochs: 4
40
+ optimizer: adamw_bnb_8bit
41
+ lr_scheduler: cosine
42
+ learning_rate: 0.0002
43
+
44
+ train_on_inputs: false
45
+ group_by_length: false
46
+ bf16: true
47
+ fp16: false
48
+ tf32: false
49
+
50
+ gradient_checkpointing: false
51
+ early_stopping_patience:
52
+ resume_from_checkpoint:
53
+ local_rank:
54
+ logging_steps: 1
55
+ xformers_attention:
56
+ flash_attention: true
57
+
58
+ warmup_steps: 10
59
+ eval_steps: 0.05
60
+ eval_table_size:
61
+ eval_table_max_new_tokens: 128
62
+ save_steps:
63
+ debug:
64
+ deepspeed:
65
+ weight_decay: 0.0
66
+ fsdp:
67
+ fsdp_config:
68
+ special_tokens:
examples/qwen/qlora.yml ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ base_model: Qwen/Qwen-7B
2
+ model_type: AutoModelForCausalLM
3
+ tokenizer_type: AutoTokenizer
4
+
5
+ is_qwen_derived_model: true
6
+ trust_remote_code: true
7
+
8
+ load_in_8bit: false
9
+ load_in_4bit: true
10
+ strict: false
11
+
12
+ datasets:
13
+ - path: mhenrichsen/alpaca_2k_test
14
+ type: alpaca
15
+ dataset_prepared_path:
16
+ val_set_size: 0.05
17
+ output_dir: ./lora-out
18
+
19
+ sequence_len: 2048 # supports up to 8192
20
+ sample_packing: false
21
+ pad_to_sequence_len:
22
+
23
+ adapter: qlora
24
+ lora_model_dir:
25
+ lora_r: 32
26
+ lora_alpha: 16
27
+ lora_dropout: 0.05
28
+ lora_target_linear: true
29
+ lora_fan_in_fan_out:
30
+
31
+ wandb_project:
32
+ wandb_entity:
33
+ wandb_watch:
34
+ wandb_run_id:
35
+ wandb_log_model:
36
+
37
+ gradient_accumulation_steps: 4
38
+ micro_batch_size: 2
39
+ num_epochs: 4
40
+ optimizer: adamw_bnb_8bit
41
+ lr_scheduler: cosine
42
+ learning_rate: 0.0002
43
+
44
+ train_on_inputs: false
45
+ group_by_length: false
46
+ bf16: true
47
+ fp16: false
48
+ tf32: false
49
+
50
+ gradient_checkpointing: false
51
+ early_stopping_patience:
52
+ resume_from_checkpoint:
53
+ local_rank:
54
+ logging_steps: 1
55
+ xformers_attention:
56
+ flash_attention: true
57
+
58
+ warmup_steps: 10
59
+ eval_steps: 0.05
60
+ eval_table_size:
61
+ eval_table_max_new_tokens: 128
62
+ save_steps:
63
+ debug:
64
+ deepspeed:
65
+ weight_decay: 0.0
66
+ fsdp:
67
+ fsdp_config:
68
+ special_tokens:
src/axolotl/utils/config.py CHANGED
@@ -122,6 +122,19 @@ def normalize_config(cfg):
122
  or (cfg.model_type and "mistral" in cfg.model_type.lower())
123
  )
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  if isinstance(cfg.learning_rate, str):
126
  cfg.learning_rate = float(cfg.learning_rate)
127
 
@@ -379,6 +392,11 @@ def validate_config(cfg):
379
  if cfg.warmup_steps and cfg.warmup_ratio:
380
  raise ValueError("warmup_steps and warmup_ratio are mutually exclusive")
381
 
 
 
 
 
 
382
  # TODO
383
  # MPT 7b
384
  # https://github.com/facebookresearch/bitsandbytes/issues/25
 
122
  or (cfg.model_type and "mistral" in cfg.model_type.lower())
123
  )
124
 
125
+ cfg.is_qwen_derived_model = (
126
+ (
127
+ hasattr(model_config, "model_type")
128
+ and model_config.model_type
129
+ in [
130
+ "qwen",
131
+ ]
132
+ )
133
+ or cfg.is_qwen_derived_model
134
+ or "qwen" in cfg.base_model.lower()
135
+ or (cfg.model_type and "qwen" in cfg.model_type.lower())
136
+ )
137
+
138
  if isinstance(cfg.learning_rate, str):
139
  cfg.learning_rate = float(cfg.learning_rate)
140
 
 
392
  if cfg.warmup_steps and cfg.warmup_ratio:
393
  raise ValueError("warmup_steps and warmup_ratio are mutually exclusive")
394
 
395
+ if cfg.is_qwen_derived_model and cfg.gradient_checkpointing:
396
+ LOG.warning(
397
+ "Gradient checkpointing is broken for Qwen models for transformers>=4.35.0, except main branch."
398
+ )
399
+
400
  # TODO
401
  # MPT 7b
402
  # https://github.com/facebookresearch/bitsandbytes/issues/25
src/axolotl/utils/models.py CHANGED
@@ -84,6 +84,18 @@ def load_tokenizer(cfg):
84
  if cfg.is_mistral_derived_model and cfg.flash_attention and not cfg.sample_packing:
85
  tokenizer.padding_side = "left"
86
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  if cfg.special_tokens:
88
  for k, val in cfg.special_tokens.items():
89
  tokenizer.add_special_tokens(
 
84
  if cfg.is_mistral_derived_model and cfg.flash_attention and not cfg.sample_packing:
85
  tokenizer.padding_side = "left"
86
 
87
+ # Qwen base only has single token, so we need to set the special tokens
88
+ if cfg.is_qwen_derived_model:
89
+ token_ids = ["bos_token_id", "eos_token_id", "pad_token_id", "unk_token_id"]
90
+ for attr_name in token_ids:
91
+ if getattr(tokenizer, attr_name) is None:
92
+ setattr(tokenizer, attr_name, tokenizer.eod_id)
93
+
94
+ token_names = ["bos_token", "eos_token", "pad_token", "unk_token"]
95
+ for attr_name in token_names:
96
+ if getattr(tokenizer, attr_name) is None:
97
+ setattr(tokenizer, attr_name, "<|endoftext|>")
98
+
99
  if cfg.special_tokens:
100
  for k, val in cfg.special_tokens.items():
101
  tokenizer.add_special_tokens(