Skip to content

Commit 6a17b01

Browse files
committed
Add check for configuration
1 parent df9cb13 commit 6a17b01

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

optimum/intel/openvino/configuration.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ def __init__(
200200
self,
201201
bits: int = 8,
202202
sym: bool = False,
203-
tokenizer: Any = None,
203+
tokenizer: Optional[Any] = None,
204204
dataset: Optional[str] = None,
205-
ratio: Optional[float] = None,
205+
ratio: float = 1.0,
206206
group_size: Optional[int] = None,
207207
all_layers: Optional[bool] = None,
208208
sensitivity_metric: Optional[str] = None,
@@ -213,7 +213,7 @@ def __init__(
213213
self.sym = sym
214214
self.tokenizer = tokenizer
215215
self.dataset = dataset
216-
self.group_size = group_size
216+
self.group_size = group_size or (-1 if bits == 8 else 128)
217217
self.ratio = ratio
218218
self.all_layers = all_layers
219219
self.sensitivity_metric = sensitivity_metric
@@ -226,9 +226,9 @@ def post_init(self):
226226
Safety checker that arguments are correct
227227
"""
228228
if self.ratio is not None and not (0 <= self.ratio <= 1):
229-
raise ValueError("damp_percent must between 0 and 1.")
229+
raise ValueError("`damp_percent` must between 0 and 1.")
230230
if self.group_size is not None and self.group_size != -1 and self.group_size <= 0:
231-
raise ValueError("group_size must be greater than 0 or equal to -1")
231+
raise ValueError("`group_size` must be greater than 0 or equal to -1")
232232
if self.dataset is not None and isinstance(self.dataset, str):
233233
if self.dataset not in ["wikitext2", "c4", "c4-new", "ptb", "ptb-new"]:
234234
raise ValueError(
@@ -239,6 +239,16 @@ def post_init(self):
239239
if self.bits not in [4, 8]:
240240
raise ValueError(f"Only support quantization to [4,8] bits but found {self.bits}")
241241

242+
if self.bits == 8:
243+
if self.ratio != 1:
244+
raise ValueError(
245+
f"For 8-bit quantization, `ratio` is expected to be set to 1.0, but was set to {self.ratio}"
246+
)
247+
if self.group_size != -1:
248+
raise ValueError(
249+
f"For 8-bit quantization, `group_size` is expected to be set to -1, but was set to {self.group_size}"
250+
)
251+
242252

243253
def _check_default_4bit_configs(config: PretrainedConfig):
244254
return _DEFAULT_4BIT_CONFIGS.get(config.name_or_path, None)

0 commit comments

Comments
 (0)