-
Notifications
You must be signed in to change notification settings - Fork 59
[WIP] refact ouptut formats #906
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
Draft
n1ck-guo
wants to merge
1
commit into
main
Choose a base branch
from
hengguo/refactor_format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| # Copyright (c) 2025 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Callable, Union | ||
|
|
||
| from auto_round.schemes import PRESET_SCHEMES, QuantizationScheme | ||
|
|
||
|
|
||
| class OutputFormat: | ||
| support_schemes: list = [] | ||
| _format_list: dict[str, OutputFormat] = {} | ||
|
|
||
| def __init__(self, format): | ||
| self.output_format = format.split(":")[0] | ||
| self.backend = format.split(":")[1] if ":" in format else None | ||
|
|
||
| @classmethod | ||
| def register(cls, *names: str) -> Callable[[OutputFormat], OutputFormat]: | ||
| assert names | ||
|
|
||
| def func(output_format: OutputFormat) -> OutputFormat: | ||
| for name in names: | ||
| cls._format_list[name] = output_format | ||
| return output_format | ||
|
|
||
| return func | ||
|
|
||
| @classmethod | ||
| def get_support_matrix(cls: OutputFormat) -> str: | ||
| output_str = "" | ||
| for k, v in cls._format_list.items(): | ||
| support_scheme = ", ".join(v.support_schemes).rstrip(",") | ||
| output_str += f"\x1b[31;1m{k}\x1b[0m support scheme:\n\t{support_scheme}\n" | ||
| return output_str | ||
|
|
||
| @classmethod | ||
| def is_support_scheme(cls: OutputFormat, scheme: Union[str, QuantizationScheme]) -> bool: | ||
| if scheme in cls.support_schemes: | ||
| return True | ||
| if isinstance(scheme, QuantizationScheme): | ||
| for key in cls.support_schemes: | ||
| if scheme == PRESET_SCHEMES[key]: | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| @OutputFormat.register("fake") | ||
| class FakeFormat(OutputFormat): | ||
| support_schemes = [ | ||
| "W4A16", | ||
| "W2A16", | ||
| "W3A16", | ||
| "W8A16", | ||
| "MXFP4", | ||
| "MXFP8", | ||
| "NVFP4", | ||
| "FPW8A16", | ||
| "W2A16G64", | ||
| "W2A16G32", | ||
| "FP8_STATIC", | ||
| "BF16", | ||
| "GGUF:Q4_0", | ||
| "GGUF:Q4_1", | ||
| "GGUF:Q5_0", | ||
| "GGUF:Q5_1", | ||
| "GGUF:Q2_K_S", | ||
| "GGUF:Q3_K_S", | ||
| "GGUF:Q3_K_M", | ||
| "GGUF:Q3_K_L", | ||
| "GGUF:Q4_K_S", | ||
| "GGUF:Q4_K_M", | ||
| "GGUF:Q5_K_S", | ||
| "GGUF:Q5_K_M", | ||
| "GGUF:Q6_K", | ||
| "GGUF:Q8_0", | ||
| ] | ||
|
|
||
|
|
||
| @OutputFormat.register("llm_compressor") | ||
| class LLMCompressorFormat(OutputFormat): | ||
| support_schemes = ["MXFP4", "MXFP8", "NVFP4", "FPW8A16", "FP8_STATIC"] | ||
|
|
||
|
|
||
| @OutputFormat.register("auto_gptq") | ||
| class AutoGPTQFormat(OutputFormat): | ||
| support_schemes = ["W4A16", "W2A16", "W3A16", "W8A16", "BF16", "W2A16G64", "W2A16G32"] | ||
|
|
||
|
|
||
| @OutputFormat.register("auto_awq") | ||
| class AutoAWQFormat(OutputFormat): | ||
| support_schemes = ["W4A16", "W2A16", "W3A16", "W8A16", "BF16", "W2A16G64", "W2A16G32"] | ||
|
|
||
|
|
||
| @OutputFormat.register("itrex") | ||
| @OutputFormat.register("itrex_xpu") | ||
| class ITREXFormat(OutputFormat): | ||
| support_schemes = ["W4A16", "W2A16", "W3A16", "W8A16", "BF16", "W2A16G64", "W2A16G32"] | ||
|
|
||
|
|
||
| @OutputFormat.register("gguf") | ||
| class GGUFFormat(OutputFormat): | ||
| support_schemes = [ | ||
| "GGUF:Q4_0", | ||
| "GGUF:Q4_1", | ||
| "GGUF:Q5_0", | ||
| "GGUF:Q5_1", | ||
| "GGUF:Q2_K_S", | ||
| "GGUF:Q3_K_S", | ||
| "GGUF:Q3_K_M", | ||
| "GGUF:Q3_K_L", | ||
| "GGUF:Q4_K_S", | ||
| "GGUF:Q4_K_M", | ||
| "GGUF:Q5_K_S", | ||
| "GGUF:Q5_K_M", | ||
| "GGUF:Q6_K", | ||
| "GGUF:Q8_0", | ||
| ] | ||
|
|
||
|
|
||
| @OutputFormat.register("auto_round") | ||
| class AutoRoundFormat(OutputFormat): | ||
| support_schemes = [ | ||
| "W4A16", | ||
| "W2A16", | ||
| "W3A16", | ||
| "W8A16", | ||
| "MXFP4", | ||
| "MXFP8", | ||
| "NVFP4", | ||
| "FPW8A16", | ||
| "W2A16G64", | ||
| "W2A16G32", | ||
| "FP8_STATIC", | ||
| "BF16", | ||
| ] | ||
|
|
||
| def __init__(self, format): | ||
| self.output_format = format.split(":")[0] | ||
| self.backend = format.split(":")[1] if ":" in format else None | ||
|
|
||
| if self.backend == "llm_compressor": | ||
| self.support_schemes = ["MXFP4", "MXFP8", "NVFP4", "FPW8A16", "FP8_STATIC"] | ||
| elif self.backend == "auto_gptq" or "gptqmodel": | ||
| self.support_schemes = ["W4A16", "W2A16", "W3A16", "W8A16", "BF16", "W2A16G64", "W2A16G32"] | ||
| elif self.backend == "auto_awq": | ||
| self.support_schemes = ["W4A16", "W2A16", "W3A16", "W8A16", "BF16", "W2A16G64", "W2A16G32"] | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
decouple backend from format . auto-gtpq, auto-awq, llm-compressor, auto-round
Each backend is a class, has its support schemes and provide funcitons, pack_layer, pack_model
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.
as we are going to support layer-wise datatype