Skip to content

Commit 20df723

Browse files
authored
relax requirements to have registered normalized config for usage con… (#537)
* relax requirements to have registered normalized config for usage converted decoder models * add property for access to normalized config
1 parent 6e79be1 commit 20df723

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

optimum/exporters/openvino/stateful.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from openvino.runtime import opset13
2323
from optimum.exporters import TasksManager
2424
from optimum.intel.utils.import_utils import _openvino_version, is_openvino_version
25-
from optimum.utils.normalized_config import NormalizedConfigManager
2625

2726

2827
def model_has_state(ov_model: ov.Model):
@@ -217,9 +216,7 @@ def patch_stateful(config: PretrainedConfig, ov_model: ov.Model):
217216
batch_dim = 1 if config.model_type == "chatglm" else 0
218217

219218
fuse_cache_reorder(ov_model, not_kv_inputs, key_value_input_names, batch_dim)
220-
221-
normalized_config = NormalizedConfigManager.get_normalized_config_class(config.model_type)(config)
222-
num_attention_heads = normalized_config.num_attention_heads if config.model_type == "bloom" else 1
219+
num_attention_heads = config.num_attention_heads if config.model_type == "bloom" else 1
223220
make_stateful(
224221
ov_model, not_kv_inputs, key_value_input_names, key_value_output_names, batch_dim, num_attention_heads, None
225222
)

optimum/intel/openvino/modeling_decoder.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
2828
from transformers.modeling_outputs import CausalLMOutputWithPast
2929

30-
from optimum.utils import NormalizedConfigManager
30+
from optimum.utils.normalized_config import NormalizedConfigManager
3131

3232
from ...exporters.openvino import ensure_stateful_is_available, main_export, patch_stateful
3333
from ...exporters.openvino.stateful import model_has_state
@@ -132,7 +132,6 @@ def __init__(
132132
self.stateful = model_has_sinks
133133
self.main_input_name = "input_ids"
134134
self.num_pkv = 2
135-
self.normalized_config = NormalizedConfigManager.get_normalized_config_class(config.model_type)(config)
136135
self.key_value_input_names = [key for key in self.input_names if "key_values" in key]
137136
self.key_value_output_names = [key for key in self.output_names if "present" in key]
138137
self._original_model = self.model.clone() # keep original model for serialization
@@ -321,6 +320,13 @@ def reshape(self, batch_size: int, sequence_length: int):
321320
logger.warning("Static shapes are not supported for causal language model.")
322321
return self
323322

323+
@property
324+
def normalized_config(self):
325+
logger.warning(
326+
"access to normalized_config attribute is deprecated and will be removed in future versions, please use config"
327+
)
328+
return NormalizedConfigManager.get_normalized_config_class(self.config.model_type)(self.config)
329+
324330
def compile(self):
325331
if self.request is None:
326332
super().compile()
@@ -364,7 +370,7 @@ def forward(
364370

365371
batch_size = input_ids.shape[0]
366372
if self.config.model_type == "bloom":
367-
batch_size *= self.normalized_config.num_attention_heads
373+
batch_size *= self.config.num_attention_heads
368374

369375
inputs = {}
370376
past_len = 0
@@ -592,8 +598,8 @@ def _reorder_cache(
592598
if self.stateful:
593599
beam_idx = np.array(beam_idx)
594600
batch_size = beam_idx.shape[0]
595-
indices = np.array(range(batch_size * self.normalized_config.num_attention_heads))
596-
indices = indices.reshape([batch_size, self.normalized_config.num_attention_heads])
601+
indices = np.array(range(batch_size * self.config.num_attention_heads))
602+
indices = indices.reshape([batch_size, self.config.num_attention_heads])
597603
self.next_beam_idx = np.take(indices, beam_idx, 0).flatten()
598604
return past_key_values
599605
else:

0 commit comments

Comments
 (0)