Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
lm-evaluation-harness
Commits
593998e8
"profiler/vscode:/vscode.git/clone" did not exist on "6b6360b107aabe988151eff9150327cd6f54a8db"
Commit
593998e8
authored
Jul 01, 2024
by
haileyschoelkopf
Browse files
fixes
parent
d5195462
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
66 deletions
+12
-66
lm_eval/models/__init__.py
lm_eval/models/__init__.py
+0
-1
lm_eval/models/hf_vlms.py
lm_eval/models/hf_vlms.py
+12
-65
No files found.
lm_eval/models/__init__.py
View file @
593998e8
...
@@ -4,7 +4,6 @@ from . import (
...
@@ -4,7 +4,6 @@ from . import (
gguf
,
gguf
,
hf_vlms
,
hf_vlms
,
huggingface
,
huggingface
,
llava
,
mamba_lm
,
mamba_lm
,
nemo_lm
,
nemo_lm
,
neuralmagic
,
neuralmagic
,
...
...
lm_eval/models/hf_vlms.py
View file @
593998e8
...
@@ -19,65 +19,7 @@ class HFMultimodalLM(HFLM):
...
@@ -19,65 +19,7 @@ class HFMultimodalLM(HFLM):
An abstracted Hugging Face model class for multimodal LMs like Llava and Idefics.
An abstracted Hugging Face model class for multimodal LMs like Llava and Idefics.
"""
"""
AUTO_MODEL_CLASS
=
transformers
.
AutoModelForVision2Seq
AUTO_MODEL_CLASS
=
transformers
.
AutoModelForVision2Seq
# TODO: what's the right way to handle this. maybe phase out the direct class-equality checks in HFLM?
# @property
# def max_length(self):
# raise NotImplementedError
@
property
def
tokenizer_name
(
self
)
->
str
:
return
self
.
processor
.
tokenizer
.
name_or_path
.
replace
(
"/"
,
"__"
)
@
property
def
chat_template
(
self
)
->
str
:
if
self
.
processor
.
tokenizer
.
chat_template
is
not
None
:
return
self
.
processor
.
tokenizer
.
chat_template
return
self
.
processor
.
tokenizer
.
default_chat_template
def
_get_config
(
self
,
pretrained
:
str
,
revision
:
str
=
"main"
,
trust_remote_code
:
bool
=
False
,
)
->
None
:
self
.
_config
=
transformers
.
AutoConfig
.
from_pretrained
(
pretrained
,
revision
=
revision
,
trust_remote_code
=
trust_remote_code
,
)
# def _create_model(
# self,
# pretrained: Union[str, transformers.PreTrainedModel],
# revision="main",
# dtype="auto",
# trust_remote_code=False,
# **kwargs,
# ) -> None:
# """
# Initializes an HF or HF-compatible PreTrainedModel from scratch
# inside HFLM, using the kwargs passed into self.__init__().
# """
# model_kwargs = kwargs if kwargs else {}
# if parallelize:
# # do stuff
# pass
# if isinstance(pretrained, str):
# return self.AUTO_MODEL_CLASS.from_pretrained(
# pretrained,
# revision=revision,
# torch_dtype=get_dtype(dtype),
# trust_remote_code=trust_remote_code,
# **model_kwargs,
# )
# assert isinstance(pretrained, transformers.PreTrainedModel)
# return pretrained
def
_create_tokenizer
(
def
_create_tokenizer
(
self
,
self
,
...
@@ -94,6 +36,9 @@ class HFMultimodalLM(HFLM):
...
@@ -94,6 +36,9 @@ class HFMultimodalLM(HFLM):
)
->
None
:
)
->
None
:
"""
"""
Helper method during initialization.
Helper method during initialization.
For the multimodal variant, we initialize not just
`self.tokenizer` but also `self.processor`.
"""
"""
if
tokenizer
:
if
tokenizer
:
...
@@ -201,10 +146,10 @@ class HFMultimodalLM(HFLM):
...
@@ -201,10 +146,10 @@ class HFMultimodalLM(HFLM):
gen_kwargs
[
"max_new_tokens"
]
=
1024
gen_kwargs
[
"max_new_tokens"
]
=
1024
if
"temperature"
not
in
gen_kwargs
:
if
"temperature"
not
in
gen_kwargs
:
gen_kwargs
[
"temperature"
]
=
0
gen_kwargs
[
"temperature"
]
=
0
#
if "top_p" not in gen_kwargs:
if
"top_p"
not
in
gen_kwargs
:
#
gen_kwargs["top_p"] = None
gen_kwargs
[
"top_p"
]
=
None
#
if "num_beams" not in gen_kwargs:
if
"num_beams"
not
in
gen_kwargs
:
#
gen_kwargs["num_beams"] = 1
gen_kwargs
[
"num_beams"
]
=
1
stopping_criteria
=
stop_sequences_criteria
(
stopping_criteria
=
stop_sequences_criteria
(
self
.
tokenizer
,
self
.
tokenizer
,
...
@@ -319,12 +264,14 @@ class HFMultimodalLM(HFLM):
...
@@ -319,12 +264,14 @@ class HFMultimodalLM(HFLM):
print
(
f
"Prompt:
\n\n
{
contexts
}
\n
"
)
print
(
f
"Prompt:
\n\n
{
contexts
}
\n
"
)
self
.
tokenizer
.
padding_side
=
"left"
self
.
tokenizer
.
padding_side
=
"left"
inputs
=
self
.
processor
(
inputs
=
self
.
processor
(
# TODO: write this as tok_batch_encode (and allow that to either take a visuals value or None)
images
=
visuals
,
text
=
contexts
,
return_tensors
=
"pt"
,
padding
=
True
images
=
visuals
,
text
=
contexts
,
return_tensors
=
"pt"
,
padding
=
True
).
to
(
).
to
(
self
.
_
device
,
self
.
model
.
dtype
self
.
device
,
self
.
model
.
dtype
)
# TODO: factor out into a tok_batch_encode bit ; truncate from left using max_ctx_len
)
# TODO: factor out into a tok_batch_encode bit ; truncate from left using max_ctx_len
print
(
inputs
)
context_enc
=
inputs
[
"input_ids"
]
context_enc
=
inputs
[
"input_ids"
]
if
"max_length"
not
in
kwargs
:
if
"max_length"
not
in
kwargs
:
...
...
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