Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
fad15fba
Unverified
Commit
fad15fba
authored
Jul 26, 2024
by
Raushan Turganbay
Committed by
GitHub
Jul 26, 2024
Browse files
Llava: generate without images (#32183)
* llava w/o images * tests
parent
4ab33c2d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
3 deletions
+16
-3
src/transformers/models/llava/processing_llava.py
src/transformers/models/llava/processing_llava.py
+3
-3
tests/models/llava/test_modeling_llava.py
tests/models/llava/test_modeling_llava.py
+13
-0
No files found.
src/transformers/models/llava/processing_llava.py
View file @
fad15fba
...
...
@@ -104,14 +104,14 @@ class LlavaProcessor(ProcessorMixin):
- **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
"""
if
images
is
not
None
:
pixel_value
s
=
self
.
image_processor
(
images
,
return_tensors
=
return_tensors
)
[
"pixel_values"
]
image_input
s
=
self
.
image_processor
(
images
,
return_tensors
=
return_tensors
)
else
:
pixel_values
=
None
image_inputs
=
{}
text_inputs
=
self
.
tokenizer
(
text
,
return_tensors
=
return_tensors
,
padding
=
padding
,
truncation
=
truncation
,
max_length
=
max_length
)
return
BatchFeature
(
data
=
{
**
text_inputs
,
"pixel_values"
:
pixel_value
s
})
return
BatchFeature
(
data
=
{
**
text_inputs
,
**
image_input
s
})
# Copied from transformers.models.clip.processing_clip.CLIPProcessor.batch_decode with CLIP->Llama
def
batch_decode
(
self
,
*
args
,
**
kwargs
):
...
...
tests/models/llava/test_modeling_llava.py
View file @
fad15fba
...
...
@@ -458,3 +458,16 @@ class LlavaForConditionalGenerationIntegrationTest(unittest.TestCase):
EXPECTED_OUTPUT
=
[
'<|im_start|>'
,
'system'
,
'
\n
'
,
'Answer'
,
'▁the'
,
'▁questions'
,
'.'
,
'<|im_end|>'
,
'<|im_start|>'
,
'user'
,
'
\n
'
,
'<image>'
,
'
\n
'
,
'What'
,
'▁is'
,
'▁shown'
,
'▁in'
,
'▁this'
,
'▁image'
,
'?'
,
'<|im_end|>'
,
'<|im_start|>'
,
'ass'
,
'istant'
,
'
\n
'
]
# fmt: skip
self
.
assertEqual
(
slow_tokenizer
.
tokenize
(
prompt
),
EXPECTED_OUTPUT
)
self
.
assertEqual
(
fast_tokenizer
.
tokenize
(
prompt
),
EXPECTED_OUTPUT
)
@
slow
@
require_bitsandbytes
def
test_generation_no_images
(
self
):
model_id
=
"llava-hf/llava-1.5-7b-hf"
model
=
LlavaForConditionalGeneration
.
from_pretrained
(
model_id
,
load_in_4bit
=
True
)
processor
=
AutoProcessor
.
from_pretrained
(
model_id
)
# Prepare inputs with no images
inputs
=
processor
(
"Hello, I am"
,
return_tensors
=
"pt"
).
to
(
torch_device
)
# Make sure that `generate` works
_
=
model
.
generate
(
**
inputs
,
max_new_tokens
=
20
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment