fangshengren commited on
Commit
6489805
1 Parent(s): f4fac26

Upload 10 files

Browse files
ChatLM-mini-Chinese/.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
ChatLM-mini-Chinese/README.md ADDED
The diff for this file is too large to render. See raw diff
 
ChatLM-mini-Chinese/config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "./model_save/dpo/",
3
+ "architectures": [
4
+ "TextToTextModel"
5
+ ],
6
+ "auto_map": {
7
+ "AutoModelForSeq2SeqLM": "modeling_chat_model.TextToTextModel"
8
+ },
9
+ "classifier_dropout": 0.0,
10
+ "d_ff": 3072,
11
+ "d_kv": 64,
12
+ "d_model": 768,
13
+ "decoder_start_token_id": 0,
14
+ "dense_act_fn": "relu",
15
+ "dropout_rate": 0.1,
16
+ "eos_token_id": 1,
17
+ "feed_forward_proj": "relu",
18
+ "initializer_factor": 1.0,
19
+ "is_encoder_decoder": true,
20
+ "is_gated_act": false,
21
+ "layer_norm_epsilon": 1e-06,
22
+ "model_type": "t5",
23
+ "num_decoder_layers": 10,
24
+ "num_heads": 12,
25
+ "num_layers": 10,
26
+ "pad_token_id": 0,
27
+ "relative_attention_max_distance": 128,
28
+ "relative_attention_num_buckets": 32,
29
+ "torch_dtype": "float32",
30
+ "transformers_version": "4.36.2",
31
+ "use_cache": true,
32
+ "vocab_size": 29298
33
+ }
ChatLM-mini-Chinese/configuration_chat_model.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ from transformers import T5Config
2
+
3
+ class TextToTextModelConfig(T5Config):
4
+ model_type = 't5'
ChatLM-mini-Chinese/generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "decoder_start_token_id": 0,
4
+ "eos_token_id": 1,
5
+ "pad_token_id": 0,
6
+ "transformers_version": "4.36.2"
7
+ }
ChatLM-mini-Chinese/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:054caeae92bcc13f0b6e7a12f86e75c8e18117279ecd89c4aa1f8ac74c95c02a
3
+ size 750794624
ChatLM-mini-Chinese/modeling_chat_model.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import Tensor, LongTensor
3
+ from transformers import T5ForConditionalGeneration, T5Config
4
+ from transformers import TextIteratorStreamer
5
+ from transformers.generation.configuration_utils import GenerationConfig
6
+
7
+ class TextToTextModel(T5ForConditionalGeneration):
8
+ def __init__(self, config: T5Config) -> None:
9
+ '''
10
+ TextToTextModel继承T5ForConditionalGeneration
11
+ '''
12
+ super().__init__(config)
13
+
14
+ @torch.no_grad()
15
+ def my_generate(self,
16
+ input_ids: LongTensor,
17
+ attention_mask: LongTensor,
18
+ max_seq_len: int=256,
19
+ search_type: str='beam',
20
+ streamer: TextIteratorStreamer=None,
21
+ ) -> Tensor:
22
+ '''
23
+ 自定义gennerate方法方便调用、测试
24
+ search_type: ['greedy', 'beam', 'sampling', 'contrastive', ]
25
+
26
+ - *greedy decoding* by calling [`~generation.GenerationMixin.greedy_search`] if `num_beams=1` and
27
+ `do_sample=False`
28
+ - *contrastive search* by calling [`~generation.GenerationMixin.contrastive_search`] if `penalty_alpha>0.`
29
+ and `top_k>1`
30
+ - *multinomial sampling* by calling [`~generation.GenerationMixin.sample`] if `num_beams=1` and
31
+ `do_sample=True`
32
+ - *beam-search decoding* by calling [`~generation.GenerationMixin.beam_search`] if `num_beams>1` and
33
+ `do_sample=False`
34
+ - *beam-search multinomial sampling* by calling [`~generation.GenerationMixin.beam_sample`] if
35
+ `num_beams>1` and `do_sample=True`
36
+ '''
37
+ generation_config = GenerationConfig()
38
+ generation_config.remove_invalid_values = True
39
+ generation_config.eos_token_id = 1
40
+ generation_config.pad_token_id = 0
41
+ generation_config.decoder_start_token_id = self.config.decoder_start_token_id
42
+ generation_config.max_new_tokens = max_seq_len
43
+ # generation_config.repetition_penalty = 1.1 # 重复词惩罚
44
+
45
+ if search_type == 'greedy':
46
+ generation_config.num_beams = 1
47
+ generation_config.do_sample = False
48
+ elif search_type == 'beam':
49
+ generation_config.top_k = 50
50
+ generation_config.num_beams = 5
51
+ generation_config.do_sample = True
52
+ generation_config.top_p = 0.95
53
+ generation_config.no_repeat_ngram_size = 4
54
+ generation_config.length_penalty = -2.0
55
+ generation_config.early_stopping = True
56
+ elif search_type == 'sampling':
57
+ generation_config.num_beams = 1
58
+ generation_config.do_sample = True
59
+ generation_config.top_k = 50
60
+ generation_config.temperature = 0.98 # 越低概率越趋向于均匀分布
61
+ generation_config.top_p = 0.80
62
+ generation_config.no_repeat_ngram_size = 4
63
+ elif search_type == 'contrastive':
64
+ generation_config.penalty_alpha = 0.5
65
+ generation_config.top_k = 50
66
+
67
+ result = self.generate(
68
+ inputs=input_ids,
69
+ attention_mask=attention_mask,
70
+ generation_config=generation_config,
71
+ streamer=streamer,
72
+ )
73
+
74
+ return result
ChatLM-mini-Chinese/special_tokens_map.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "eos_token": "[EOS]",
3
+ "pad_token": "[PAD]",
4
+ "unk_token": "[UNK]"
5
+ }
ChatLM-mini-Chinese/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
ChatLM-mini-Chinese/tokenizer_config.json ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "[EOS]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "[SEP]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "[BOS]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "4": {
36
+ "content": "[CLS]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "5": {
44
+ "content": "[MASK]",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "6": {
52
+ "content": "[UNK]",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ }
59
+ },
60
+ "clean_up_tokenization_spaces": true,
61
+ "eos_token": "[EOS]",
62
+ "model_max_length": 1000000000000000019884624838656,
63
+ "pad_token": "[PAD]",
64
+ "tokenizer_class": "PreTrainedTokenizerFast",
65
+ "unk_token": "[UNK]"
66
+ }