微信扫码
添加专属顾问
我要投稿
pip install -U optimum[neural-compressor] intel-extension-for-transformers
def quantize(model_name: str, output_path: str, calibration_set: "datasets.Dataset"):model = AutoModel.from_pretrained(model_name)tokenizer = AutoTokenizer.from_pretrained(model_name)def preprocess_function(examples):return tokenizer(examples["text"], padding="max_length", max_length=512, truncation=True)vectorized_ds = calibration_set.map(preprocess_function, num_proc=10)vectorized_ds = vectorized_ds.remove_columns(["text"])quantizer = INCQuantizer.from_pretrained(model)quantization_config = PostTrainingQuantConfig(approach="static", backend="ipex", domain="nlp")quantizer.quantize(quantization_config=quantization_config,calibration_dataset=vectorized_ds,save_directory=output_path,batch_size=1,)tokenizer.save_pretrained(output_path)
# 数据集地址https://huggingface.co/datasets/allenai/qasper
from optimum.intel import IPEXModelmodel = IPEXModel.from_pretrained("Intel/bge-small-en-v1.5-rag-int8-static")from transformers import AutoTokenizertokenizer = AutoTokenizer.from_pretrained("Intel/bge-small-en-v1.5-rag-int8-static")inputs = tokenizer(sentences, return_tensors="pt")with torch.no_grad():outputs = model(**inputs)# get the [CLS] tokenembeddings = outputs[0][:, 0]
从上面的结果可以看出,通过量化后模型的延迟和吞吐量都有大幅提升。大家是不是学会的呢。下篇我们继续介绍一个相关工具,辅助我们高效管理RAG流程。
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2026-03-20
为什么总感觉 Claude Code 比 Cursor 聪明?真正的原因根本不是模型能力!
2026-03-18
从RAG到GraphRAG:货拉拉元数据检索应用实践
2026-03-17
企业AI落地三重门,用友如何破局?
2026-03-16
Java 开发者的轻量级 RAG 方案:MeiliSearch 混合搜索实战
2026-03-11
Embedding相似度虚高,如何用langchain+Milvus搭建CRAG解决?
2026-03-11
上下文腐烂:拖垮企业AI与LLM表现的隐患与对策
2026-03-10
从向量里逆向出原始文本和模型来源
2026-02-27
如何用 AI 做业务级 Code Review
2026-01-15
2026-01-02
2025-12-23
2026-02-13
2026-02-03
2025-12-31
2026-01-06
2026-02-03
2025-12-29
2025-12-21
2026-03-17
2026-03-11
2026-02-22
2026-02-15
2026-02-04
2026-02-03
2026-01-19
2026-01-12