Upload 2 files
Browse files- modeling_internvl_chat.py +0 -2
- modeling_qwen.py +3 -2
modeling_internvl_chat.py
CHANGED
|
@@ -26,8 +26,6 @@ weight_tensor = torch.Tensor([5.,4.,3.,2.,1.])
|
|
| 26 |
|
| 27 |
def get_special_token(tokenizer):
|
| 28 |
preferential_ids_ = [id_[-1] for id_ in tokenizer(special_words)["input_ids"]]
|
| 29 |
-
print(preferential_ids_)
|
| 30 |
-
print(tokenizer.batch_decode(preferential_ids_))
|
| 31 |
return preferential_ids_
|
| 32 |
|
| 33 |
|
|
|
|
| 26 |
|
| 27 |
def get_special_token(tokenizer):
|
| 28 |
preferential_ids_ = [id_[-1] for id_ in tokenizer(special_words)["input_ids"]]
|
|
|
|
|
|
|
| 29 |
return preferential_ids_
|
| 30 |
|
| 31 |
|
modeling_qwen.py
CHANGED
|
@@ -2,6 +2,7 @@ from transformers.models.qwen2.modeling_qwen2 import *
|
|
| 2 |
from transformers.modeling_outputs import dataclass, ModelOutput
|
| 3 |
import torch.nn as nn
|
| 4 |
import torch.nn.init as init
|
|
|
|
| 5 |
|
| 6 |
@dataclass
|
| 7 |
class CausalLMOutputWithPastAndScore(ModelOutput):
|
|
@@ -113,8 +114,7 @@ class Expert_Head(nn.Module):
|
|
| 113 |
|
| 114 |
pooled_expert_scores = torch.cat([pooled_scores2[:,:5], pooled_scores3, pooled_scores2[:,5:], pooled_scores4, expert_scores], dim=1)
|
| 115 |
|
| 116 |
-
return pooled_expert_scores
|
| 117 |
-
|
| 118 |
|
| 119 |
class Qwen2ForCausalLM_score(Qwen2ForCausalLM):
|
| 120 |
_tied_weights_keys = ["lm_head.weight", "regression_head.weight"]
|
|
@@ -200,6 +200,7 @@ class Qwen2ForCausalLM_score(Qwen2ForCausalLM):
|
|
| 200 |
logits = self.lm_head(hidden_states[:, -num_logits_to_keep:, :])
|
| 201 |
|
| 202 |
scores = self.lm_regression_head(hidden_states)
|
|
|
|
| 203 |
|
| 204 |
if input_ids is not None:
|
| 205 |
batch_size = input_ids.shape[0]
|
|
|
|
| 2 |
from transformers.modeling_outputs import dataclass, ModelOutput
|
| 3 |
import torch.nn as nn
|
| 4 |
import torch.nn.init as init
|
| 5 |
+
import torch.nn.functional as F
|
| 6 |
|
| 7 |
@dataclass
|
| 8 |
class CausalLMOutputWithPastAndScore(ModelOutput):
|
|
|
|
| 114 |
|
| 115 |
pooled_expert_scores = torch.cat([pooled_scores2[:,:5], pooled_scores3, pooled_scores2[:,5:], pooled_scores4, expert_scores], dim=1)
|
| 116 |
|
| 117 |
+
return F.sigmoid(pooled_expert_scores)
|
|
|
|
| 118 |
|
| 119 |
class Qwen2ForCausalLM_score(Qwen2ForCausalLM):
|
| 120 |
_tied_weights_keys = ["lm_head.weight", "regression_head.weight"]
|
|
|
|
| 200 |
logits = self.lm_head(hidden_states[:, -num_logits_to_keep:, :])
|
| 201 |
|
| 202 |
scores = self.lm_regression_head(hidden_states)
|
| 203 |
+
scores = F.sigmoid(scores)
|
| 204 |
|
| 205 |
if input_ids is not None:
|
| 206 |
batch_size = input_ids.shape[0]
|