Upload folder using huggingface_hub
Browse files- README.md +7 -7
- modeling_intern_vit.py +6 -12
README.md
CHANGED
@@ -179,7 +179,7 @@ model = AutoModel.from_pretrained(
|
|
179 |
trust_remote_code=True).eval().cuda()
|
180 |
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)
|
181 |
|
182 |
-
generation_config = dict(max_new_tokens=1024, do_sample=
|
183 |
question = 'Hello, who are you?'
|
184 |
response, history = model.chat(tokenizer, None, question, generation_config, history=None, return_history=True)
|
185 |
print(f'User: {question}')
|
@@ -210,7 +210,7 @@ image_processor = CLIPImageProcessor.from_pretrained(path)
|
|
210 |
image = Image.open('./examples/image2.jpg').resize((448, 448))
|
211 |
pixel_values = image_processor(images=image, return_tensors='pt').pixel_values.to(torch.bfloat16).cuda()
|
212 |
|
213 |
-
generation_config = dict(max_new_tokens=1024, do_sample=
|
214 |
question = '<image>\nPlease describe the image shortly.'
|
215 |
response = model.chat(tokenizer, pixel_values, question, generation_config)
|
216 |
print(f'User: {question}')
|
@@ -236,7 +236,7 @@ image_processor = CLIPImageProcessor.from_pretrained(path)
|
|
236 |
image = Image.open('./examples/image2.jpg').resize((448, 448))
|
237 |
pixel_values = image_processor(images=image, return_tensors='pt').pixel_values.to(torch.bfloat16).cuda()
|
238 |
|
239 |
-
generation_config = dict(max_new_tokens=1024, do_sample=
|
240 |
question = '<image>\nPlease describe the image in detail.'
|
241 |
response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=None, return_history=True)
|
242 |
print(f'User: {question}')
|
@@ -272,7 +272,7 @@ image2 = Image.open('./examples/image2.jpg').resize((448, 448))
|
|
272 |
pixel_values2 = image_processor(images=image2, return_tensors='pt').pixel_values.to(torch.bfloat16).cuda()
|
273 |
pixel_values = torch.cat((pixel_values1, pixel_values2), dim=0)
|
274 |
|
275 |
-
generation_config = dict(max_new_tokens=1024, do_sample=
|
276 |
question = '<image>\nDescribe the two images in detail.'
|
277 |
response, history = model.chat(tokenizer, pixel_values, question, generation_config,
|
278 |
history=None, return_history=True)
|
@@ -311,7 +311,7 @@ pixel_values2 = image_processor(images=image2, return_tensors='pt').pixel_values
|
|
311 |
pixel_values = torch.cat((pixel_values1, pixel_values2), dim=0)
|
312 |
num_patches_list = [pixel_values1.size(0), pixel_values2.size(0)]
|
313 |
|
314 |
-
generation_config = dict(max_new_tokens=1024, do_sample=
|
315 |
question = 'Image-1: <image>\nImage-2: <image>\nDescribe the two images in detail.'
|
316 |
response, history = model.chat(tokenizer, pixel_values, question, generation_config,
|
317 |
num_patches_list=num_patches_list, history=None, return_history=True)
|
@@ -348,7 +348,7 @@ pixel_values2 = image_processor(images=image2, return_tensors='pt').pixel_values
|
|
348 |
pixel_values = torch.cat((pixel_values1, pixel_values2), dim=0)
|
349 |
num_patches_list = [pixel_values1.size(0), pixel_values2.size(0)]
|
350 |
|
351 |
-
generation_config = dict(max_new_tokens=1024, do_sample=
|
352 |
questions = ['<image>\nDescribe the image in detail.'] * len(num_patches_list)
|
353 |
responses = model.batch_chat(tokenizer, pixel_values,
|
354 |
num_patches_list=num_patches_list,
|
@@ -410,7 +410,7 @@ model = AutoModel.from_pretrained(
|
|
410 |
trust_remote_code=True).eval().cuda()
|
411 |
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)
|
412 |
|
413 |
-
generation_config = dict(max_new_tokens=1024, do_sample=
|
414 |
|
415 |
video_path = './examples/red-panda.mp4'
|
416 |
pixel_values, num_patches_list = load_video(video_path, num_segments=8)
|
|
|
179 |
trust_remote_code=True).eval().cuda()
|
180 |
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)
|
181 |
|
182 |
+
generation_config = dict(max_new_tokens=1024, do_sample=True)
|
183 |
question = 'Hello, who are you?'
|
184 |
response, history = model.chat(tokenizer, None, question, generation_config, history=None, return_history=True)
|
185 |
print(f'User: {question}')
|
|
|
210 |
image = Image.open('./examples/image2.jpg').resize((448, 448))
|
211 |
pixel_values = image_processor(images=image, return_tensors='pt').pixel_values.to(torch.bfloat16).cuda()
|
212 |
|
213 |
+
generation_config = dict(max_new_tokens=1024, do_sample=True)
|
214 |
question = '<image>\nPlease describe the image shortly.'
|
215 |
response = model.chat(tokenizer, pixel_values, question, generation_config)
|
216 |
print(f'User: {question}')
|
|
|
236 |
image = Image.open('./examples/image2.jpg').resize((448, 448))
|
237 |
pixel_values = image_processor(images=image, return_tensors='pt').pixel_values.to(torch.bfloat16).cuda()
|
238 |
|
239 |
+
generation_config = dict(max_new_tokens=1024, do_sample=True)
|
240 |
question = '<image>\nPlease describe the image in detail.'
|
241 |
response, history = model.chat(tokenizer, pixel_values, question, generation_config, history=None, return_history=True)
|
242 |
print(f'User: {question}')
|
|
|
272 |
pixel_values2 = image_processor(images=image2, return_tensors='pt').pixel_values.to(torch.bfloat16).cuda()
|
273 |
pixel_values = torch.cat((pixel_values1, pixel_values2), dim=0)
|
274 |
|
275 |
+
generation_config = dict(max_new_tokens=1024, do_sample=True)
|
276 |
question = '<image>\nDescribe the two images in detail.'
|
277 |
response, history = model.chat(tokenizer, pixel_values, question, generation_config,
|
278 |
history=None, return_history=True)
|
|
|
311 |
pixel_values = torch.cat((pixel_values1, pixel_values2), dim=0)
|
312 |
num_patches_list = [pixel_values1.size(0), pixel_values2.size(0)]
|
313 |
|
314 |
+
generation_config = dict(max_new_tokens=1024, do_sample=True)
|
315 |
question = 'Image-1: <image>\nImage-2: <image>\nDescribe the two images in detail.'
|
316 |
response, history = model.chat(tokenizer, pixel_values, question, generation_config,
|
317 |
num_patches_list=num_patches_list, history=None, return_history=True)
|
|
|
348 |
pixel_values = torch.cat((pixel_values1, pixel_values2), dim=0)
|
349 |
num_patches_list = [pixel_values1.size(0), pixel_values2.size(0)]
|
350 |
|
351 |
+
generation_config = dict(max_new_tokens=1024, do_sample=True)
|
352 |
questions = ['<image>\nDescribe the image in detail.'] * len(num_patches_list)
|
353 |
responses = model.batch_chat(tokenizer, pixel_values,
|
354 |
num_patches_list=num_patches_list,
|
|
|
410 |
trust_remote_code=True).eval().cuda()
|
411 |
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)
|
412 |
|
413 |
+
generation_config = dict(max_new_tokens=1024, do_sample=True)
|
414 |
|
415 |
video_path = './examples/red-panda.mp4'
|
416 |
pixel_values, num_patches_list = load_video(video_path, num_segments=8)
|
modeling_intern_vit.py
CHANGED
@@ -20,18 +20,12 @@ from transformers.utils import logging
|
|
20 |
from .configuration_intern_vit import InternVisionConfig
|
21 |
|
22 |
try:
|
23 |
-
try: # v1
|
24 |
-
from flash_attn.flash_attn_interface import \
|
25 |
-
flash_attn_unpadded_qkvpacked_func
|
26 |
-
except: # v2
|
27 |
-
from flash_attn.flash_attn_interface import \
|
28 |
-
flash_attn_varlen_qkvpacked_func as flash_attn_unpadded_qkvpacked_func
|
29 |
-
|
30 |
from flash_attn.bert_padding import pad_input, unpad_input
|
31 |
-
|
|
|
32 |
has_flash_attn = True
|
33 |
except:
|
34 |
-
print('
|
35 |
has_flash_attn = False
|
36 |
|
37 |
logger = logging.get_logger(__name__)
|
@@ -74,7 +68,7 @@ class FlashAttention(nn.Module):
|
|
74 |
max_s = seqlen
|
75 |
cu_seqlens = torch.arange(0, (batch_size + 1) * seqlen, step=seqlen, dtype=torch.int32,
|
76 |
device=qkv.device)
|
77 |
-
output =
|
78 |
qkv, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,
|
79 |
softmax_scale=self.softmax_scale, causal=causal
|
80 |
)
|
@@ -84,7 +78,7 @@ class FlashAttention(nn.Module):
|
|
84 |
x = rearrange(qkv, 'b s three h d -> b s (three h d)')
|
85 |
x_unpad, indices, cu_seqlens, max_s = unpad_input(x, key_padding_mask)
|
86 |
x_unpad = rearrange(x_unpad, 'nnz (three h d) -> nnz three h d', three=3, h=nheads)
|
87 |
-
output_unpad =
|
88 |
x_unpad, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,
|
89 |
softmax_scale=self.softmax_scale, causal=causal
|
90 |
)
|
@@ -93,7 +87,7 @@ class FlashAttention(nn.Module):
|
|
93 |
'b s (h d) -> b s h d', h=nheads)
|
94 |
else:
|
95 |
assert max_s is not None
|
96 |
-
output =
|
97 |
qkv, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,
|
98 |
softmax_scale=self.softmax_scale, causal=causal
|
99 |
)
|
|
|
20 |
from .configuration_intern_vit import InternVisionConfig
|
21 |
|
22 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
from flash_attn.bert_padding import pad_input, unpad_input
|
24 |
+
from flash_attn.flash_attn_interface import \
|
25 |
+
flash_attn_varlen_qkvpacked_func
|
26 |
has_flash_attn = True
|
27 |
except:
|
28 |
+
print('FlashAttention2 is not installed.')
|
29 |
has_flash_attn = False
|
30 |
|
31 |
logger = logging.get_logger(__name__)
|
|
|
68 |
max_s = seqlen
|
69 |
cu_seqlens = torch.arange(0, (batch_size + 1) * seqlen, step=seqlen, dtype=torch.int32,
|
70 |
device=qkv.device)
|
71 |
+
output = flash_attn_varlen_qkvpacked_func(
|
72 |
qkv, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,
|
73 |
softmax_scale=self.softmax_scale, causal=causal
|
74 |
)
|
|
|
78 |
x = rearrange(qkv, 'b s three h d -> b s (three h d)')
|
79 |
x_unpad, indices, cu_seqlens, max_s = unpad_input(x, key_padding_mask)
|
80 |
x_unpad = rearrange(x_unpad, 'nnz (three h d) -> nnz three h d', three=3, h=nheads)
|
81 |
+
output_unpad = flash_attn_varlen_qkvpacked_func(
|
82 |
x_unpad, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,
|
83 |
softmax_scale=self.softmax_scale, causal=causal
|
84 |
)
|
|
|
87 |
'b s (h d) -> b s h d', h=nheads)
|
88 |
else:
|
89 |
assert max_s is not None
|
90 |
+
output = flash_attn_varlen_qkvpacked_func(
|
91 |
qkv, cu_seqlens, max_s, self.dropout_p if self.training else 0.0,
|
92 |
softmax_scale=self.softmax_scale, causal=causal
|
93 |
)
|