Update modeling_gpt2vision.py
Browse files- modeling_gpt2vision.py +4 -17
modeling_gpt2vision.py
CHANGED
@@ -2,18 +2,8 @@ import torch
|
|
2 |
import torch.nn as nn
|
3 |
from transformers import PreTrainedModel, AutoTokenizer
|
4 |
from .configuration_gpt2vision import GPT2VisionConfig, GPT2Config
|
5 |
-
import
|
6 |
-
|
7 |
-
print(sys.path)
|
8 |
-
|
9 |
-
try:
|
10 |
-
from .vision_encoder import VisionEncoder
|
11 |
-
except ImportError as e:
|
12 |
-
print(f"Error importing VisionEncoder: {e}")
|
13 |
-
print("Current directory contents:")
|
14 |
-
import os
|
15 |
-
print(os.listdir('./'))
|
16 |
-
|
17 |
|
18 |
|
19 |
IMAGE_TOKEN = "<image>"
|
@@ -22,7 +12,6 @@ ANSWER_EOS = "<|endoftext|>"
|
|
22 |
def resize_token_embeds(model_name="openai-community/gpt2"):
|
23 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
24 |
new_tokens={
|
25 |
-
"pad_token": "<pad>",
|
26 |
"additional_special_tokens": [IMAGE_TOKEN]
|
27 |
}
|
28 |
tokenizer.add_special_tokens(new_tokens)
|
@@ -30,8 +19,6 @@ def resize_token_embeds(model_name="openai-community/gpt2"):
|
|
30 |
|
31 |
tokenizer = resize_token_embeds()
|
32 |
|
33 |
-
|
34 |
-
print("tokenizer",tokenizer)
|
35 |
def create_labels(input_ids, tokenizer, attention_mask):
|
36 |
labels = input_ids.clone()
|
37 |
|
@@ -121,7 +108,7 @@ class GPT2Vision(PreTrainedModel):
|
|
121 |
input_texts,
|
122 |
padding='max_length',
|
123 |
truncation=True,
|
124 |
-
max_length=
|
125 |
return_tensors="pt",
|
126 |
pad_to_multiple_of=8,
|
127 |
).to(device)
|
@@ -178,7 +165,7 @@ class GPT2Vision(PreTrainedModel):
|
|
178 |
inputs_embeds=inputs_embeds,
|
179 |
attention_mask=attention_mask,
|
180 |
max_new_tokens=max_new_tokens,
|
181 |
-
pad_token_id=self.tokenizer.
|
182 |
eos_token_id=self.tokenizer.eos_token_id,
|
183 |
**kwargs
|
184 |
)
|
|
|
2 |
import torch.nn as nn
|
3 |
from transformers import PreTrainedModel, AutoTokenizer
|
4 |
from .configuration_gpt2vision import GPT2VisionConfig, GPT2Config
|
5 |
+
from .vision_encoder import VisionEncoder
|
6 |
+
from .modeling_gpt2 import GPT2LMHeadModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
|
9 |
IMAGE_TOKEN = "<image>"
|
|
|
12 |
def resize_token_embeds(model_name="openai-community/gpt2"):
|
13 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
14 |
new_tokens={
|
|
|
15 |
"additional_special_tokens": [IMAGE_TOKEN]
|
16 |
}
|
17 |
tokenizer.add_special_tokens(new_tokens)
|
|
|
19 |
|
20 |
tokenizer = resize_token_embeds()
|
21 |
|
|
|
|
|
22 |
def create_labels(input_ids, tokenizer, attention_mask):
|
23 |
labels = input_ids.clone()
|
24 |
|
|
|
108 |
input_texts,
|
109 |
padding='max_length',
|
110 |
truncation=True,
|
111 |
+
max_length=768,
|
112 |
return_tensors="pt",
|
113 |
pad_to_multiple_of=8,
|
114 |
).to(device)
|
|
|
165 |
inputs_embeds=inputs_embeds,
|
166 |
attention_mask=attention_mask,
|
167 |
max_new_tokens=max_new_tokens,
|
168 |
+
pad_token_id=self.tokenizer.eos_token_id,
|
169 |
eos_token_id=self.tokenizer.eos_token_id,
|
170 |
**kwargs
|
171 |
)
|