我可以使用4位、8位版本的Transformers翻译模型吗?

问题描述 投票:0回答:1

量化版本是否可用于 LLM 之外的其他 Transformer 模型,特别是翻译模型?我正在寻找有关以下型号的信息:

此型号:

我进行了在线搜索,但尚未找到有关这些模型的量化版本可用性的明确答案。

python deep-learning huggingface-transformers quantization
1个回答
0
投票

它可能不适用于每个模型,但您可以尝试使用本机 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 位量化的示例

© www.soinside.com 2019 - 2024. All rights reserved.