量化版本是否可用于 LLM 之外的其他 Transformer 模型,特别是翻译模型?我正在寻找有关以下型号的信息:
此型号:
我进行了在线搜索,但尚未找到有关这些模型的量化版本可用性的明确答案。
它可能不适用于每个模型,但您可以尝试使用本机 pytorch 进行 8 位量化,https://pytorch.org/tutorials/recipes/recipes/dynamic_quantization.html,如下所示:
import gc
import torch
from torch import nn
def quantize_model(model: nn.Module, precision=torch.qint8, layers={nn.LayerNorm, nn.Linear, nn.Dropout}):
model_q = torch.quantization.quantize_dynamic(
model, layers, dtype=precision)
del model
gc.collect()
return model_q
然后:
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
model = quantize_model(self.model)
https://github.com/alvations/lightyear/tree/main/lightyear/translators 上还有更多 8 位量化的示例