Qwen1.5-1.8B-GPTQ-4-Bit

我要开发同款
匿名用户2024年07月31日
35阅读
所属分类ai、qwen2
开源地址https://modelscope.cn/models/skyxiaobaibai/Qwen1.5-1.8B-GPTQ-4-Bit
授权协议mit

作品详情

Introduction

Qwen1.5 is the beta version of Qwen2, a transformer-based decoder-only language model pretrained on a large amount of data. In comparison with the previous released Qwen, the improvements include:

8 model sizes, including 0.5B, 1.8B, 4B, 7B, 14B, 32B and 72B dense models, and an MoE model of 14B with 2.7B activated;
Significant performance improvement in Chat models;
Multilingual support of both base and chat models;
Stable support of 32K context length for models of all sizes
No need of trust_remote_code.

For more details, please refer to our blog post and GitHub repo. Model Details

Qwen1.5 is a language model series including decoder language models of different model sizes. For each size, we release the base language model and the aligned chat model. It is based on the Transformer architecture with SwiGLU activation, attention QKV bias, group query attention, mixture of sliding window attention and full attention, etc. Additionally, we have an improved tokenizer adaptive to multiple natural languages and codes. For the beta version, temporarily we did not include GQA (except for 32B) and the mixture of SWA and full attention. Requirements

The code of Qwen1.5 has been in the latest Hugging face transformers and we advise you to install transformers>=4.37.0, or you might encounter the following error:

from transformers import AutoTokenizer, TextGenerationPipeline from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig import logging

logging.basicConfig( format="%(asctime)s %(levelname)s [%(name)s] %(message)s", level=logging.INFO, datefmt="%Y-%m-%d %H:%M:%S" )

pretrainedmodeldir = "Qwen/Qwen1.5-1.8B" quantizedmodeldir = "local "

tokenizer = AutoTokenizer.frompretrained(pretrainedmodeldir, usefast=True) examples = [ tokenizer( "auto-gptq is an easy-to-use model quantization library with user-friendly apis, based on GPTQ algorithm." ) ]

quantizeconfig = BaseQuantizeConfig( bits=4, # quantize model to 4-bit groupsize=128, # it is recommended to set the value to 128 desc_act=False, # set to False can significantly speed up inference but the perplexity may slightly bad )

load un-quantized model, by default, the model will always be loaded into CPU memory

model = AutoGPTQForCausalLM.frompretrained(pretrainedmodeldir, quantizeconfig)

quantize model, the examples should be list of dict whose keys can only be "inputids" and "attentionmask"

model.quantize(examples)

save quantized model

model.savequantized(quantizedmodel_dir)

save quantized model using safetensors

model.savequantized(quantizedmodeldir, usesafetensors=True)

push quantized model to Hugging Face Hub.

to use useauthtoken=True, Login first via huggingface-cli login.

or pass explcit token with: useauthtoken="hf_xxxxxxx"

(uncomment the following three lines to enable this feature)

repoid = f"YourUserName/{quantizedmodel_dir}"

commitmessage = f"AutoGPTQ model for {pretrainedmodeldir}: {quantizeconfig.bits}bits, gr{quantizeconfig.groupsize}, descact={quantizeconfig.desc_act}"

model.pushtohub(repoid, commitmessage=commitmessage, useauth_token=True)

alternatively you can save and push at the same time

(uncomment the following three lines to enable this feature)

repoid = f"YourUserName/{quantizedmodel_dir}"

commitmessage = f"AutoGPTQ model for {pretrainedmodeldir}: {quantizeconfig.bits}bits, gr{quantizeconfig.groupsize}, descact={quantizeconfig.desc_act}"

model.pushtohub(repoid, savedir=quantizedmodeldir, usesafetensors=True, commitmessage=commitmessage, useauth_token=True)

load quantized model to the first GPU

model = AutoGPTQForCausalLM.fromquantized(quantizedmodel_dir, device="cuda:0")

download quantized model from Hugging Face Hub and load to the first GPU

model = AutoGPTQForCausalLM.fromquantized(repoid, device="cuda:0", usesafetensors=True, usetriton=False)

inference with model.generate

print(tokenizer.decode(model.generate(**tokenizer("autogptq is", returntensors="pt").to(model.device))[0]))

or you can also use pipeline

GGUF add function calling & C++ quantize INT4

pipeline = TextGenerationPipeline(model=model, tokenizer=tokenizer) print(pipeline("auto-gptq is")[0]["generated_text"])

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论