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

[AWQ] e2e awq-quantized model #1229

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions python/mlc_chat/cli/convert_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def _parse_source(path: Union[str, Path], config_path: Path) -> Path:
if path == "auto":
return config_path.parent
path = Path(path)
if not path.is_dir():
raise argparse.ArgumentTypeError(f"Directory does not exist: {path}")
if not path.exists():
raise argparse.ArgumentTypeError(f"Model source does not exist: {path}")
return path

def _parse_output(path: Union[str, Path]) -> Path:
Expand Down Expand Up @@ -60,7 +60,7 @@ def _parse_output(path: Union[str, Path]) -> Path:
parser.add_argument(
"--source-format",
type=str,
choices=["auto", "huggingface-torch", "huggingface-safetensor"],
choices=["auto", "huggingface-torch", "huggingface-safetensor", "awq"],
default="auto",
help="The format of source model weight, infer from `config` if missing. "
"(default: %(default)s)",
Expand Down
1 change: 1 addition & 0 deletions python/mlc_chat/compiler/loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
LOADER: Dict[str, Any] = {
"huggingface-torch": HuggingFaceLoader,
"huggingface-safetensor": HuggingFaceLoader,
"awq": HuggingFaceLoader,
}
1 change: 1 addition & 0 deletions python/mlc_chat/compiler/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Model:
},
quantize={
"group-quant": llama_quantization.group_quant,
"awq": llama_quantization.awq_quant,
},
)
}
Expand Down
6 changes: 3 additions & 3 deletions python/mlc_chat/compiler/quantization/awq_quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _dequantize(
tir.subtract(float_weight[i, j], float_zeros[i, j // self.group_size]),
scale[i, j // self.group_size],
),
name="decode",
name="dequantize",
)


Expand Down Expand Up @@ -250,7 +250,7 @@ def forward(self, x: nn.Tensor) -> nn.Tensor: # pylint: disable=invalid-name
scale,
[tir.IntImm("int64", self.out_features), tir.IntImm("int64", self.in_features)],
),
name_hint="decode",
name_hint="dequantize",
args=[self.qweight, self.qzeros, self.scales],
)
w = nn.op.permute_dims(w) # pylint: disable=invalid-name
Expand Down Expand Up @@ -356,7 +356,7 @@ def forward(self, x: nn.Tensor) -> Sequence[nn.Tensor]: # pylint: disable=inval
tir.IntImm("int64", self.in_features),
],
),
name_hint="decode",
name_hint="dequantize",
args=[self.qweight, self.qzeros, self.scales],
)
w = nn.op.permute_dims(w) # pylint: disable=invalid-name
Expand Down
6 changes: 4 additions & 2 deletions python/mlc_chat/support/auto_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def detect_weight(
weight_config_path = check_func(weight_path)
if not weight_config_path:
raise ValueError(f"The weight is not in {weight_format} format.")
else:
weight_config_path = weight_path
return weight_config_path, weight_format


Expand Down Expand Up @@ -143,5 +145,5 @@ def _check_safetensor(weight_path: Path) -> Optional[Path]:
"huggingface-safetensor": _check_safetensor,
}

# "awq", "ggml", "gguf" are not supported yet.
AVAILABLE_WEIGHT_FORMAT = ["huggingface-torch", "huggingface-safetensor"]
# "ggml", "gguf" are not supported yet.
AVAILABLE_WEIGHT_FORMAT = ["huggingface-torch", "huggingface-safetensor", "awq"]