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
05b37f20
Unverified
Commit
05b37f20
authored
Aug 25, 2025
by
Nikita Savelyev
Committed by
GitHub
Aug 25, 2025
Browse files
Add support for OpenVINO text2text generation models (#3101)
* Add support for OVModelForSeq2SeqLM * Add test
parent
dddfe7ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
20 deletions
+16
-20
lm_eval/models/optimum_lm.py
lm_eval/models/optimum_lm.py
+5
-11
tests/models/test_openvino.py
tests/models/test_openvino.py
+11
-9
No files found.
lm_eval/models/optimum_lm.py
View file @
05b37f20
...
...
@@ -28,9 +28,8 @@ class OptimumLM(HFLM):
**
kwargs
,
)
->
None
:
if
"backend"
in
kwargs
:
# optimum currently only supports causal models
assert
kwargs
[
"backend"
]
==
"causal"
,
(
"Currently, only OVModelForCausalLM is supported."
assert
kwargs
[
"backend"
]
in
[
"causal"
,
"seq2seq"
],
(
"Currently, only OVModelForCausalLM or OVModelForSeq2SeqLM are supported."
)
self
.
openvino_device
=
device
...
...
@@ -54,7 +53,7 @@ class OptimumLM(HFLM):
"package `optimum` is not installed. Please install it via `pip install optimum[openvino]`"
)
else
:
from
optimum.intel.openvino
import
OVModelForCausalLM
from
optimum.intel.openvino
import
OVModelForCausalLM
,
OVModelForSeq2SeqLM
model_kwargs
=
kwargs
if
kwargs
else
{}
if
"ov_config"
in
model_kwargs
:
...
...
@@ -76,17 +75,12 @@ class OptimumLM(HFLM):
model_kwargs
[
"ov_config"
][
"MODEL_DISTRIBUTION_POLICY"
]
=
(
"PIPELINE_PARALLEL"
)
model_file
=
Path
(
pretrained
)
/
"openvino_model.xml"
if
model_file
.
exists
():
export
=
False
else
:
export
=
True
self
.
_model
=
OVModelForCausalLM
.
from_pretrained
(
model_cls
=
OVModelForCausalLM
if
self
.
backend
==
"causal"
else
OVModelForSeq2SeqLM
self
.
_model
=
model_cls
.
from_pretrained
(
pretrained
,
revision
=
revision
,
trust_remote_code
=
trust_remote_code
,
export
=
export
,
device
=
self
.
openvino_device
.
upper
(),
**
model_kwargs
,
)
tests/models/test_openvino.py
View file @
05b37f20
...
...
@@ -3,23 +3,25 @@ import tempfile
from
pathlib
import
Path
import
pytest
from
optimum.intel
import
OVModelForCausalLM
from
optimum.intel
import
OVModelForCausalLM
,
OVModelForSeq2SeqLM
from
transformers
import
AutoTokenizer
from
lm_eval
import
evaluator
from
lm_eval.api.registry
import
get_model
SUPPORTED_ARCHITECTURES_TASKS
=
{
"facebook/opt-125m"
:
"lambada_openai"
,
"hf-internal-testing/tiny-random-gpt2"
:
"wikitext"
,
}
SUPPORTED_ARCHITECTURES_TASKS
=
[
(
"causal"
,
"facebook/opt-125m"
,
"lambada_openai"
,),
(
"causal"
,
"hf-internal-testing/tiny-random-gpt2"
,
"wikitext"
,),
(
"seq2seq"
,
"hf-internal-testing/tiny-random-t5"
,
"sst2"
,),
]
@
pytest
.
mark
.
parametrize
(
"model_id,task"
,
SUPPORTED_ARCHITECTURES_TASKS
.
items
()
)
def
test_evaluator
(
model_id
,
task
):
@
pytest
.
mark
.
parametrize
(
"
backend,
model_id,task"
,
SUPPORTED_ARCHITECTURES_TASKS
)
def
test_evaluator
(
backend
,
model_id
,
task
):
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
model
=
OVModelForCausalLM
.
from_pretrained
(
model_cls
=
OVModelForCausalLM
if
backend
==
"causal"
else
OVModelForSeq2SeqLM
model
=
model_cls
.
from_pretrained
(
model_id
,
export
=
True
,
use_cache
=
True
)
model
.
save_pretrained
(
tmpdirname
)
...
...
@@ -27,7 +29,7 @@ def test_evaluator(model_id, task):
tokenizer
.
save_pretrained
(
tmpdirname
)
lm
=
get_model
(
"openvino"
).
create_from_arg_string
(
f
"pretrained=
{
tmpdirname
}
"
,
f
"pretrained=
{
tmpdirname
}
,backend=
{
backend
}
"
,
{
"batch_size"
:
1
,
"device"
:
"cpu"
,
...
...
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