Geralt-Targaryen commited on
Commit
e8e1a4c
·
verified ·
1 Parent(s): 6f77431

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* 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
 
 
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
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "C2LLMForEmbedding"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "attn_implementation": "flash_attention_2",
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_c2llm.C2LLMConfig",
9
+ "AutoModel": "modeling_c2llm.C2LLMForEmbedding"
10
+ },
11
+ "compressed_dim": 3584,
12
+ "embedding_method": "pma",
13
+ "hidden_act": "silu",
14
+ "hidden_size": 3584,
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 18944,
17
+ "max_position_embeddings": 32768,
18
+ "max_window_layers": 28,
19
+ "model_type": "c2llm",
20
+ "num_attention_heads": 28,
21
+ "num_hidden_layers": 28,
22
+ "num_key_value_heads": 4,
23
+ "padding_side": "left",
24
+ "pma_ln": true,
25
+ "pma_norm": false,
26
+ "pma_norm_mode": "post_normal",
27
+ "pma_num_heads": 32,
28
+ "rms_norm_eps": 1e-06,
29
+ "rope_theta": 1000000.0,
30
+ "sliding_window": null,
31
+ "tie_word_embeddings": false,
32
+ "tokenizer_name_or_path": "codefuse-ai/C2LLM-7B",
33
+ "torch_dtype": "bfloat16",
34
+ "transformers_version": "4.51.3",
35
+ "use_cache": true,
36
+ "use_sliding_window": false,
37
+ "vocab_size": 152064
38
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "prompts": {
3
+ "query": "Given a query from a web search, retrieve code that is helpful in addressing the query.\n",
4
+ "document": "Retrieved Answer:"
5
+ },
6
+ "default_prompt_name": null,
7
+ "similarity_fn_name": "cosine"
8
+ }
configuration_c2llm.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+ class C2LLMConfig(PretrainedConfig):
4
+ model_type = "c2llm"
5
+ keys_to_ignore_at_inference = ["past_key_values"]
6
+
7
+ base_model_tp_plan = {
8
+ "layers.*.self_attn.q_proj": "colwise",
9
+ "layers.*.self_attn.k_proj": "colwise",
10
+ "layers.*.self_attn.v_proj": "colwise",
11
+ "layers.*.self_attn.o_proj": "rowwise",
12
+ "layers.*.mlp.gate_proj": "colwise",
13
+ "layers.*.mlp.up_proj": "colwise",
14
+ "layers.*.mlp.down_proj": "rowwise",
15
+ }
16
+ base_model_pp_plan = {
17
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
18
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
19
+ "norm": (["hidden_states"], ["hidden_states"]),
20
+ }
21
+
22
+
23
+ def __init__(
24
+ self,
25
+ attention_dropout=0.0,
26
+ bos_token_id=151643,
27
+ eos_token_id=151645,
28
+ hidden_act="silu",
29
+ hidden_size=3584,
30
+ initializer_range=0.02,
31
+ intermediate_size=18944,
32
+ max_position_embeddings=32768,
33
+ max_window_layers=28,
34
+ model_type="c2llm",
35
+ num_attention_heads=28,
36
+ num_hidden_layers=28,
37
+ num_key_value_heads=4,
38
+ rms_norm_eps=1e-6,
39
+ rope_theta=1000000.0,
40
+ sliding_window=131072,
41
+ tie_word_embeddings=False,
42
+ torch_dtype="bfloat16",
43
+ transformers_version="4.43.1",
44
+ use_cache=True,
45
+ use_sliding_window=False,
46
+ vocab_size=152064,
47
+ **kwargs,
48
+ ):
49
+ self.vocab_size = vocab_size
50
+ self.max_position_embeddings = max_position_embeddings
51
+ self.hidden_size = hidden_size
52
+ self.intermediate_size = intermediate_size
53
+ self.num_hidden_layers = num_hidden_layers
54
+ self.num_attention_heads = num_attention_heads
55
+ self.use_sliding_window = use_sliding_window
56
+ self.sliding_window = sliding_window if use_sliding_window else None
57
+ self.max_window_layers = max_window_layers
58
+
59
+ # for backward compatibility
60
+ if num_key_value_heads is None:
61
+ num_key_value_heads = num_attention_heads
62
+
63
+ self.num_key_value_heads = num_key_value_heads
64
+ self.hidden_act = hidden_act
65
+ self.initializer_range = initializer_range
66
+ self.rms_norm_eps = rms_norm_eps
67
+ self.use_cache = use_cache
68
+ self.rope_theta = rope_theta
69
+ self.attention_dropout = attention_dropout
70
+
71
+ super().__init__(
72
+ tie_word_embeddings=tie_word_embeddings,
73
+ **kwargs,
74
+ )
75
+ def to_dict(self):
76
+ output = super().to_dict()
77
+
78
+ keys_to_remove = [
79
+ "base_model"
80
+ ]
81
+
82
+ for key in keys_to_remove:
83
+ output.pop(key, None)
84
+
85
+ return output
86
+
87
+ __all__ = ["C2LLMConfig"]
custom_transformer.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import inspect
4
+ import logging
5
+ import os
6
+ from collections.abc import Callable
7
+ from pathlib import Path
8
+ from typing import TYPE_CHECKING, Any
9
+
10
+ from sentence_transformers.backend import load_onnx_model, load_openvino_model
11
+
12
+ try:
13
+ from typing import Self
14
+ except ImportError:
15
+ from typing_extensions import Self
16
+
17
+ import torch
18
+ from transformers import AutoConfig, AutoModel, AutoTokenizer, MT5Config, PretrainedConfig, T5Config
19
+ from transformers.utils.import_utils import is_peft_available
20
+ from transformers.utils.peft_utils import find_adapter_config_file
21
+
22
+ from sentence_transformers.models.InputModule import InputModule
23
+
24
+ logger = logging.getLogger(__name__)
25
+
26
+ if TYPE_CHECKING and is_peft_available():
27
+ from peft import PeftConfig
28
+ from sentence_transformers.models import Transformer
29
+
30
+
31
+ class C2LLMTransformer(Transformer):
32
+ config_file_name: str = "sentence_bert_config.json"
33
+ config_keys: list[str] = ["max_seq_length", "do_lower_case"]
34
+ save_in_root: bool = True
35
+
36
+
37
+ def forward(self, features: dict[str, torch.Tensor], **kwargs) -> dict[str, torch.Tensor]:
38
+ trans_features = {key: value for key, value in features.items() if key in self.model_forward_params}
39
+
40
+ outputs = self.auto_model(**trans_features, **kwargs, return_dict=True)
41
+
42
+ sentence_embedding = outputs["sentence_embedding"]
43
+ features["sentence_embedding"] = sentence_embedding
44
+
45
+ return features
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2766a6d5a6f3a0c00676b1705aa971928704f4b408456dbbaef0642f5d20bc9b
3
+ size 4330866320
model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d7113672e683e2af68b90adaeb06e102f242a773af8c96e70a8d2da5d3ea8c44
3
+ size 1192821112
model.safetensors.index.json ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 15334057984
4
+ },
5
+ "weight_map": {
6
+ "mha_pma_disc.S": "model-00004-of-00004.safetensors",
7
+ "mha_pma_disc.mab.fc_k.bias": "model-00004-of-00004.safetensors",
8
+ "mha_pma_disc.mab.fc_k.weight": "model-00004-of-00004.safetensors",
9
+ "mha_pma_disc.mab.fc_o.bias": "model-00004-of-00004.safetensors",
10
+ "mha_pma_disc.mab.fc_o.weight": "model-00004-of-00004.safetensors",
11
+ "mha_pma_disc.mab.fc_q.bias": "model-00004-of-00004.safetensors",
12
+ "mha_pma_disc.mab.fc_q.weight": "model-00004-of-00004.safetensors",
13
+ "mha_pma_disc.mab.fc_v.bias": "model-00004-of-00004.safetensors",
14
+ "mha_pma_disc.mab.fc_v.weight": "model-00004-of-00004.safetensors",
15
+ "mha_pma_disc.mab.ln0.bias": "model-00004-of-00004.safetensors",
16
+ "mha_pma_disc.mab.ln0.weight": "model-00004-of-00004.safetensors",
17
+ "mha_pma_disc.mab.ln1.bias": "model-00004-of-00004.safetensors",
18
+ "mha_pma_disc.mab.ln1.weight": "model-00004-of-00004.safetensors",
19
+ "plm_model.lm_head.weight": "model-00004-of-00004.safetensors",
20
+ "plm_model.model.embed_tokens.weight": "model-00001-of-00004.safetensors",
21
+ "plm_model.model.layers.0.input_layernorm.weight": "model-00001-of-00004.safetensors",
22
+ "plm_model.model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
23
+ "plm_model.model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
24
+ "plm_model.model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
25
+ "plm_model.model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
26
+ "plm_model.model.layers.0.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
27
+ "plm_model.model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
28
+ "plm_model.model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
29
+ "plm_model.model.layers.0.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
30
+ "plm_model.model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
31
+ "plm_model.model.layers.0.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
32
+ "plm_model.model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
33
+ "plm_model.model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
34
+ "plm_model.model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
35
+ "plm_model.model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
36
+ "plm_model.model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
37
+ "plm_model.model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
38
+ "plm_model.model.layers.1.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
39
+ "plm_model.model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
40
+ "plm_model.model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
41
+ "plm_model.model.layers.1.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
42
+ "plm_model.model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
43
+ "plm_model.model.layers.1.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
44
+ "plm_model.model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
45
+ "plm_model.model.layers.10.input_layernorm.weight": "model-00002-of-00004.safetensors",
46
+ "plm_model.model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
47
+ "plm_model.model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
48
+ "plm_model.model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
49
+ "plm_model.model.layers.10.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
50
+ "plm_model.model.layers.10.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
51
+ "plm_model.model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
52
+ "plm_model.model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
53
+ "plm_model.model.layers.10.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
54
+ "plm_model.model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
55
+ "plm_model.model.layers.10.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
56
+ "plm_model.model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
57
+ "plm_model.model.layers.11.input_layernorm.weight": "model-00002-of-00004.safetensors",
58
+ "plm_model.model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
59
+ "plm_model.model.layers.11.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
60
+ "plm_model.model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
61
+ "plm_model.model.layers.11.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
62
+ "plm_model.model.layers.11.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
63
+ "plm_model.model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
64
+ "plm_model.model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
65
+ "plm_model.model.layers.11.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
66
+ "plm_model.model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
67
+ "plm_model.model.layers.11.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
68
+ "plm_model.model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
69
+ "plm_model.model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors",
70
+ "plm_model.model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
71
+ "plm_model.model.layers.12.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
72
+ "plm_model.model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
73
+ "plm_model.model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
74
+ "plm_model.model.layers.12.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
75
+ "plm_model.model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
76
+ "plm_model.model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
77
+ "plm_model.model.layers.12.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
78
+ "plm_model.model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
79
+ "plm_model.model.layers.12.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
80
+ "plm_model.model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
81
+ "plm_model.model.layers.13.input_layernorm.weight": "model-00002-of-00004.safetensors",
82
+ "plm_model.model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
83
+ "plm_model.model.layers.13.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
84
+ "plm_model.model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
85
+ "plm_model.model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
86
+ "plm_model.model.layers.13.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
87
+ "plm_model.model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
88
+ "plm_model.model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
89
+ "plm_model.model.layers.13.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
90
+ "plm_model.model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
91
+ "plm_model.model.layers.13.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
92
+ "plm_model.model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
93
+ "plm_model.model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
94
+ "plm_model.model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
95
+ "plm_model.model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
96
+ "plm_model.model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
97
+ "plm_model.model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
98
+ "plm_model.model.layers.14.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
99
+ "plm_model.model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
100
+ "plm_model.model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
101
+ "plm_model.model.layers.14.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
102
+ "plm_model.model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
103
+ "plm_model.model.layers.14.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
104
+ "plm_model.model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
105
+ "plm_model.model.layers.15.input_layernorm.weight": "model-00002-of-00004.safetensors",
106
+ "plm_model.model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
107
+ "plm_model.model.layers.15.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
108
+ "plm_model.model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
109
+ "plm_model.model.layers.15.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
110
+ "plm_model.model.layers.15.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
111
+ "plm_model.model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
112
+ "plm_model.model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
113
+ "plm_model.model.layers.15.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
114
+ "plm_model.model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
115
+ "plm_model.model.layers.15.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
116
+ "plm_model.model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
117
+ "plm_model.model.layers.16.input_layernorm.weight": "model-00002-of-00004.safetensors",
118
+ "plm_model.model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
119
+ "plm_model.model.layers.16.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
120
+ "plm_model.model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
121
+ "plm_model.model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
122
+ "plm_model.model.layers.16.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
123
+ "plm_model.model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
124
+ "plm_model.model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
125
+ "plm_model.model.layers.16.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
126
+ "plm_model.model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
127
+ "plm_model.model.layers.16.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
128
+ "plm_model.model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
129
+ "plm_model.model.layers.17.input_layernorm.weight": "model-00002-of-00004.safetensors",
130
+ "plm_model.model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
131
+ "plm_model.model.layers.17.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
132
+ "plm_model.model.layers.17.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
133
+ "plm_model.model.layers.17.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
134
+ "plm_model.model.layers.17.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
135
+ "plm_model.model.layers.17.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
136
+ "plm_model.model.layers.17.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
137
+ "plm_model.model.layers.17.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
138
+ "plm_model.model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
139
+ "plm_model.model.layers.17.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
140
+ "plm_model.model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
141
+ "plm_model.model.layers.18.input_layernorm.weight": "model-00003-of-00004.safetensors",
142
+ "plm_model.model.layers.18.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
143
+ "plm_model.model.layers.18.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
144
+ "plm_model.model.layers.18.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
145
+ "plm_model.model.layers.18.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
146
+ "plm_model.model.layers.18.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
147
+ "plm_model.model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
148
+ "plm_model.model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
149
+ "plm_model.model.layers.18.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
150
+ "plm_model.model.layers.18.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
151
+ "plm_model.model.layers.18.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
152
+ "plm_model.model.layers.18.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
153
+ "plm_model.model.layers.19.input_layernorm.weight": "model-00003-of-00004.safetensors",
154
+ "plm_model.model.layers.19.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
155
+ "plm_model.model.layers.19.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
156
+ "plm_model.model.layers.19.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
157
+ "plm_model.model.layers.19.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
158
+ "plm_model.model.layers.19.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
159
+ "plm_model.model.layers.19.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
160
+ "plm_model.model.layers.19.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
161
+ "plm_model.model.layers.19.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
162
+ "plm_model.model.layers.19.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
163
+ "plm_model.model.layers.19.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
164
+ "plm_model.model.layers.19.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
165
+ "plm_model.model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
166
+ "plm_model.model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
167
+ "plm_model.model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
168
+ "plm_model.model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
169
+ "plm_model.model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
170
+ "plm_model.model.layers.2.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
171
+ "plm_model.model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
172
+ "plm_model.model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
173
+ "plm_model.model.layers.2.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
174
+ "plm_model.model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
175
+ "plm_model.model.layers.2.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
176
+ "plm_model.model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
177
+ "plm_model.model.layers.20.input_layernorm.weight": "model-00003-of-00004.safetensors",
178
+ "plm_model.model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
179
+ "plm_model.model.layers.20.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
180
+ "plm_model.model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
181
+ "plm_model.model.layers.20.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
182
+ "plm_model.model.layers.20.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
183
+ "plm_model.model.layers.20.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
184
+ "plm_model.model.layers.20.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
185
+ "plm_model.model.layers.20.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
186
+ "plm_model.model.layers.20.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
187
+ "plm_model.model.layers.20.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
188
+ "plm_model.model.layers.20.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
189
+ "plm_model.model.layers.21.input_layernorm.weight": "model-00003-of-00004.safetensors",
190
+ "plm_model.model.layers.21.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
191
+ "plm_model.model.layers.21.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
192
+ "plm_model.model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
193
+ "plm_model.model.layers.21.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
194
+ "plm_model.model.layers.21.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
195
+ "plm_model.model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
196
+ "plm_model.model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
197
+ "plm_model.model.layers.21.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
198
+ "plm_model.model.layers.21.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
199
+ "plm_model.model.layers.21.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
200
+ "plm_model.model.layers.21.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
201
+ "plm_model.model.layers.22.input_layernorm.weight": "model-00003-of-00004.safetensors",
202
+ "plm_model.model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
203
+ "plm_model.model.layers.22.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
204
+ "plm_model.model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
205
+ "plm_model.model.layers.22.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
206
+ "plm_model.model.layers.22.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
207
+ "plm_model.model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
208
+ "plm_model.model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
209
+ "plm_model.model.layers.22.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
210
+ "plm_model.model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
211
+ "plm_model.model.layers.22.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
212
+ "plm_model.model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
213
+ "plm_model.model.layers.23.input_layernorm.weight": "model-00003-of-00004.safetensors",
214
+ "plm_model.model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
215
+ "plm_model.model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
216
+ "plm_model.model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
217
+ "plm_model.model.layers.23.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
218
+ "plm_model.model.layers.23.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
219
+ "plm_model.model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
220
+ "plm_model.model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
221
+ "plm_model.model.layers.23.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
222
+ "plm_model.model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
223
+ "plm_model.model.layers.23.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
224
+ "plm_model.model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
225
+ "plm_model.model.layers.24.input_layernorm.weight": "model-00003-of-00004.safetensors",
226
+ "plm_model.model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
227
+ "plm_model.model.layers.24.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
228
+ "plm_model.model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
229
+ "plm_model.model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
230
+ "plm_model.model.layers.24.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
231
+ "plm_model.model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
232
+ "plm_model.model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
233
+ "plm_model.model.layers.24.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
234
+ "plm_model.model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
235
+ "plm_model.model.layers.24.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
236
+ "plm_model.model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
237
+ "plm_model.model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
238
+ "plm_model.model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
239
+ "plm_model.model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
240
+ "plm_model.model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
241
+ "plm_model.model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
242
+ "plm_model.model.layers.25.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
243
+ "plm_model.model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
244
+ "plm_model.model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
245
+ "plm_model.model.layers.25.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
246
+ "plm_model.model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
247
+ "plm_model.model.layers.25.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
248
+ "plm_model.model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
249
+ "plm_model.model.layers.26.input_layernorm.weight": "model-00003-of-00004.safetensors",
250
+ "plm_model.model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
251
+ "plm_model.model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
252
+ "plm_model.model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
253
+ "plm_model.model.layers.26.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
254
+ "plm_model.model.layers.26.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
255
+ "plm_model.model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
256
+ "plm_model.model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
257
+ "plm_model.model.layers.26.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
258
+ "plm_model.model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
259
+ "plm_model.model.layers.26.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
260
+ "plm_model.model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
261
+ "plm_model.model.layers.27.input_layernorm.weight": "model-00003-of-00004.safetensors",
262
+ "plm_model.model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
263
+ "plm_model.model.layers.27.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
264
+ "plm_model.model.layers.27.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
265
+ "plm_model.model.layers.27.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
266
+ "plm_model.model.layers.27.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
267
+ "plm_model.model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
268
+ "plm_model.model.layers.27.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
269
+ "plm_model.model.layers.27.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
270
+ "plm_model.model.layers.27.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
271
+ "plm_model.model.layers.27.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
272
+ "plm_model.model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
273
+ "plm_model.model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors",
274
+ "plm_model.model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
275
+ "plm_model.model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
276
+ "plm_model.model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
277
+ "plm_model.model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
278
+ "plm_model.model.layers.3.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
279
+ "plm_model.model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
280
+ "plm_model.model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
281
+ "plm_model.model.layers.3.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
282
+ "plm_model.model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
283
+ "plm_model.model.layers.3.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
284
+ "plm_model.model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
285
+ "plm_model.model.layers.4.input_layernorm.weight": "model-00001-of-00004.safetensors",
286
+ "plm_model.model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
287
+ "plm_model.model.layers.4.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
288
+ "plm_model.model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
289
+ "plm_model.model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
290
+ "plm_model.model.layers.4.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
291
+ "plm_model.model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
292
+ "plm_model.model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
293
+ "plm_model.model.layers.4.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
294
+ "plm_model.model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
295
+ "plm_model.model.layers.4.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
296
+ "plm_model.model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
297
+ "plm_model.model.layers.5.input_layernorm.weight": "model-00001-of-00004.safetensors",
298
+ "plm_model.model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
299
+ "plm_model.model.layers.5.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
300
+ "plm_model.model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
301
+ "plm_model.model.layers.5.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
302
+ "plm_model.model.layers.5.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
303
+ "plm_model.model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
304
+ "plm_model.model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
305
+ "plm_model.model.layers.5.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
306
+ "plm_model.model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
307
+ "plm_model.model.layers.5.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
308
+ "plm_model.model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
309
+ "plm_model.model.layers.6.input_layernorm.weight": "model-00001-of-00004.safetensors",
310
+ "plm_model.model.layers.6.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
311
+ "plm_model.model.layers.6.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
312
+ "plm_model.model.layers.6.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
313
+ "plm_model.model.layers.6.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
314
+ "plm_model.model.layers.6.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
315
+ "plm_model.model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
316
+ "plm_model.model.layers.6.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
317
+ "plm_model.model.layers.6.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
318
+ "plm_model.model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
319
+ "plm_model.model.layers.6.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
320
+ "plm_model.model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
321
+ "plm_model.model.layers.7.input_layernorm.weight": "model-00001-of-00004.safetensors",
322
+ "plm_model.model.layers.7.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
323
+ "plm_model.model.layers.7.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
324
+ "plm_model.model.layers.7.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
325
+ "plm_model.model.layers.7.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
326
+ "plm_model.model.layers.7.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
327
+ "plm_model.model.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
328
+ "plm_model.model.layers.7.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
329
+ "plm_model.model.layers.7.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
330
+ "plm_model.model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
331
+ "plm_model.model.layers.7.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
332
+ "plm_model.model.layers.7.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
333
+ "plm_model.model.layers.8.input_layernorm.weight": "model-00002-of-00004.safetensors",
334
+ "plm_model.model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
335
+ "plm_model.model.layers.8.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
336
+ "plm_model.model.layers.8.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
337
+ "plm_model.model.layers.8.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
338
+ "plm_model.model.layers.8.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
339
+ "plm_model.model.layers.8.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
340
+ "plm_model.model.layers.8.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
341
+ "plm_model.model.layers.8.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
342
+ "plm_model.model.layers.8.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
343
+ "plm_model.model.layers.8.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
344
+ "plm_model.model.layers.8.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
345
+ "plm_model.model.layers.9.input_layernorm.weight": "model-00002-of-00004.safetensors",
346
+ "plm_model.model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
347
+ "plm_model.model.layers.9.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
348
+ "plm_model.model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
349
+ "plm_model.model.layers.9.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
350
+ "plm_model.model.layers.9.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
351
+ "plm_model.model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
352
+ "plm_model.model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
353
+ "plm_model.model.layers.9.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
354
+ "plm_model.model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
355
+ "plm_model.model.layers.9.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
356
+ "plm_model.model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
357
+ "plm_model.model.norm.weight": "model-00003-of-00004.safetensors"
358
+ }
359
+ }
modeling_c2llm.py ADDED
@@ -0,0 +1,641 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gc
3
+ import inspect
4
+ import math
5
+ import multiprocessing as mp
6
+ import queue
7
+ from multiprocessing import Queue
8
+ import warnings
9
+ from typing import Any, Union, List, Dict, Literal, Optional
10
+ import torch
11
+ import torch.nn.functional as F
12
+ import torch.utils.checkpoint
13
+ from torch import nn
14
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
15
+ from transformers import PretrainedConfig
16
+
17
+ from transformers import Qwen2Config
18
+ from transformers.activations import ACT2FN
19
+ from transformers.cache_utils import Cache, DynamicCache
20
+ from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask, _prepare_4d_causal_attention_mask_for_sdpa, _prepare_4d_attention_mask, _prepare_4d_attention_mask_for_sdpa
21
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast
22
+ from transformers.modeling_utils import PreTrainedModel
23
+ from transformers.utils import (
24
+ add_start_docstrings,
25
+ add_start_docstrings_to_model_forward,
26
+ is_flash_attn_2_available,
27
+ is_flash_attn_greater_or_equal_2_10,
28
+ logging,
29
+ replace_return_docstrings,
30
+ )
31
+ import numpy as np
32
+ from transformers import Qwen2Config
33
+ from transformers import Qwen2ForCausalLM
34
+ import inspect
35
+ import math
36
+ import os
37
+ import warnings
38
+ from typing import List, Optional, Tuple, Union
39
+ from tqdm import tqdm, trange
40
+ import torch
41
+ import torch.nn.functional as F
42
+ import torch.utils.checkpoint
43
+ from torch import nn
44
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
45
+
46
+ from transformers.activations import ACT2FN
47
+ from transformers.cache_utils import Cache, DynamicCache
48
+ from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask, _prepare_4d_causal_attention_mask_for_sdpa, _prepare_4d_attention_mask, _prepare_4d_attention_mask_for_sdpa
49
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast
50
+ from transformers.modeling_utils import PreTrainedModel
51
+ from transformers.utils import (
52
+ add_start_docstrings,
53
+ add_start_docstrings_to_model_forward,
54
+ is_flash_attn_2_available,
55
+ is_flash_attn_greater_or_equal_2_10,
56
+ logging,
57
+ replace_return_docstrings,
58
+ )
59
+ import numpy as np
60
+ import torch
61
+ import os
62
+ import argparse
63
+ import json
64
+ from tqdm import tqdm
65
+ from typing import cast, List, Union, Tuple
66
+ from transformers import AutoTokenizer, AutoModel # pylint: disable=C0413
67
+ from peft import LoraConfig, get_peft_model, TaskType
68
+ import time
69
+ import torch.nn.functional as F
70
+ import sys
71
+ import time
72
+ import torch
73
+ import torch.nn as nn
74
+ import torch.nn.functional as F
75
+ import numpy as np
76
+ from tqdm import tqdm, trange
77
+ from collections import defaultdict
78
+ from transformers import AutoTokenizer, AutoModel, AutoModelForCausalLM, AutoConfig
79
+ import torch.distributed as dist
80
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
81
+ import sys
82
+ import torch
83
+ import torch.nn as nn
84
+ import torch.nn.functional as F
85
+ import math
86
+ import re
87
+ import logging
88
+ logging.getLogger().setLevel(logging.INFO)
89
+ from .configuration_c2llm import C2LLMConfig
90
+ from transformers.models.qwen2.modeling_qwen2 import Qwen2DecoderLayer, Qwen2Attention
91
+
92
+ class MAB_POST(nn.Module):
93
+ def __init__(self, dim_Q, dim_K, dim_V, num_heads, ln=False):
94
+ super(MAB_POST, self).__init__()
95
+ self.dim_V = dim_V
96
+ self.num_heads = num_heads
97
+ self.fc_q = nn.Linear(dim_Q, dim_V)
98
+ self.fc_k = nn.Linear(dim_K, dim_V)
99
+ self.fc_v = nn.Linear(dim_K, dim_V)
100
+ if ln:
101
+ self.ln0 = nn.LayerNorm(dim_V)
102
+ self.ln1 = nn.LayerNorm(dim_V)
103
+ self.fc_o = nn.Linear(dim_V, dim_V)
104
+ nn.init.xavier_uniform_(self.fc_q.weight)
105
+ nn.init.xavier_uniform_(self.fc_k.weight)
106
+ nn.init.xavier_uniform_(self.fc_v.weight)
107
+ nn.init.xavier_uniform_(self.fc_o.weight)
108
+
109
+ def forward(self, Q, K, pad_mask=None):
110
+
111
+ Q_ = self.fc_q(Q)
112
+ K_, V_ = self.fc_k(K), self.fc_v(K)
113
+
114
+ dim_split = self.dim_V // self.num_heads
115
+ Q_ = torch.cat(Q_.split(dim_split, 2), 0)
116
+ K_ = torch.cat(K_.split(dim_split, 2), 0)
117
+ V_ = torch.cat(V_.split(dim_split, 2), 0)
118
+
119
+ pad_mask = pad_mask.unsqueeze(1).repeat(self.num_heads, Q.size(1), 1)
120
+ score = Q_.bmm(K_.transpose(1,2))/math.sqrt(self.dim_V)
121
+ score = score.masked_fill(pad_mask == 0, -1e12)
122
+ A = torch.softmax(score, 2)
123
+ A = A * pad_mask
124
+ O = torch.cat(A.bmm(V_).split(Q.size(0), 0), 2)
125
+ O = Q + O
126
+ O = O if getattr(self, 'ln0', None) is None else self.ln0(O)
127
+ O = O + F.relu(self.fc_o(O))
128
+ O = O if getattr(self, 'ln1', None) is None else self.ln1(O)
129
+ return O
130
+
131
+
132
+ class PMA(nn.Module):
133
+ def __init__(self, dim, compressed_dim, num_heads, num_seeds, ln=False, pma_mode=None):
134
+ super(PMA, self).__init__()
135
+ self.S = nn.Parameter(torch.Tensor(1, num_seeds, compressed_dim))
136
+ nn.init.xavier_uniform_(self.S)
137
+ if pma_mode == 'post_normal':
138
+ self.mab = MAB_POST(compressed_dim, dim, compressed_dim, num_heads, ln=ln)
139
+ else:
140
+ raise ValueError(f"Error, the pma_mode {pma_mode} is not implemented !")
141
+
142
+ def forward(self, X, pad_mask):
143
+ if self.S.dtype != torch.bfloat16:
144
+ X = X.float()
145
+ return self.mab(self.S.repeat(X.size(0), 1, 1), X, pad_mask)
146
+
147
+
148
+
149
+ class MAB_POST_v2(nn.Module):
150
+ def __init__(self, dim_Q, dim_K, dim_V, num_heads, ln=False):
151
+ super(MAB_POST_v2, self).__init__()
152
+ self.dim_V = dim_V
153
+ self.num_heads = num_heads
154
+ self.fc_q = nn.Linear(dim_Q, dim_V)
155
+ self.fc_k = nn.Linear(dim_K, dim_V)
156
+ self.fc_v = nn.Linear(dim_K, dim_V)
157
+
158
+ if ln:
159
+ self.ln0 = nn.LayerNorm(dim_V)
160
+ self.ln1 = nn.LayerNorm(dim_V)
161
+ self.fc_o = nn.Linear(dim_V, dim_V)
162
+ nn.init.xavier_uniform_(self.fc_q.weight)
163
+ nn.init.xavier_uniform_(self.fc_k.weight)
164
+ nn.init.xavier_uniform_(self.fc_v.weight)
165
+ nn.init.xavier_uniform_(self.fc_o.weight)
166
+
167
+
168
+
169
+ # Q(B, num_seed, D), pad_mask (bs, seq) Post-LN
170
+ def forward(self, Q, K, pad_mask=None):
171
+
172
+ Q_tmp = self.fc_q(Q) # B, num_seed, C
173
+ K_, V_ = self.fc_k(K), self.fc_v(K) # B, L, C
174
+
175
+ dim_split = self.dim_V // self.num_heads
176
+ Q_ = torch.cat(Q_tmp.split(dim_split, 2), 0) # (B* num_head, num_seed, C)
177
+ K_ = torch.cat(K_.split(dim_split, 2), 0) # (B* num_head, L, C)
178
+ V_ = torch.cat(V_.split(dim_split, 2), 0) # (B* num_head,L, C)
179
+
180
+ pad_mask = pad_mask.unsqueeze(1).repeat(self.num_heads, Q.size(1), 1) # (B*num_head, num_seed, L)
181
+ score = Q_.bmm(K_.transpose(1,2))/math.sqrt(self.dim_V) # (B*num_head, num_seed, L)
182
+ score = score.masked_fill(pad_mask == 0, -1e12) # B,num_seed,L
183
+ A = torch.softmax(score, 2) # (B*num_head, num_seed, L)
184
+ A = A * pad_mask
185
+ O = torch.cat(A.bmm(V_).split(Q.size(0), 0), 2) # (B, num_seed, D)
186
+ O = Q_tmp + O
187
+ # O = torch.cat((Q_ + A.bmm(V_)).split(Q.size(0), 0), 2)
188
+ O = O if getattr(self, 'ln0', None) is None else self.ln0(O)
189
+ O = O + F.relu(self.fc_o(O))
190
+ O = O if getattr(self, 'ln1', None) is None else self.ln1(O)
191
+ return O
192
+
193
+
194
+
195
+
196
+ class PMA_v2(nn.Module):
197
+ def __init__(self, dim, compressed_dim, num_heads, num_seeds, ln=False):
198
+ super(PMA_v2, self).__init__()
199
+ self.S = nn.Parameter(torch.Tensor(1, num_seeds, dim))
200
+ nn.init.xavier_uniform_(self.S)
201
+ # if pma_mode == 'post_normal':
202
+ self.mab = MAB_POST_v2(dim, dim, compressed_dim, num_heads, ln=ln)
203
+ # elif pma_mode == 'pre_normal':
204
+ # self.mab = MAB_PRE_NORMAL(dim, dim, compressed_dim, num_heads, ln=ln)
205
+ # elif pma_mode == 'pre_gptj':
206
+ # self.mab = MAB_PRE_GPTJ(dim, dim, compressed_dim, num_heads, ln=ln)
207
+ # else:
208
+ # raise ValueError(f"Error, the pma_mode {pma_mode} is not implemented !")
209
+ # X: (bs, seq, emb), pad_mask: (bs, seq)
210
+ def forward(self, X, pad_mask):
211
+ if self.S.dtype != torch.bfloat16:
212
+ X = X.float()
213
+ return self.mab(self.S.expand(X.size(0), -1, -1), X, pad_mask)
214
+
215
+
216
+ class C2LLMModel(PreTrainedModel):
217
+ config_class = C2LLMConfig
218
+ config: C2LLMConfig
219
+ base_model_prefix = "model"
220
+ supports_gradient_checkpointing = True
221
+ _no_split_modules = ["Qwen2DecoderLayer"]
222
+ _skip_keys_device_placement = ["past_key_values"]
223
+ _supports_flash_attn = True
224
+ _supports_sdpa = True
225
+ _supports_flex_attn = True
226
+
227
+ _can_compile_fullgraph = True
228
+ _supports_attention_backend = True
229
+ _can_record_outputs = {
230
+ "hidden_states": Qwen2DecoderLayer,
231
+ "attentions": Qwen2Attention,
232
+ }
233
+
234
+
235
+ class C2LLMForEmbedding(C2LLMModel):
236
+
237
+ config_class = C2LLMConfig
238
+ model_type = "c2llm"
239
+
240
+ def __init__(self, config):
241
+ super().__init__(config)
242
+ qwen_cfg = Qwen2Config.from_dict(config.to_dict())
243
+ self.plm_model = AutoModelForCausalLM.from_config(qwen_cfg)
244
+ self.embedding_method = config.embedding_method
245
+ self.inf_seq_length = 2048
246
+ self.padding_side = config.padding_side
247
+
248
+ self.emb_dim = self.plm_model.model.embed_tokens.weight.size(1)
249
+ self.keep_max_layer = self.plm_model.config.num_hidden_layers
250
+ self.num_heads = config.pma_num_heads
251
+ self.ln = config.pma_ln
252
+ self.norm = config.pma_norm
253
+ self.pma_mode = config.pma_norm_mode
254
+ self.compressed_dim = config.compressed_dim
255
+
256
+ self.mha_pma_disc = PMA_v2(self.emb_dim, self.compressed_dim, self.num_heads, 1, ln=self.ln)
257
+ self.pool = None
258
+ self.target_devices = self.get_target_devices(None)
259
+ self.tokenizer = AutoTokenizer.from_pretrained(config.tokenizer_name_or_path, padding_side=config.padding_side) if config.tokenizer_name_or_path is not None else None
260
+ self.config_class = C2LLMConfig
261
+
262
+
263
+ def pma_embedding(self, mha_pma, A, mask):
264
+ res = mha_pma(A, mask).squeeze(1)
265
+ return res
266
+
267
+ def get_hidden_states(self, **inputs):
268
+ outputs = self.plm_model(inputs['input_ids'], inputs['attention_mask'], output_hidden_states=True)
269
+ return outputs.hidden_states[self.keep_max_layer]
270
+
271
+ def get_sentence_embedding(self, embedding_method, hidden_states, emb_type, attention_mask):
272
+
273
+
274
+ if embedding_method == 'pma':
275
+
276
+ if emb_type == 'disc':
277
+ res_embedding = self.pma_embedding(self.mha_pma_disc, hidden_states, attention_mask)
278
+ if self.norm:
279
+ res_embedding = torch.nn.functional.normalize(res_embedding, p=2.0, dim=-1, eps=1e-12, out=None)
280
+ return res_embedding
281
+ else:
282
+ raise NotImplementedError(f"emb type {emb_type} hasn't been implemented")
283
+ else:
284
+ raise NotImplementedError(f"embedding method {embedding_method} hasn't been implemented")
285
+
286
+
287
+ @staticmethod
288
+ def get_target_devices(devices: Union[str, int, List[str], List[int]]) -> List[str]:
289
+ """
290
+
291
+ Args:
292
+ devices (Union[str, int, List[str], List[int]]): specified devices, can be `str`, `int`, list of `str`, or list of `int`.
293
+
294
+ Raises:
295
+ ValueError: Devices should be a string or an integer or a list of strings or a list of integers.
296
+
297
+ Returns:
298
+ List[str]: A list of target devices in format.
299
+ """
300
+ if devices is None:
301
+ if torch.cuda.is_available():
302
+ return [f"cuda:{i}" for i in range(torch.cuda.device_count())]
303
+ elif is_torch_npu_available():
304
+ return [f"npu:{i}" for i in range(torch.npu.device_count())]
305
+ elif hasattr(torch, "musa") and torch.musa.is_available():
306
+ return [f"musa:{i}" for i in range(torch.musa.device_count())]
307
+ elif torch.backends.mps.is_available():
308
+ try:
309
+ return [f"mps:{i}" for i in range(torch.mps.device_count())]
310
+ except:
311
+ return ["mps"]
312
+ else:
313
+ return ["cpu"]
314
+ elif isinstance(devices, str):
315
+ return [devices]
316
+ elif isinstance(devices, int):
317
+ if hasattr(torch, "musa") and torch.musa.is_available():
318
+ return [f"musa:{devices}"]
319
+ else:
320
+ return [f"cuda:{devices}"]
321
+ elif isinstance(devices, list):
322
+ if isinstance(devices[0], str):
323
+ return devices
324
+ elif isinstance(devices[0], int):
325
+ if hasattr(torch, "musa") and torch.musa.is_available():
326
+ return [f"musa:{device}" for device in devices]
327
+ else:
328
+ return [f"cuda:{device}" for device in devices]
329
+ else:
330
+ raise ValueError("devices should be a string or an integer or a list of strings or a list of integers.")
331
+ else:
332
+ raise ValueError("devices should be a string or an integer or a list of strings or a list of integers.")
333
+
334
+ # adapted from https://github.com/UKPLab/sentence-transformers/blob/1802076d4eae42ff0a5629e1b04e75785d4e193b/sentence_transformers/SentenceTransformer.py#L807
335
+
336
+
337
+ def start_multi_process_pool(
338
+ self,
339
+ process_target_func: Any,
340
+ ) -> Dict[Literal["input", "output", "processes"], Any]:
341
+ """
342
+ Starts a multi-process pool to process the encoding with several independent processes
343
+ via :meth:`SentenceTransformer.encode_multi_process <sentence_transformers.SentenceTransformer.encode_multi_process>`.
344
+
345
+ This method is recommended if you want to encode on multiple GPUs or CPUs. It is advised
346
+ to start only one process per GPU. This method works together with encode_multi_process
347
+ and stop_multi_process_pool.
348
+
349
+ Returns:
350
+ Dict[str, Any]: A dictionary with the target processes, an input queue, and an output queue.
351
+ """
352
+ if self.plm_model is None or self.mha_pma_disc is None:
353
+ raise ValueError("Model is not initialized.")
354
+
355
+ logging.info("Start multi-process pool on devices: {}".format(", ".join(map(str, self.target_devices))))
356
+
357
+ self.to("cpu")
358
+ self.share_memory()
359
+ ctx = mp.get_context("spawn")
360
+ input_queue = ctx.Queue()
361
+ output_queue = ctx.Queue()
362
+ processes = []
363
+
364
+ for device_id in tqdm(self.target_devices, desc='initial target device'):
365
+ p = ctx.Process(
366
+ target=process_target_func,
367
+ args=(device_id, self, input_queue, output_queue),
368
+ daemon=True,
369
+ )
370
+ p.start()
371
+ processes.append(p)
372
+
373
+ return {"input": input_queue, "output": output_queue, "processes": processes}
374
+
375
+
376
+
377
+ @staticmethod
378
+ def _encode_multi_process_worker(
379
+ target_device: str, model: 'C2LLMForEmbedding', input_queue: Queue, results_queue: Queue
380
+ ) -> None:
381
+ model = model.to(target_device)
382
+ while True:
383
+ try:
384
+ chunk_id, sentences, kwargs = (
385
+ input_queue.get()
386
+ )
387
+ embeddings = model.encode_single_device(
388
+ sentences,
389
+ device=target_device,
390
+ **kwargs
391
+ )
392
+
393
+ results_queue.put([chunk_id, embeddings])
394
+ except queue.Empty:
395
+ break
396
+
397
+ def encode_multi_process(
398
+ self,
399
+ sentences: List[str],
400
+ pool: Dict[Literal["input", "output", "processes"], Any],
401
+ **kwargs
402
+ ):
403
+
404
+ chunk_size = math.ceil(len(sentences) / len(pool["processes"]))
405
+
406
+ input_queue = pool["input"]
407
+ last_chunk_id = 0
408
+ chunk = []
409
+
410
+ for sentence in sentences:
411
+ chunk.append(sentence)
412
+ if len(chunk) >= chunk_size:
413
+ input_queue.put(
414
+ [last_chunk_id, chunk, kwargs]
415
+ )
416
+ last_chunk_id += 1
417
+ chunk = []
418
+
419
+ if len(chunk) > 0:
420
+ input_queue.put([last_chunk_id, chunk, kwargs])
421
+ last_chunk_id += 1
422
+
423
+ output_queue = pool["output"]
424
+ results_list = sorted(
425
+ [output_queue.get() for _ in trange(last_chunk_id, desc="")],
426
+ key=lambda x: x[0],
427
+ )
428
+ embeddings = self._concatenate_results_from_multi_process([result[1] for result in results_list])
429
+ return embeddings
430
+
431
+ def _concatenate_results_from_multi_process(self, results_list: List[Union[torch.Tensor, np.ndarray, Any]]):
432
+ """concatenate and return the results from all the processes
433
+
434
+ Args:
435
+ results_list (List[Union[torch.Tensor, np.ndarray, Any]]): A list of results from all the processes.
436
+
437
+ Raises:
438
+ NotImplementedError: Unsupported type for results_list
439
+
440
+ Returns:
441
+ Union[torch.Tensor, np.ndarray]: return the embedding vectors in a numpy array or tensor.
442
+ """
443
+ if isinstance(results_list[0], torch.Tensor):
444
+ # move all tensors to the same device
445
+ results_list = [res.to(self.target_devices[0]) for res in results_list]
446
+ return torch.cat(results_list, dim=0)
447
+ elif isinstance(results_list[0], np.ndarray):
448
+ return np.concatenate(results_list, axis=0)
449
+ else:
450
+ raise NotImplementedError("Unsupported type for results_list")
451
+
452
+
453
+ def forward(self, input_ids: torch.Tensor, attention_mask: torch.Tensor, return_dict: bool=True, **kwargs):
454
+ outputs = self.plm_model(input_ids, attention_mask, output_hidden_states=True)
455
+ hidden_states = outputs.hidden_states[self.keep_max_layer]
456
+ embeddings = self.get_sentence_embedding(self.embedding_method, hidden_states, 'disc', attention_mask)
457
+ if not return_dict:
458
+ return (embeddings,)
459
+ return {"sentence_embedding": embeddings}
460
+
461
+ def encode_single_device(
462
+ self,
463
+ sentences: Union[List[str], str],
464
+ batch_size: int = 16,
465
+ convert_to_numpy: bool = False,
466
+ convert_to_tensor: bool = True,
467
+ show_progress_bar: bool = True,
468
+ max_seq_length: int = 2048,
469
+ device: Optional[str] = None,
470
+ **kwargs: Any
471
+ ):
472
+ if max_seq_length is None:
473
+ max_seq_length = self.inf_seq_length
474
+
475
+ input_is_string = False
476
+ if isinstance(sentences, str) or not hasattr(sentences, "__len__"):
477
+ sentences = [sentences]
478
+ input_is_string = True
479
+ all_embeddings = []
480
+ length_sorted_idx = np.argsort([-len(s) for s in sentences])
481
+ sentences_sorted = [sentences[idx] for idx in length_sorted_idx] # 大到小重排
482
+ with torch.no_grad():
483
+ for start_index in trange(0, len(sentences), batch_size, desc="Batches", disable=not show_progress_bar):
484
+ sentences_batch = sentences_sorted[start_index: start_index + batch_size]
485
+ inputs = self.tokenizer(sentences_batch, padding=True, truncation=True, max_length=max_seq_length, return_tensors='pt').to(self.plm_model.device)
486
+ hidden_states = self.get_hidden_states(**inputs)
487
+ embeddings = self.get_sentence_embedding(self.embedding_method, hidden_states, 'disc', inputs['attention_mask'])
488
+ embeddings = embeddings.detach()
489
+ if convert_to_numpy:
490
+ if embeddings.dtype == torch.bfloat16:
491
+ embeddings = embeddings.cpu().to(torch.float32)
492
+ else:
493
+ embeddings = embeddings.cpu()
494
+ all_embeddings.extend(embeddings)
495
+ all_embeddings = [all_embeddings[idx] for idx in np.argsort(length_sorted_idx)]
496
+ if convert_to_tensor:
497
+ all_embeddings = torch.stack(all_embeddings)
498
+ elif convert_to_numpy:
499
+ all_embeddings = np.asarray([emb.numpy() for emb in all_embeddings])
500
+
501
+ if input_is_string:
502
+ all_embeddings = all_embeddings[0]
503
+ return all_embeddings
504
+
505
+
506
+ def encode(self, sentences, batch_size=16, convert_to_numpy=False,
507
+ convert_to_tensor=True, show_progress_bar=True, max_seq_length=None, **kwargs):
508
+
509
+ if max_seq_length is None:
510
+ max_seq_length = self.inf_seq_length
511
+
512
+ if convert_to_tensor == convert_to_numpy:
513
+ convert_to_tensor=True
514
+ convert_to_numpy=False
515
+
516
+ if isinstance(sentences, str) or len(self.target_devices) == 1:
517
+ return self.encode_single_device(
518
+ sentences,
519
+ batch_size=batch_size,
520
+ convert_to_numpy=convert_to_numpy,
521
+ convert_to_tensor=convert_to_tensor,
522
+ show_progress_bar=show_progress_bar,
523
+ max_seq_length=max_seq_length,
524
+ device=self.target_devices[0],
525
+ **kwargs
526
+ )
527
+ if self.pool is None:
528
+ self.pool = self.start_multi_process_pool(C2LLMForEmbedding._encode_multi_process_worker)
529
+
530
+
531
+ all_embeddings = []
532
+ length_sorted_idx = np.argsort([-len(s) for s in sentences])
533
+ sentences_sorted = [sentences[idx] for idx in length_sorted_idx] # 大到小重排
534
+ with torch.no_grad():
535
+ for start_index in trange(0, len(sentences), batch_size, desc="Batches", disable=not show_progress_bar):
536
+ sentences_batch = sentences_sorted[start_index: start_index + batch_size]
537
+ embeddings_batch = self.encode_multi_process(
538
+ sentences_batch,
539
+ self.pool,
540
+ convert_to_numpy=convert_to_numpy,
541
+ convert_to_tensor=convert_to_tensor,
542
+ show_progress_bar=show_progress_bar,
543
+ max_seq_length=max_seq_length,
544
+ **kwargs
545
+ )
546
+ embeddings_batch = embeddings_batch.detach()
547
+ if convert_to_numpy:
548
+ if embeddings_batch.dtype == torch.bfloat16:
549
+ embeddings_batch = embeddings_batch.cpu().to(torch.float32)
550
+ else:
551
+ embeddings_batch = embeddings_batch.cpu()
552
+ all_embeddings.extend(embeddings_batch)
553
+ all_embeddings = [all_embeddings[idx] for idx in np.argsort(length_sorted_idx)]
554
+ if convert_to_tensor:
555
+ all_embeddings = torch.stack(all_embeddings)
556
+ elif convert_to_numpy:
557
+ all_embeddings = np.asarray([emb.numpy() for emb in all_embeddings])
558
+
559
+
560
+ return all_embeddings
561
+
562
+
563
+ def encode_queries(self, sentences, batch_size=16, convert_to_numpy=False,
564
+ convert_to_tensor=True, show_progress_bar=True, max_seq_length=None, **kwargs):
565
+ if max_seq_length is None:
566
+ max_seq_length = self.inf_seq_length
567
+
568
+ if convert_to_tensor == convert_to_numpy:
569
+ convert_to_tensor=True
570
+ convert_to_numpy=False
571
+
572
+ return self.encode(
573
+ sentences=sentences,
574
+ batch_size=batch_size,
575
+ convert_to_numpy=convert_to_numpy,
576
+ convert_to_tensor=convert_to_tensor,
577
+ show_progress_bar=show_progress_bar,
578
+ max_seq_length=max_seq_length,
579
+ **kwargs
580
+ )
581
+
582
+
583
+ def encode_corpus(self, sentences, batch_size=16, convert_to_numpy=False,
584
+ convert_to_tensor=True, show_progress_bar=True, max_seq_length=None, **kwargs):
585
+
586
+ if max_seq_length is None:
587
+ max_seq_length = self.inf_seq_length
588
+
589
+ if convert_to_tensor == convert_to_numpy:
590
+ convert_to_tensor=True
591
+ convert_to_numpy=False
592
+ sentences = [sentence['title']+' '+sentence['text'] for sentence in sentences]
593
+
594
+ return self.encode(
595
+ sentences=sentences,
596
+ batch_size=batch_size,
597
+ convert_to_numpy=convert_to_numpy,
598
+ convert_to_tensor=convert_to_tensor,
599
+ show_progress_bar=show_progress_bar,
600
+ max_seq_length=max_seq_length,
601
+ **kwargs
602
+
603
+ )
604
+
605
+ @staticmethod
606
+ def stop_multi_process_pool(pool: Dict[Literal["input", "output", "processes"], Any]) -> None:
607
+ """
608
+ Stops all processes started with start_multi_process_pool.
609
+
610
+ Args:
611
+ pool (Dict[str, object]): A dictionary containing the input queue, output queue, and process list.
612
+
613
+ Returns:
614
+ None
615
+ """
616
+ for p in pool["processes"]:
617
+ p.terminate()
618
+
619
+ for p in pool["processes"]:
620
+ p.join()
621
+ p.close()
622
+
623
+ pool["input"].close()
624
+ pool["output"].close()
625
+ pool = None
626
+
627
+ def stop_self_pool(self):
628
+ if self.pool is not None:
629
+ self.stop_multi_process_pool(self.pool)
630
+ self.pool = None
631
+ try:
632
+ self.model.to('cpu')
633
+ torch.cuda.empty_cache()
634
+ except:
635
+ pass
636
+ if gc is not None and callable(gc.collect):
637
+ gc.collect()
638
+
639
+ def __del__(self):
640
+ self.stop_self_pool()
641
+
modules.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "custom_transformer.C2LLMTransformer"
7
+ }
8
+ ]
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 32768,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
3
+ size 11421896
tokenizer_config.json ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ }
181
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
199
+ "clean_up_tokenization_spaces": false,
200
+ "eos_token": "<|im_end|>",
201
+ "errors": "replace",
202
+ "extra_special_tokens": {},
203
+ "model_max_length": 32768,
204
+ "pad_token": "<|endoftext|>",
205
+ "split_special_tokens": false,
206
+ "tokenizer_class": "Qwen2Tokenizer",
207
+ "unk_token": null
208
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff