Franso commited on
Commit
bdf64ba
·
verified ·
1 Parent(s): fa7fe7a

Upload model

Browse files
README.md ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags: []
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
+ This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
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]
config.json ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "DockGenModel"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_dockgen.DockGenConfig",
9
+ "AutoModelForCausalLM": "modeling_dockgen.DockGenModel"
10
+ },
11
+ "head_dim": 128,
12
+ "hidden_act": "silu",
13
+ "hidden_size": 1024,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 3072,
16
+ "layer_types": [
17
+ "full_attention",
18
+ "full_attention",
19
+ "full_attention",
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention"
45
+ ],
46
+ "max_position_embeddings": 40960,
47
+ "max_window_layers": 28,
48
+ "mm_token_id": 151655,
49
+ "model_type": "dockgen",
50
+ "num_attention_heads": 16,
51
+ "num_hidden_layers": 28,
52
+ "num_key_value_heads": 8,
53
+ "prot_embedding_dim": 320,
54
+ "rms_norm_eps": 1e-06,
55
+ "rope_scaling": null,
56
+ "rope_theta": 1000000,
57
+ "sliding_window": null,
58
+ "torch_dtype": "float32",
59
+ "transformers_version": "4.53.1",
60
+ "use_cache": true,
61
+ "use_sliding_window": false,
62
+ "vocab_size": 151936
63
+ }
configuration_dockgen.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Optional
2
+
3
+ from transformers.models.qwen3 import Qwen3Config
4
+
5
+
6
+ class DockGenConfig(Qwen3Config):
7
+ model_type = "dockgen"
8
+ keys_to_ignore_at_inference = ["past_key_values"]
9
+
10
+ # Default tensor parallel plan for base model `Qwen3`
11
+ base_model_tp_plan = {
12
+ "layers.*.self_attn.q_proj": "colwise",
13
+ "layers.*.self_attn.k_proj": "colwise",
14
+ "layers.*.self_attn.v_proj": "colwise",
15
+ "layers.*.self_attn.o_proj": "rowwise",
16
+ "layers.*.mlp.gate_proj": "colwise",
17
+ "layers.*.mlp.up_proj": "colwise",
18
+ "layers.*.mlp.down_proj": "rowwise",
19
+ }
20
+ base_model_pp_plan = {
21
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
22
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
23
+ "norm": (["hidden_states"], ["hidden_states"]),
24
+ }
25
+
26
+ def __init__(
27
+ self,
28
+ prot_embedding_dim: int = 1024,
29
+ mm_token_id: int = 151655,
30
+ vocab_size: int = 151936,
31
+ hidden_size: int = 4096,
32
+ intermediate_size: int = 22016,
33
+ num_hidden_layers: int = 32,
34
+ num_attention_heads: int = 32,
35
+ num_key_value_heads: int = 32,
36
+ head_dim: int = 128,
37
+ hidden_act: str = "silu",
38
+ max_position_embeddings: int = 32768,
39
+ initializer_range: float = 0.02,
40
+ rms_norm_eps: float = 1e-6,
41
+ use_cache: bool = True,
42
+ tie_word_embeddings: bool = True,
43
+ rope_theta: float = 10000.0,
44
+ rope_scaling: Optional[float] = None,
45
+ attention_bias: bool = False,
46
+ use_sliding_window: bool = False,
47
+ sliding_window: int = 4096,
48
+ max_window_layers: int = 28,
49
+ layer_types: Optional[str] = None,
50
+ attention_dropout: float = 0.0,
51
+ **kwargs: Any,
52
+ ):
53
+ self.prot_embedding_dim = prot_embedding_dim
54
+ self.mm_token_id = mm_token_id
55
+ super().__init__(
56
+ vocab_size=vocab_size,
57
+ hidden_size=hidden_size,
58
+ intermediate_size=intermediate_size,
59
+ num_hidden_layers=num_hidden_layers,
60
+ num_attention_heads=num_attention_heads,
61
+ num_key_value_heads=num_key_value_heads,
62
+ head_dim=head_dim,
63
+ hidden_act=hidden_act,
64
+ max_position_embeddings=max_position_embeddings,
65
+ initializer_range=initializer_range,
66
+ rms_norm_eps=rms_norm_eps,
67
+ use_cache=use_cache,
68
+ tie_word_embeddings=tie_word_embeddings,
69
+ rope_theta=rope_theta,
70
+ rope_scaling=rope_scaling,
71
+ attention_bias=attention_bias,
72
+ use_sliding_window=use_sliding_window,
73
+ sliding_window=sliding_window,
74
+ max_window_layers=max_window_layers,
75
+ layer_types=layer_types,
76
+ attention_dropout=attention_dropout,
77
+ **kwargs,
78
+ )
79
+
80
+ @classmethod
81
+ def from_qwen3_config(
82
+ cls,
83
+ qwen3_config: Qwen3Config,
84
+ prot_embedding_dim: int = 1024,
85
+ mm_token_id: int = 151655,
86
+ **kwargs: Any,
87
+ ) -> "DockGenConfig":
88
+ """Create a DockGenConfig from a Qwen3Config."""
89
+ return cls(
90
+ prot_embedding_dim=prot_embedding_dim,
91
+ mm_token_id=mm_token_id,
92
+ vocab_size=qwen3_config.vocab_size,
93
+ hidden_size=qwen3_config.hidden_size,
94
+ intermediate_size=qwen3_config.intermediate_size,
95
+ num_hidden_layers=qwen3_config.num_hidden_layers,
96
+ num_attention_heads=qwen3_config.num_attention_heads,
97
+ num_key_value_heads=qwen3_config.num_key_value_heads,
98
+ head_dim=qwen3_config.head_dim,
99
+ hidden_act=qwen3_config.hidden_act,
100
+ max_position_embeddings=qwen3_config.max_position_embeddings,
101
+ initializer_range=qwen3_config.initializer_range,
102
+ rms_norm_eps=qwen3_config.rms_norm_eps,
103
+ use_cache=qwen3_config.use_cache,
104
+ tie_word_embeddings=qwen3_config.tie_word_embeddings,
105
+ rope_theta=qwen3_config.rope_theta,
106
+ rope_scaling=qwen3_config.rope_scaling,
107
+ attention_bias=qwen3_config.attention_bias,
108
+ use_sliding_window=qwen3_config.use_sliding_window,
109
+ sliding_window=qwen3_config.sliding_window,
110
+ max_window_layers=qwen3_config.max_window_layers,
111
+ layer_types=qwen3_config.layer_types,
112
+ attention_dropout=qwen3_config.attention_dropout,
113
+ **kwargs,
114
+ )
generation_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "transformers_version": "4.53.1"
4
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7051d7005cd5d718bf463396d07f0a71be4987d1ef31c70905280268dfd8de1e
3
+ size 3007880032
modeling_dockgen.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Optional
2
+
3
+ import torch
4
+ from torch import nn
5
+ from transformers.modeling_outputs import (
6
+ CausalLMOutputWithPast,
7
+ )
8
+ from transformers.models.qwen3.modeling_qwen3 import (
9
+ KwargsForCausalLM,
10
+ Qwen3ForCausalLM,
11
+ Qwen3Model,
12
+ )
13
+ from transformers.processing_utils import Unpack
14
+
15
+ from .configuration_dockgen import DockGenConfig
16
+
17
+
18
+ class DockGenModelBase(Qwen3Model):
19
+ config_class = DockGenConfig
20
+
21
+ def __init__(self, config: DockGenConfig) -> None:
22
+ super().__init__(config)
23
+
24
+ @classmethod
25
+ def from_language_model(cls, language_model: Qwen3Model) -> "DockGenModelBase":
26
+ """Create a DockGenModelBase from a Qwen3Model."""
27
+ base_model = language_model
28
+ dock_gen_config = DockGenConfig.from_qwen3_config(
29
+ language_model.config,
30
+ )
31
+ model = cls(dock_gen_config)
32
+ model.load_state_dict(base_model.state_dict(), strict=True)
33
+ return model
34
+
35
+
36
+ class DockGenModel(Qwen3ForCausalLM):
37
+ config_class = DockGenConfig
38
+
39
+ _tied_weights_keys = ["lm_head.weight"]
40
+ _tp_plan = {"lm_head": "colwise_rep"}
41
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
42
+
43
+ def __init__(self, config: DockGenConfig) -> None:
44
+ super(Qwen3ForCausalLM, self).__init__(config)
45
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
46
+ self.model = DockGenModelBase(config)
47
+ self.vocab_size = config.vocab_size
48
+ self.aligner = nn.Linear(
49
+ self.config.prot_embedding_dim, self.config.hidden_size, bias=True
50
+ )
51
+ self.post_init()
52
+
53
+ def get_multimodal_embeddings(
54
+ self, pixel_values: Optional[torch.Tensor]
55
+ ) -> torch.Tensor:
56
+ if pixel_values is None:
57
+ return None
58
+ # Run multimodal inputs through encoder and projector
59
+ embeddings = self.aligner(pixel_values)
60
+ return embeddings
61
+
62
+ def get_input_embed_embeddings(
63
+ self,
64
+ input_ids: torch.Tensor,
65
+ multimodal_embeddings: Optional[Any] = None,
66
+ ) -> torch.Tensor:
67
+ # `get_input_embeddings` should already be implemented for the language
68
+ # model as one of the requirements of basic vLLM model implementation.
69
+ inputs_embeds = self.model.embed_tokens(input_ids)
70
+
71
+ if multimodal_embeddings is not None:
72
+ if input_ids is None:
73
+ special_mm_mask = inputs_embeds == self.get_input_embeddings()(
74
+ torch.tensor(
75
+ self.config.mm_token_id,
76
+ dtype=torch.long,
77
+ device=inputs_embeds.device,
78
+ )
79
+ )
80
+ special_mm_mask = special_mm_mask.all(-1)
81
+ else:
82
+ special_mm_mask = input_ids == self.config.mm_token_id
83
+
84
+ special_mm_mask = (
85
+ special_mm_mask.unsqueeze(-1)
86
+ .expand_as(inputs_embeds)
87
+ .to(inputs_embeds.device)
88
+ )
89
+ assert special_mm_mask.all(-1).sum() == multimodal_embeddings.shape[0], (
90
+ "The number of multimodal embeddings should match the number of "
91
+ "special multimodal tokens in the input_ids."
92
+ )
93
+ inputs_embeds = inputs_embeds.masked_scatter(
94
+ special_mm_mask, multimodal_embeddings
95
+ )
96
+
97
+ return inputs_embeds
98
+
99
+ def forward(
100
+ self,
101
+ input_ids: Optional[torch.LongTensor] = None,
102
+ pixel_values: Optional[torch.FloatTensor] = None,
103
+ inputs_embeds: Optional[torch.FloatTensor] = None,
104
+ labels: Optional[torch.LongTensor] = None,
105
+ logits_to_keep: Optional[int] = None,
106
+ **kwargs: Unpack[KwargsForCausalLM],
107
+ ) -> CausalLMOutputWithPast:
108
+ if inputs_embeds is None:
109
+ multimodal_embeddings = self.get_multimodal_embeddings(pixel_values)
110
+ inputs_embeds = self.get_input_embed_embeddings(
111
+ input_ids=input_ids, multimodal_embeddings=multimodal_embeddings
112
+ )
113
+ return super().forward(
114
+ inputs_embeds=inputs_embeds,
115
+ labels=labels,
116
+ logits_to_keep=logits_to_keep,
117
+ **kwargs,
118
+ )
119
+
120
+ @classmethod
121
+ def from_language_model(
122
+ cls,
123
+ language_model: Qwen3ForCausalLM,
124
+ prot_embedding_dim: int = 1024,
125
+ mm_token_id: int = 151655,
126
+ ) -> "DockGenModel":
127
+ """Create a DockGenModel from a Qwen3ForCausalLM model."""
128
+ base_model = DockGenModelBase.from_language_model(language_model.model)
129
+
130
+ dock_gen_config = DockGenConfig.from_qwen3_config(
131
+ language_model.config,
132
+ prot_embedding_dim=prot_embedding_dim,
133
+ )
134
+ model = cls(dock_gen_config)
135
+ model.model = base_model
136
+ return model