-
Notifications
You must be signed in to change notification settings - Fork 124
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
Add dynamic quantization config #661
Merged
Merged
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c16fba7
add warning
echarlaix 5805bf6
remove deprecated feature arg
echarlaix e9b6aa0
add model arch
echarlaix 868848a
rmeove calibration dataset argument
echarlaix f8e513c
format
echarlaix 9463607
remove comments
echarlaix 4fde5ad
minor
echarlaix f138a4d
fix ignore
echarlaix 41c49a6
fix
echarlaix 15f1104
replace preset with sym for compatibility between configs
echarlaix 675665e
format
echarlaix 486e6d7
add dynamic quantization
echarlaix ce66da3
add dynamic config
echarlaix d86de3a
remove test deprecated config parameter
echarlaix 1e46ac9
fix
echarlaix 15c1bf8
merge main in branch
echarlaix 69c955b
add bits and sym to base config
echarlaix eb1a843
fix
echarlaix 4471552
updated message
echarlaix ec36742
add config test
echarlaix 985513e
format
echarlaix 31b0460
add kv cache precision
echarlaix 3c12b86
format
echarlaix a4016b2
add test
echarlaix 3504606
format
echarlaix dbf77e4
move compilation step
echarlaix 17debf6
set kv cache precision for seq2seq models
echarlaix 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import copy | ||
import logging | ||
import os | ||
from pathlib import Path | ||
|
@@ -596,11 +595,10 @@ def _from_pretrained( | |
quantization_config = cls._prepare_weight_quantization_config(quantization_config, load_in_8bit) | ||
|
||
load_in_4bit = quantization_config.bits == 4 if quantization_config else False | ||
calibration_dataset = kwargs.get("calibration_dataset", None) | ||
echarlaix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Comment on lines
-599
to
+598
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. Removed |
||
model = cls.load_model( | ||
model_cache_path, | ||
quantization_config=None if load_in_4bit else quantization_config, | ||
calibration_dataset=calibration_dataset, | ||
) | ||
|
||
model_type = config.model_type.replace("_", "-") | ||
|
@@ -637,18 +635,15 @@ def _from_pretrained( | |
f"For the given model, we recommend the following `quantization_config` : {default_config}" | ||
) | ||
|
||
if calibration_dataset is None and isinstance(quantization_config.dataset, str): | ||
calibration_dataset = None | ||
if isinstance(quantization_config.dataset, str): | ||
tokenizer = quantization_config.tokenizer or AutoTokenizer.from_pretrained(model_id) | ||
|
||
from optimum.gptq.data import get_dataset, prepare_dataset | ||
|
||
# from optimum.gptq.utils import get_seqlen | ||
|
||
# seqlen = get_seqlen(causal_model) | ||
nsamples = quantization_config.num_samples if quantization_config.num_samples else 128 | ||
nsamples = quantization_config.num_samples or 128 | ||
dataset = get_dataset(quantization_config.dataset, tokenizer, seqlen=32, nsamples=nsamples) | ||
dataset = prepare_dataset(dataset) | ||
quantization_config = copy.deepcopy(quantization_config) | ||
calibration_dataset = nncf.Dataset(dataset, lambda x: causal_model.prepare_inputs(**x)) | ||
|
||
_weight_only_quantization(model, quantization_config, calibration_dataset) | ||
|
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
Oops, something went wrong.
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.
@echarlaix, shall we turn 8-bit KV-cache quantization as well? It is essentially a per-token INT8 quantization and it is safe in terms of accuracy degradation?