Skip to content
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

Quantization Scheme Validation #209

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Changes from 2 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
20 changes: 17 additions & 3 deletions src/compressed_tensors/quantization/quant_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# limitations under the License.

from copy import deepcopy
from typing import List, Optional
from typing import Any, Dict, List, Optional

from compressed_tensors.quantization.quant_args import (
QuantizationArgs,
QuantizationStrategy,
QuantizationType,
)
from pydantic import BaseModel
from pydantic import BaseModel, model_validator


__all__ = [
Expand All @@ -47,12 +47,26 @@ class QuantizationScheme(BaseModel):
input_activations: Optional[QuantizationArgs] = None
output_activations: Optional[QuantizationArgs] = None

@model_validator(mode="after")
def validate_model_after(model: "QuantizationArgs") -> Dict[str, Any]:
inputs = model.input_activations
outputs = model.output_activations

if inputs is not None:
if inputs.actorder is not None:
raise ValueError("Cannot apply actorder to input activations")

if outputs is not None:
if outputs.actorder is not None:
raise ValueError("Cannot apply actorder to output activations")

return model

@classmethod
def default_scheme(
cls,
targets: Optional[List[str]] = None,
):

if targets is None:
# default to quantizing all Linear layers
targets = ["Linear"]
Expand Down
Loading