Skip to content

Commit

Permalink
allow passing trust remote code for tokenizer init in weight compress…
Browse files Browse the repository at this point in the history
…ion (#830)

* allow passing trust remote code for tokenizer init in weight compression

* Update optimum/intel/openvino/modeling_decoder.py

* Apply suggestions from code review

Co-authored-by: Ilyas Moutawwakil <57442720+IlyasMoutawwakil@users.noreply.github.com>

---------

Co-authored-by: Ilyas Moutawwakil <57442720+IlyasMoutawwakil@users.noreply.github.com>
  • Loading branch information
eaidova and IlyasMoutawwakil authored Aug 9, 2024
1 parent 12438c4 commit 3559c6a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions optimum/commands/export/openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ def run(self):
"scale_estimation": self.args.scale_estimation,
}

if quantization_config.get("dataset", None) is not None:
quantization_config["trust_remote_code"] = self.args.trust_remote_code

if self.args.weight_format in {"int4_sym_g128", "int4_asym_g128", "int4_sym_g64", "int4_asym_g64"}:
logger.warning(
f"--weight-format {self.args.weight_format} is deprecated, possible choices are fp32, fp16, int8, int4"
Expand Down
2 changes: 2 additions & 0 deletions optimum/intel/openvino/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def __init__(
sym: bool = False,
group_size: Optional[int] = None,
tokenizer: Optional[str] = None,
trust_remote_code: bool = False,
dataset: Optional[Union[str, List[str]]] = None,
ratio: float = 1.0,
all_layers: Optional[bool] = None,
Expand All @@ -275,6 +276,7 @@ def __init__(
):
super().__init__(bits=bits, sym=sym, ignored_scope=ignored_scope, num_samples=num_samples)
self.tokenizer = tokenizer
self.trust_remote_code = trust_remote_code
self.dataset = dataset
self.group_size = group_size or (-1 if bits == 8 else 128)
self.ratio = ratio
Expand Down
4 changes: 4 additions & 0 deletions optimum/intel/openvino/modeling_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def _from_transformers(
stateful=None,
load_in_8bit=load_in_8bit,
quantization_config=quantization_config,
trust_remote_code=trust_remote_code,
**kwargs,
)

Expand Down Expand Up @@ -781,6 +782,9 @@ def _from_pretrained(

if isinstance(quantization_config, dict) and quantization_config == {"bits": 4}:
quantization_config = get_default_int4_config(config.name_or_path)
if quantization_config.get("dataset", None) is not None:
quantization_config["trust_remote_code"] = kwargs.get("trust_remote_code", False)

quantization_config = cls._prepare_weight_quantization_config(quantization_config, load_in_8bit)

enable_compilation = kwargs.pop("compile", True) and not quantization_config
Expand Down
4 changes: 3 additions & 1 deletion optimum/intel/openvino/quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,9 @@ def _remove_unused_columns(self, dataset: "Dataset"):
def _prepare_builtin_dataset(self, quantization_config: OVWeightQuantizationConfig):
from optimum.gptq.data import get_dataset, prepare_dataset

tokenizer = AutoTokenizer.from_pretrained(quantization_config.tokenizer)
tokenizer = AutoTokenizer.from_pretrained(
quantization_config.tokenizer, trust_remote_code=quantization_config.trust_remote_code
)
nsamples = quantization_config.num_samples if quantization_config.num_samples else 128
calibration_dataset = get_dataset(quantization_config.dataset, tokenizer, seqlen=32, nsamples=nsamples)
calibration_dataset = prepare_dataset(calibration_dataset)
Expand Down

0 comments on commit 3559c6a

Please sign in to comment.