KashiwaByte commited on
Commit
9d513ce
1 Parent(s): c39e401
Files changed (4) hide show
  1. README.md +200 -1
  2. adapter_config.json +31 -0
  3. adapter_model.bin +3 -0
  4. xtuner_config.py +214 -0
README.md CHANGED
@@ -1,3 +1,202 @@
1
  ---
2
- license: apache-2.0
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ library_name: peft
3
+ base_model: /root/lanyun-tmp/ZhipuAI/chatglm3-6b
4
  ---
5
+
6
+ # Model Card for Model ID
7
+
8
+ <!-- Provide a quick summary of what the model is/does. -->
9
+
10
+
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ <!-- Provide a longer summary of what this model is. -->
17
+
18
+
19
+
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
+
28
+ ### Model Sources [optional]
29
+
30
+ <!-- Provide the basic links for the model. -->
31
+
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
+
36
+ ## Uses
37
+
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
+
40
+ ### Direct Use
41
+
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
+
44
+ [More Information Needed]
45
+
46
+ ### Downstream Use [optional]
47
+
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
+
50
+ [More Information Needed]
51
+
52
+ ### Out-of-Scope Use
53
+
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
+
56
+ [More Information Needed]
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
+
62
+ [More Information Needed]
63
+
64
+ ### Recommendations
65
+
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
+
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
+
70
+ ## How to Get Started with the Model
71
+
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
+
199
+ [More Information Needed]
200
+ ### Framework versions
201
+
202
+ - PEFT 0.10.0
adapter_config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "/root/lanyun-tmp/ZhipuAI/chatglm3-6b",
5
+ "bias": "none",
6
+ "fan_in_fan_out": false,
7
+ "inference_mode": true,
8
+ "init_lora_weights": true,
9
+ "layer_replication": null,
10
+ "layers_pattern": null,
11
+ "layers_to_transform": null,
12
+ "loftq_config": {},
13
+ "lora_alpha": 16,
14
+ "lora_dropout": 0.1,
15
+ "megatron_config": null,
16
+ "megatron_core": "megatron.core",
17
+ "modules_to_save": null,
18
+ "peft_type": "LORA",
19
+ "r": 64,
20
+ "rank_pattern": {},
21
+ "revision": null,
22
+ "target_modules": [
23
+ "dense",
24
+ "dense_h_to_4h",
25
+ "dense_4h_to_h",
26
+ "query_key_value"
27
+ ],
28
+ "task_type": "CAUSAL_LM",
29
+ "use_dora": false,
30
+ "use_rslora": false
31
+ }
adapter_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df3bf84ded32ba8667b5fd8d00861735f38eb92918f0c310159be750170e703e
3
+ size 237260362
xtuner_config.py ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) OpenMMLab. All rights reserved.
2
+ import torch
3
+ from datasets import load_dataset
4
+ from mmengine.dataset import DefaultSampler
5
+ from mmengine.hooks import (CheckpointHook, DistSamplerSeedHook, IterTimerHook,
6
+ LoggerHook, ParamSchedulerHook)
7
+ from mmengine.optim import AmpOptimWrapper, CosineAnnealingLR, LinearLR
8
+ from peft import LoraConfig
9
+ from torch.optim import AdamW
10
+ from transformers import (AutoModelForCausalLM, AutoTokenizer,
11
+ BitsAndBytesConfig)
12
+
13
+ from xtuner.dataset import process_hf_dataset
14
+ from xtuner.dataset.collate_fns import default_collate_fn
15
+ from xtuner.dataset.map_fns import alpaca_map_fn, template_map_fn_factory
16
+ from xtuner.engine.hooks import (DatasetInfoHook, EvaluateChatHook,
17
+ VarlenAttnArgsToMessageHubHook)
18
+ from xtuner.engine.runner import TrainLoop
19
+ from xtuner.model import SupervisedFinetune
20
+ from xtuner.utils import PROMPT_TEMPLATE, SYSTEM_TEMPLATE
21
+
22
+ #######################################################################
23
+ # PART 1 Settings #
24
+ #######################################################################
25
+ # Model
26
+ pretrained_model_name_or_path = '/root/lanyun-tmp/ZhipuAI/chatglm3-6b'
27
+ use_varlen_attn = False
28
+
29
+ # Data
30
+ data_path = '/root/lanyun-tmp/Dataset/Xtuner_Read_Comperhension50k.jsonl'
31
+ prompt_template = PROMPT_TEMPLATE.chatglm3
32
+ max_length = 512
33
+ pack_to_max_length = True
34
+
35
+ # Scheduler & Optimizer
36
+ batch_size = 1 # per_device
37
+ accumulative_counts = 16
38
+ dataloader_num_workers = 0
39
+ max_epochs = 3
40
+ optim_type = AdamW
41
+ lr = 2e-4
42
+ betas = (0.9, 0.999)
43
+ weight_decay = 0
44
+ max_norm = 1 # grad clip
45
+ warmup_ratio = 0.03
46
+
47
+ # Save
48
+ save_steps = 500
49
+ save_total_limit = 2 # Maximum checkpoints to keep (-1 means unlimited)
50
+
51
+ # Evaluate the generation performance during the training
52
+ evaluation_freq = 500
53
+ SYSTEM = SYSTEM_TEMPLATE.alpaca
54
+ evaluation_inputs = [
55
+ "{'context': {'[DOC] [TLE] Belltown Pub - Seattle BoozeBelltown Pub - Seattle Booze [PAR] Trivia [PAR] Booze [PAR] (Q) \\xa0What popular drink did a Dutch medical professor produce in his laboratory while trying to come up with a blood cleanser that could be sold in drugstores? [PAR] (Q) Gin.'}, 'question': {'What popular drink did a Dutch medical professor produce in his laboratory while trying to come up with a blood cleanser that could be sold in drugstores?'}}", 'Please tell me five scenic spots in Shanghai', "{'context': {\"( See ! I ' m working on not being so damn shy ! ) I got in and got excellent seats . I think I was on the 3rd row , almost directly in front of Michael Rosenbaum !\"}, 'question': {'What sort of behavior type do they tend to possess ?'}, 'answer0': {'They tend to sit near the back of lectures'}, 'answer1': {'They tend to avoid sitting near the front'}, 'answer2': {'None of the above choices .'}, 'answer3': {'They tend to be a very shy person'}}"
56
+
57
+ ]
58
+
59
+ #######################################################################
60
+ # PART 2 Model & Tokenizer #
61
+ #######################################################################
62
+ tokenizer = dict(
63
+ type=AutoTokenizer.from_pretrained,
64
+ pretrained_model_name_or_path=pretrained_model_name_or_path,
65
+ trust_remote_code=True,
66
+ encode_special_tokens=True,
67
+ padding_side='left')
68
+
69
+ model = dict(
70
+ type=SupervisedFinetune,
71
+ use_varlen_attn=use_varlen_attn,
72
+ llm=dict(
73
+ type=AutoModelForCausalLM.from_pretrained,
74
+ pretrained_model_name_or_path=pretrained_model_name_or_path,
75
+ trust_remote_code=True,
76
+ torch_dtype=torch.float16,
77
+ quantization_config=dict(
78
+ type=BitsAndBytesConfig,
79
+ load_in_4bit=True,
80
+ load_in_8bit=False,
81
+ llm_int8_threshold=6.0,
82
+ llm_int8_has_fp16_weight=False,
83
+ bnb_4bit_compute_dtype=torch.float16,
84
+ bnb_4bit_use_double_quant=True,
85
+ bnb_4bit_quant_type='nf4')),
86
+ lora=dict(
87
+ type=LoraConfig,
88
+ r=64,
89
+ lora_alpha=16,
90
+ lora_dropout=0.1,
91
+ bias='none',
92
+ task_type='CAUSAL_LM'))
93
+
94
+ #######################################################################
95
+ # PART 3 Dataset & Dataloader #
96
+ #######################################################################
97
+ alpaca_en = dict(
98
+ type=process_hf_dataset,
99
+ dataset=dict(type=load_dataset,path='json',data_files=dict(train=data_path)),
100
+ tokenizer=tokenizer,
101
+ max_length=max_length,
102
+ dataset_map_fn=None,
103
+ template_map_fn=dict(
104
+ type=template_map_fn_factory, template=prompt_template),
105
+ remove_unused_columns=True,
106
+ shuffle_before_pack=True,
107
+ pack_to_max_length=pack_to_max_length,
108
+ use_varlen_attn=use_varlen_attn)
109
+
110
+ train_dataloader = dict(
111
+ batch_size=batch_size,
112
+ num_workers=dataloader_num_workers,
113
+ dataset=alpaca_en,
114
+ sampler=dict(type=DefaultSampler, shuffle=True),
115
+ collate_fn=dict(type=default_collate_fn, use_varlen_attn=use_varlen_attn))
116
+
117
+ #######################################################################
118
+ # PART 4 Scheduler & Optimizer #
119
+ #######################################################################
120
+ # optimizer
121
+ optim_wrapper = dict(
122
+ type=AmpOptimWrapper,
123
+ optimizer=dict(
124
+ type=optim_type, lr=lr, betas=betas, weight_decay=weight_decay),
125
+ clip_grad=dict(max_norm=max_norm, error_if_nonfinite=False),
126
+ accumulative_counts=accumulative_counts,
127
+ loss_scale='dynamic',
128
+ dtype='float16')
129
+
130
+ # learning policy
131
+ # More information: https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/param_scheduler.md # noqa: E501
132
+ param_scheduler = [
133
+ dict(
134
+ type=LinearLR,
135
+ start_factor=1e-5,
136
+ by_epoch=True,
137
+ begin=0,
138
+ end=warmup_ratio * max_epochs,
139
+ convert_to_iter_based=True),
140
+ dict(
141
+ type=CosineAnnealingLR,
142
+ eta_min=0.0,
143
+ by_epoch=True,
144
+ begin=warmup_ratio * max_epochs,
145
+ end=max_epochs,
146
+ convert_to_iter_based=True)
147
+ ]
148
+
149
+ # train, val, test setting
150
+ train_cfg = dict(type=TrainLoop, max_epochs=max_epochs)
151
+
152
+ #######################################################################
153
+ # PART 5 Runtime #
154
+ #######################################################################
155
+ # Log the dialogue periodically during the training process, optional
156
+ custom_hooks = [
157
+ dict(type=DatasetInfoHook, tokenizer=tokenizer),
158
+ dict(
159
+ type=EvaluateChatHook,
160
+ tokenizer=tokenizer,
161
+ every_n_iters=evaluation_freq,
162
+ evaluation_inputs=evaluation_inputs,
163
+ system=SYSTEM,
164
+ prompt_template=prompt_template)
165
+ ]
166
+
167
+ if use_varlen_attn:
168
+ custom_hooks += [dict(type=VarlenAttnArgsToMessageHubHook)]
169
+
170
+ # configure default hooks
171
+ default_hooks = dict(
172
+ # record the time of every iteration.
173
+ timer=dict(type=IterTimerHook),
174
+ # print log every 10 iterations.
175
+ logger=dict(type=LoggerHook, log_metric_by_epoch=False, interval=10),
176
+ # enable the parameter scheduler.
177
+ param_scheduler=dict(type=ParamSchedulerHook),
178
+ # save checkpoint per `save_steps`.
179
+ checkpoint=dict(
180
+ type=CheckpointHook,
181
+ by_epoch=False,
182
+ interval=save_steps,
183
+ max_keep_ckpts=save_total_limit),
184
+ # set sampler seed in distributed evrionment.
185
+ sampler_seed=dict(type=DistSamplerSeedHook),
186
+ )
187
+
188
+ # configure environment
189
+ env_cfg = dict(
190
+ # whether to enable cudnn benchmark
191
+ cudnn_benchmark=False,
192
+ # set multi process parameters
193
+ mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0),
194
+ # set distributed parameters
195
+ dist_cfg=dict(backend='nccl'),
196
+ )
197
+
198
+ # set visualizer
199
+ visualizer = None
200
+
201
+ # set log level
202
+ log_level = 'INFO'
203
+
204
+ # load from which checkpoint
205
+ load_from = None
206
+
207
+ # whether to resume training from the loaded checkpoint
208
+ resume = False
209
+
210
+ # Defaults to use random seed and disable `deterministic`
211
+ randomness = dict(seed=None, deterministic=False)
212
+
213
+ # set log processor
214
+ log_processor = dict(by_epoch=False)