-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ort config instantiation (from_pretrained) and saving (save_pretrained) #1865
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
from dataclasses import asdict, dataclass, field | ||
from enum import Enum | ||
from pathlib import Path | ||
from typing import Dict, List, Optional, Tuple, Union | ||
from typing import Any, Dict, List, Optional, Tuple, Union | ||
|
||
from datasets import Dataset | ||
from packaging.version import Version, parse | ||
|
@@ -298,6 +298,15 @@ def __post_init__(self): | |
) | ||
self.operators_to_quantize = operators_to_quantize | ||
|
||
if isinstance(self.format, str): | ||
self.format = QuantFormat[self.format] | ||
if isinstance(self.mode, str): | ||
self.mode = QuantizationMode[self.mode] | ||
if isinstance(self.activations_dtype, str): | ||
self.activations_dtype = QuantType[self.activations_dtype] | ||
if isinstance(self.weights_dtype, str): | ||
self.weights_dtype = QuantType[self.weights_dtype] | ||
|
||
@staticmethod | ||
def quantization_type_str(activations_dtype: QuantType, weights_dtype: QuantType) -> str: | ||
return ( | ||
|
@@ -984,8 +993,28 @@ def __init__( | |
self.opset = opset | ||
self.use_external_data_format = use_external_data_format | ||
self.one_external_file = one_external_file | ||
self.optimization = self.dataclass_to_dict(optimization) | ||
self.quantization = self.dataclass_to_dict(quantization) | ||
|
||
if isinstance(optimization, dict) and optimization: | ||
self.optimization = OptimizationConfig(**optimization) | ||
elif isinstance(optimization, OptimizationConfig): | ||
self.optimization = optimization | ||
elif not optimization: | ||
self.optimization = None | ||
else: | ||
raise ValueError( | ||
f"Optional argument `optimization` must be a dictionary or an instance of OptimizationConfig, got {type(optimization)}" | ||
) | ||
if isinstance(quantization, dict) and quantization: | ||
self.quantization = QuantizationConfig(**quantization) | ||
elif isinstance(quantization, QuantizationConfig): | ||
self.quantization = quantization | ||
elif not quantization: | ||
self.quantization = None | ||
else: | ||
raise ValueError( | ||
f"Optional argument `quantization` must be a dictionary or an instance of QuantizationConfig, got {type(quantization)}" | ||
) | ||
|
||
self.optimum_version = kwargs.pop("optimum_version", None) | ||
|
||
@staticmethod | ||
|
@@ -1002,3 +1031,17 @@ def dataclass_to_dict(config) -> dict: | |
v = [elem.name if isinstance(elem, Enum) else elem for elem in v] | ||
new_config[k] = v | ||
return new_config | ||
|
||
def to_dict(self) -> Dict[str, Any]: | ||
dict_config = { | ||
"opset": self.opset, | ||
"use_external_data_format": self.use_external_data_format, | ||
"one_external_file": self.one_external_file, | ||
"optimization": self.dataclass_to_dict(self.optimization), | ||
"quantization": self.dataclass_to_dict(self.quantization), | ||
} | ||
|
||
if self.optimum_version: | ||
dict_config["optimum_version"] = self.optimum_version | ||
|
||
return dict_config | ||
Comment on lines
+1035
to
+1047
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. called by the mixin at save time (BaseConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
post init : str -> enums