Skip to content

Commit d95534d

Browse files
authored
Add INC model loading test (#348)
1 parent 7c05310 commit d95534d

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright 2021 The HuggingFace Team. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
import os
17+
import unittest
18+
19+
from parameterized import parameterized
20+
from transformers import set_seed
21+
22+
from optimum.exporters import TasksManager
23+
from optimum.intel import ( # noqa
24+
INCConfig,
25+
INCModelForCausalLM,
26+
INCModelForMaskedLM,
27+
INCModelForQuestionAnswering,
28+
INCModelForSeq2SeqLM,
29+
INCModelForSequenceClassification,
30+
INCModelForTokenClassification,
31+
INCQuantizer,
32+
INCSeq2SeqTrainer,
33+
INCStableDiffusionPipeline,
34+
INCTrainer,
35+
)
36+
from optimum.intel.neural_compressor.utils import _HEAD_TO_AUTOMODELS
37+
38+
39+
os.environ["CUDA_VISIBLE_DEVICES"] = ""
40+
set_seed(1009)
41+
42+
43+
MODEL_NAMES_TO_TASK = (
44+
("echarlaix/distilbert-base-uncased-finetuned-sst-2-english-int8-dynamic", "text-classification"),
45+
("echarlaix/distilbert-sst2-inc-dynamic-quantization-magnitude-pruning-0.1", "text-classification"),
46+
("hf-internal-testing/tiny-random-bert", "fill-mask"),
47+
("Intel/bert-base-uncased-squad-int8-static", "question-answering"),
48+
("hf-internal-testing/tiny-random-gpt2", "text-generation"),
49+
("Intel/t5-small-xsum-int8-dynamic", "text2text-generation"),
50+
# ("echarlaix/stable-diffusion-v1-5-inc-int8-dynamic", "stable-diffusion")
51+
)
52+
53+
54+
class INCModelingTest(unittest.TestCase):
55+
@parameterized.expand(MODEL_NAMES_TO_TASK)
56+
def test_modeling(self, model_id, task):
57+
inc_model = eval(_HEAD_TO_AUTOMODELS[task]).from_pretrained(model_id) # TRANSFORMERS_AUTO_CLASS
58+
model_type = inc_model.config.model_type.replace("_", "-")
59+
config_class = TasksManager.get_exporter_config_constructor(
60+
exporter="onnx",
61+
model=inc_model,
62+
task=task,
63+
model_name=model_id,
64+
model_type=model_type,
65+
)
66+
config = config_class(inc_model.config)
67+
model_inputs = config.generate_dummy_inputs(framework="pt")
68+
inc_model(**model_inputs)

0 commit comments

Comments
 (0)