Skip to content

Commit 02889ac

Browse files
committed
fix style
1 parent 0aa3f29 commit 02889ac

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

optimum/exporters/openvino/model_configs.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@
3232

3333

3434
def init_model_configs():
35-
36-
supported_model_types = ["_SUPPORTED_MODEL_TYPE", "_DIFFUSERS_SUPPORTED_MODEL_TYPE", "_TIMM_SUPPORTED_MODEL_TYPE", "_SENTENCE_TRANSFORMERS_SUPPORTED_MODEL_TYPE"]
35+
supported_model_types = [
36+
"_SUPPORTED_MODEL_TYPE",
37+
"_DIFFUSERS_SUPPORTED_MODEL_TYPE",
38+
"_TIMM_SUPPORTED_MODEL_TYPE",
39+
"_SENTENCE_TRANSFORMERS_SUPPORTED_MODEL_TYPE",
40+
]
3741

3842
for supported_models_config in supported_model_types:
3943
supported_models = getattr(TasksManager, supported_models_config)
@@ -42,9 +46,8 @@ def init_model_configs():
4246
continue
4347
onnx_config = export_configs["onnx"]
4448
supported_models[model]["openvino"] = deepcopy(onnx_config)
45-
46-
setattr(TasksManager, supported_models_config, supported_models)
4749

50+
setattr(TasksManager, supported_models_config, supported_models)
4851

4952

5053
init_model_configs()

optimum/exporters/openvino/model_patcher.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def patch_model_with_bettertransformer(model):
7171
return model
7272

7373

74-
def mixtral_sparse_moe_block_forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
74+
def _mixtral_sparse_moe_block_forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
7575
""" """
7676
batch_size, sequence_length, hidden_dim = hidden_states.shape
7777
hidden_states = hidden_states.view(-1, hidden_dim)
@@ -113,7 +113,9 @@ def __enter__(self):
113113
super().__enter__()
114114
for layer in self._model.model.layers:
115115
layer.block_sparse_moe._unpatched_forward = layer.block_sparse_moe.forward
116-
layer.block_sparse_moe.forward = types.MethodType(mixtral_sparse_moe_block_forward, layer.block_sparse_moe)
116+
layer.block_sparse_moe.forward = types.MethodType(
117+
_mixtral_sparse_moe_block_forward, layer.block_sparse_moe
118+
)
117119

118120
def __exit__(self, exc_type, exc_value, traceback):
119121
super().__exit__(exc_type, exc_value, traceback)

optimum/intel/openvino/modeling_decoder.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ def _reshape(
311311
shapes[inputs][0] = -1
312312
input_name = inputs.get_any_name()
313313
if input_name.startswith("past_key_values"):
314-
if (len(inputs.partial_shape) == 3 and input_name.endswith("value")) or self.config.model_type == "chatglm":
314+
if (
315+
len(inputs.partial_shape) == 3 and input_name.endswith("value")
316+
) or self.config.model_type == "chatglm":
315317
shapes[inputs][1] = -1
316318
else:
317319
shapes[inputs][2] = -1

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"openvino>=2023.3",
4949
"onnx",
5050
"onnxruntime",
51-
"transformers>=4.36.0",
5251
"optimum @ git+https://github.com/huggingface/optimum.git#egg=optimum",
5352
],
5453
"openvino-tokenizers": ["openvino-tokenizers[transformers]"],

tests/openvino/test_modeling.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase):
497497
)
498498
GENERATION_LENGTH = 100
499499
IS_SUPPORT_STATEFUL = is_openvino_version(">=", "2023.3")
500-
REMOTE_CODE_MODELS = ("chatglm", )
500+
REMOTE_CODE_MODELS = ("chatglm",)
501501

502502
@parameterized.expand(SUPPORTED_ARCHITECTURES)
503503
def test_compare_to_transformers(self, model_arch):
@@ -513,13 +513,18 @@ def test_compare_to_transformers(self, model_arch):
513513

514514
model_kwargs = {}
515515
if model_arch in self.REMOTE_CODE_MODELS:
516-
model_kwargs = {"config": AutoConfig.from_pretrained(model_id, trust_remote_code=True), "trust_remote_code": True}
516+
model_kwargs = {
517+
"config": AutoConfig.from_pretrained(model_id, trust_remote_code=True),
518+
"trust_remote_code": True,
519+
}
517520
ov_model = OVModelForCausalLM.from_pretrained(model_id, export=True, ov_config=F32_CONFIG, **model_kwargs)
518521
self.assertIsInstance(ov_model.config, PretrainedConfig)
519522
self.assertTrue(ov_model.use_cache)
520-
self.assertEqual(ov_model.stateful, self.IS_SUPPORT_STATEFUL and model_arch not in not_stateful)
523+
self.assertEqual(
524+
ov_model.stateful, self.IS_SUPPORT_STATEFUL and ov_model.config.model_type not in not_stateful
525+
)
521526
transformers_model = AutoModelForCausalLM.from_pretrained(model_id, **model_kwargs)
522-
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=model_arch in remote_code)
527+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=model_arch in self.REMOTE_CODE_MODELS)
523528
tokens = tokenizer(
524529
"This is a sample", return_tensors="pt", return_token_type_ids=False if model_arch == "llama" else None
525530
)
@@ -552,9 +557,14 @@ def test_pipeline(self, model_arch):
552557
model_kwargs = {}
553558
model_id = MODEL_NAMES[model_arch]
554559
if model_arch in self.REMOTE_CODE_MODELS:
555-
model_kwargs = {"config": AutoConfig.from_pretrained(model_id, trust_remote_code=True), "trust_remote_code": True}
560+
model_kwargs = {
561+
"config": AutoConfig.from_pretrained(model_id, trust_remote_code=True),
562+
"trust_remote_code": True,
563+
}
556564
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=model_arch in self.REMOTE_CODE_MODELS)
557-
model = OVModelForCausalLM.from_pretrained(model_id, export=True, use_cache=False, compile=False, **model_kwargs)
565+
model = OVModelForCausalLM.from_pretrained(
566+
model_id, export=True, use_cache=False, compile=False, **model_kwargs
567+
)
558568
model.config.encoder_no_repeat_ngram_size = 0
559569
model.to("cpu")
560570
model.half()
@@ -573,7 +583,10 @@ def test_multiple_inputs(self, model_arch):
573583
set_seed(SEED)
574584
model_kwargs = {}
575585
if model_arch in self.REMOTE_CODE_MODELS:
576-
model_kwargs = {"config": AutoConfig.from_pretrained(model_id, trust_remote_code=True), "trust_remote_code": True}
586+
model_kwargs = {
587+
"config": AutoConfig.from_pretrained(model_id, trust_remote_code=True),
588+
"trust_remote_code": True,
589+
}
577590
model = OVModelForCausalLM.from_pretrained(model_id, export=True, compile=False, **model_kwargs)
578591
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=model_arch in self.REMOTE_CODE_MODELS)
579592
tokenizer.pad_token = tokenizer.eos_token

0 commit comments

Comments
 (0)