Skip to content

More fixes needed when QuantizationConfig is None #184

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/compressed_tensors/quantization/lifecycle/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def load_pretrained_quantization(model: Module, model_name_or_path: str):


def apply_quantization_config(
model: Module, config: QuantizationConfig, run_compressed: bool = False
) -> Dict:
model: Module, config: Union[QuantizationConfig, None], run_compressed: bool = False
) -> OrderedDict:
"""
Initializes the model for quantization in-place based on the given config

Expand All @@ -117,6 +117,10 @@ def apply_quantization_config(
:param run_compressed: Whether the model will be run in compressed mode or
decompressed fully on load
"""
# Workaround for when HF Quantizer passes None, see PR #180
if config is None:
return OrderedDict()

# remove reference to the original `config`
# argument. This function can mutate it, and we'd
# like to keep the original `config` as it is.
Expand Down Expand Up @@ -186,14 +190,14 @@ def apply_quantization_config(
return names_to_scheme


def process_quantization_config(config: QuantizationConfig) -> QuantizationConfig:
def process_quantization_config(config: Optional[QuantizationConfig]) -> Optional[QuantizationConfig]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the only use of process_quantization_config is by apply_quantization_config.
What is the purpose of this change?

"""
Preprocess the raw QuantizationConfig

:param config: the raw QuantizationConfig
:return: the processed QuantizationConfig
:param config: Optional raw QuantizationConfig
:return: the processed QuantizationConfig, if the raw config is not None
"""
if config.kv_cache_scheme is not None:
if config is not None and config.kv_cache_scheme is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use this function outside of apply_quantization_config? If not, we would never hit the None case?

config = process_kv_cache_config(config)

return config
Expand Down