-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
219 additions
and
185 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,26 +1,24 @@ | ||
""" | ||
Quantization specs for Llama2 architecture. | ||
TODO: add docstring | ||
""" | ||
"""Quantization specs for Llama.""" | ||
from typing import Tuple | ||
|
||
from tvm.relax.frontend import nn | ||
|
||
from ..parameter import QuantizeMapping | ||
from ..quantization import GroupQuantizeConfig | ||
from ..quantization import GroupQuantize | ||
from .llama_config import LlamaConfig | ||
from .llama_model import LlamaForCasualLM | ||
|
||
|
||
def llama_group_quantization( | ||
model: LlamaForCasualLM, quant_config: GroupQuantizeConfig | ||
def group_quant( | ||
model_config: LlamaConfig, | ||
quantization: GroupQuantize, | ||
) -> Tuple[nn.Module, QuantizeMapping]: | ||
"""Quantize a Llama2 model using group quantization.""" | ||
model: nn.Module = LlamaForCasualLM(model_config) | ||
quant_map = QuantizeMapping({}, {}) | ||
for i in range(len(model.model.layers)): | ||
model.model.layers[i] = quant_config.apply( | ||
model.model.layers[i], quant_map, f"model.layers.{i}" | ||
) | ||
model.model.embed_tokens = quant_config.apply( | ||
model.model.embed_tokens, quant_map, "model.embed_tokens" | ||
model = quantization.quantize_model( | ||
model, | ||
quant_map, | ||
"model", | ||
) | ||
model.lm_head = quant_config.apply(model.lm_head, quant_map, "lm_head") | ||
return model, quant_map |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""A subpackage for quantization and dequantization algorithms""" | ||
from .quantization import QUANT, QuantizeConfig | ||
from .group_quantization import GroupQuantizeConfig | ||
from .group_quantization import GroupQuantize | ||
from .quantization import QUANTIZATION, Quantization |
Oops, something went wrong.