M
Mistral Small 3.1 24B Instruct 2503 Quantized.w4a16
由 RedHatAI 开发
这是一个经过INT4量化的Mistral-Small-3.1-24B-Instruct-2503模型,由Red Hat (Neural Magic)优化发布,适用于快速响应的对话代理和低延迟推理场景。
下载量 219
发布时间 : 4/15/2025
模型介绍
内容详情
替代品
模型简介
该模型是基于Mistral-Small-3.1-24B-Instruct-2503进行INT4权重量化的版本,减少了约75%的磁盘大小和GPU内存需求,同时保持较好的性能。
模型特点
高效量化
采用INT4权重量化,减少75%的磁盘大小和GPU内存需求
多语言支持
支持24种语言的文本理解和生成
多模态能力
具备文本和图像理解能力
低延迟推理
优化后适合快速响应的对话代理和函数调用
模型能力
文本生成
对话代理
编程推理
数学推理
长文档理解
视觉理解
多语言处理
使用案例
对话系统
智能客服
用于构建快速响应的客户服务对话系统
低延迟响应,支持多语言
代码辅助
编程助手
帮助开发者理解和生成代码
支持多种编程语言的代码补全和解释
文档处理
长文档摘要
自动生成长文档的摘要和关键点
支持8192 tokens的长上下文理解
语言:
- 英语
- 法语
- 德语
- 西班牙语
- 葡萄牙语
- 意大利语
- 日语
- 韩语
- 俄语
- 中文
- 阿拉伯语
- 波斯语
- 印尼语
- 马来语
- 尼泊尔语
- 波兰语
- 罗马尼亚语
- 塞尔维亚语
- 瑞典语
- 土耳其语
- 乌克兰语
- 越南语
- 印地语
- 孟加拉语 许可证: Apache-2.0 库名称: vllm 基础模型:
- mistralai/Mistral-Small-3.1-24B-Instruct-2503 管道标签: 图像文本到文本 标签:
- neuralmagic
- redhat
- llmcompressor
- 量化
- int4
Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16
模型概述
- 模型架构: Mistral3ForConditionalGeneration
- 输入: 文本/图像
- 输出: 文本
- 模型优化:
- 权重量化: INT4
- 适用场景: 适用于:
- 快速响应的对话代理。
- 低延迟函数调用。
- 通过微调的领域专家。
- 处理敏感数据的爱好者和组织的本地推理。
- 编程和数学推理。
- 长文档理解。
- 视觉理解。
- 不适用场景: 任何违反适用法律或法规(包括贸易合规法律)的使用。模型官方不支持的语言使用。
- 发布日期: 2025年4月15日
- 版本: 1.0
- 模型开发者: Red Hat (Neural Magic)
模型优化
该模型通过对Mistral-Small-3.1-24B-Instruct-2503的权重进行INT4量化获得。 此优化将每个参数的位数从16减少到4,磁盘大小和GPU内存需求减少了约75%。
仅量化了transformer块内的线性操作符权重。 权重采用对称分组量化方案,组大小为128。 使用llm-compressor库实现的GPTQ算法进行量化。
部署
该模型可以使用vLLM后端高效部署,如下例所示。
from vllm import LLM, SamplingParams
from transformers import AutoProcessor
model_id = "RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-FP8-dynamic"
number_gpus = 1
sampling_params = SamplingParams(temperature=0.7, top_p=0.8, max_tokens=256)
processor = AutoProcessor.from_pretrained(model_id)
messages = [{"role": "user", "content": "给我简单介绍一下大语言模型。"}]
prompts = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
outputs = llm.generate(prompts, sampling_params)
generated_text = outputs[0].outputs[0].text
print(generated_text)
vLLM还支持OpenAI兼容的服务。更多详情请参阅文档。
创建
创建详情
该模型通过运行以下代码片段使用[llm-compressor](https://github.com/vllm-project/llm-compressor)创建。from transformers import AutoProcessor
from llmcompressor.modifiers.quantization import GPTQModifier
from llmcompressor.transformers import oneshot
from llmcompressor.transformers.tracing import TraceableMistral3ForConditionalGeneration
from datasets import load_dataset, interleave_datasets
from PIL import Image
import io
# 加载模型
model_stub = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
model_name = model_stub.split("/")[-1]
num_text_samples = 1024
num_vision_samples = 1024
max_seq_len = 8192
processor = AutoProcessor.from_pretrained(model_stub)
model = TraceableMistral3ForConditionalGeneration.from_pretrained(
model_stub,
device_map="auto",
torch_dtype="auto",
)
# 纯文本数据子集
def preprocess_text(example):
input = {
"text": processor.apply_chat_template(
example["messages"],
add_generation_prompt=False,
),
"images": None,
}
tokenized_input = processor(**input, max_length=max_seq_len, truncation=True)
tokenized_input["pixel_values"] = tokenized_input.get("pixel_values", None)
tokenized_input["image_sizes"] = tokenized_input.get("image_sizes", None)
return tokenized_input
dst = load_dataset("neuralmagic/calibration", name="LLM", split="train").select(range(num_text_samples))
dst = dst.map(preprocess_text, remove_columns=dst.column_names)
# 文本+视觉数据子集
def preprocess_vision(example):
messages = []
image = None
for message in example["messages"]:
message_content = []
for content in message["content"]:
if content["type"] == "text":
message_content.append({"type": "text", "text": content["text"]})
else:
message_content.append({"type": "image"})
image = Image.open(io.BytesIO(content["image"]))
messages.append(
{
"role": message["role"],
"content": message_content,
}
)
input = {
"text": processor.apply_chat_template(
messages,
add_generation_prompt=False,
),
"images": image,
}
tokenized_input = processor(**input, max_length=max_seq_len, truncation=True)
tokenized_input["pixel_values"] = tokenized_input.get("pixel_values", None)
tokenized_input["image_sizes"] = tokenized_input.get("image_sizes", None)
return tokenized_input
dsv = load_dataset("neuralmagic/calibration", name="VLM", split="train").select(range(num_vision_samples))
dsv = dsv.map(preprocess_vision, remove_columns=dsv.column_names)
# 交错子集
ds = interleave_datasets((dsv, dst))
# 配置量化算法和方案
recipe = GPTQModifier(
ignore=["language_model.lm_head", "re:vision_tower.*", "re:multi_modal_projector.*"],
sequential_targets=["MistralDecoderLayer"],
dampening_frac=0.01,
targets="Linear",
scheme="W4A16",
)
# 定义数据整理器
def data_collator(batch):
import torch
assert len(batch) == 1
collated = {}
for k, v in batch[0].items():
if v is None:
continue
if k == "input_ids":
collated[k] = torch.LongTensor(v)
elif k == "pixel_values":
collated[k] = torch.tensor(v, dtype=torch.bfloat16)
else:
collated[k] = torch.tensor(v)
return collated
# 应用量化
oneshot(
model=model,
dataset=ds,
recipe=recipe,
max_seq_length=max_seq_len,
data_collator=data_collator,
num_calibration_samples=num_text_samples + num_vision_samples,
)
# 以compressed-tensors格式保存到磁盘
save_path = model_name + "-quantized.w4a16"
model.save_pretrained(save_path)
processor.save_pretrained(save_path)
print(f"模型和分词器保存至: {save_path}")
评估
该模型在OpenLLM排行榜任务(版本1)、MMLU-pro、GPQA、HumanEval和MBPP上进行了评估。 非编码任务使用lm-evaluation-harness评估,而编码任务使用evalplus的分支评估。 所有情况下均使用vLLM作为引擎。
评估详情
MMLU
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks mmlu \
--num_fewshot 5 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size auto
ARC挑战
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks arc_challenge \
--num_fewshot 25 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size auto
GSM8k
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.9,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks gsm8k \
--num_fewshot 8 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size auto
Hellaswag
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks hellaswag \
--num_fewshot 10 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size auto
Winogrande
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks winogrande \
--num_fewshot 5 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size auto
TruthfulQA
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks truthfulqa \
--num_fewshot 0 \
--apply_chat_template\
--batch_size auto
MMLU-pro
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks mmlu_pro \
--num_fewshot 5 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size auto
MMMU
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.9,max_images=8,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks mmmu_val
Clip Vit Large Patch14 336
基于Vision Transformer架构的大规模视觉语言预训练模型,支持图像与文本的跨模态理解
文本生成图像
Transformers

C
openai
5.9M
241
Fashion Clip
MIT
FashionCLIP是基于CLIP开发的视觉语言模型,专门针对时尚领域进行微调,能够生成通用产品表征。
文本生成图像
Transformers

英语
F
patrickjohncyh
3.8M
222
Gemma 3 1b It
Gemma 3是Google推出的轻量级先进开放模型系列,基于与Gemini模型相同的研究和技术构建。
文本生成图像
Transformers

G
google
2.1M
347
Blip Vqa Base
Bsd-3-clause
BLIP是一个统一的视觉语言预训练框架,擅长视觉问答任务,通过语言-图像联合训练实现多模态理解与生成能力
文本生成图像
Transformers

B
Salesforce
1.9M
154
CLIP ViT H 14 Laion2b S32b B79k
MIT
基于OpenCLIP框架在LAION-2B英文数据集上训练的视觉-语言模型,支持零样本图像分类和跨模态检索任务
文本生成图像
Safetensors
C
laion
1.8M
368
CLIP ViT B 32 Laion2b S34b B79k
MIT
基于OpenCLIP框架在LAION-2B英语子集上训练的视觉-语言模型,支持零样本图像分类和跨模态检索
文本生成图像
Safetensors
C
laion
1.1M
112
Pickscore V1
PickScore v1 是一个针对文本生成图像的评分函数,可用于预测人类偏好、评估模型性能和图像排序等任务。
文本生成图像
Transformers

P
yuvalkirstain
1.1M
44
Owlv2 Base Patch16 Ensemble
Apache-2.0
OWLv2是一种零样本文本条件目标检测模型,可通过文本查询在图像中定位对象。
文本生成图像
Transformers

O
google
932.80k
99
Llama 3.2 11B Vision Instruct
Llama 3.2 是 Meta 发布的多语言多模态大型语言模型,支持图像文本到文本的转换任务,具备强大的跨模态理解能力。
文本生成图像
Transformers

支持多种语言
L
meta-llama
784.19k
1,424
Owlvit Base Patch32
Apache-2.0
OWL-ViT是一个零样本文本条件目标检测模型,可以通过文本查询搜索图像中的对象,无需特定类别的训练数据。
文本生成图像
Transformers

O
google
764.95k
129
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers

支持多种语言
L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers

英语
C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统
中文
R
uer
2,694
98
AIbase是一个专注于MCP服务的平台,为AI开发者提供高质量的模型上下文协议服务,助力AI应用开发。
简体中文