Gemma 3 27b It Quantized.w4a16
這是google/gemma-3-27b-it的量化版本,支持視覺-文本輸入和文本輸出,通過權重量化和激活量化優化,可使用vLLM進行高效推理。
下載量 302
發布時間 : 6/4/2025
模型概述
基於google/gemma-3-27b-it的量化模型,支持多模態輸入和文本生成,適用於需要高效推理的場景。
模型特點
高效量化
採用INT4權重量化和FP16激活量化,顯著減少模型大小和推理資源需求。
多模態支持
支持視覺-文本輸入,能夠處理圖像和文本結合的複雜任務。
高效推理
優化後可通過vLLM進行高效部署和推理,提升處理速度。
模型能力
多模態理解
文本生成
圖像內容分析
使用案例
內容理解與生成
圖像內容描述
分析圖像內容並生成描述性文本
準確識別圖像中的主要元素和場景
多模態對話
結合圖像和文本輸入進行智能對話
提供與圖像內容相關的連貫回答
🚀 gemma-3-27b-it-quantized.w4a16
這是 google/gemma-3-27b-it 的量化版本,該模型支持視覺 - 文本輸入,輸出為文本。通過權重量化和激活量化等優化,可使用 vLLM 進行高效推理。
🚀 快速開始
本模型可使用 vLLM 後端進行高效部署,示例代碼如下:
from vllm import LLM, SamplingParams
from vllm.assets.image import ImageAsset
from transformers import AutoProcessor
# Define model name once
model_name = "RedHatAI/gemma-3-27b-it-quantized.w4a16"
# Load image and processor
image = ImageAsset("cherry_blossom").pil_image.convert("RGB")
processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
# Build multimodal prompt
chat = [
{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "What is the content of this image?"}]},
{"role": "assistant", "content": []}
]
prompt = processor.apply_chat_template(chat, add_generation_prompt=True)
# Initialize model
llm = LLM(model=model_name, trust_remote_code=True)
# Run inference
inputs = {"prompt": prompt, "multi_modal_data": {"image": [image]}}
outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
# Display result
print("RESPONSE:", outputs[0].outputs[0].text)
vLLM 還支持與 OpenAI 兼容的服務,更多詳情請參閱 文檔。
✨ 主要特性
模型概述
- 模型架構:google/gemma-3-27b-it
- 輸入:視覺 - 文本
- 輸出:文本
- 模型優化:
- 權重量化:INT4
- 激活量化:FP16
- 發佈日期:2025 年 4 月 6 日
- 版本:1.0
- 模型開發者:RedHatAI
模型優化
本模型通過將 google/gemma-3-27b-it 的權重量化為 INT4 數據類型獲得,可使用 vLLM >= 0.8.0 進行推理。
💻 使用示例
基礎用法
from vllm import LLM, SamplingParams
from vllm.assets.image import ImageAsset
from transformers import AutoProcessor
# Define model name once
model_name = "RedHatAI/gemma-3-27b-it-quantized.w4a16"
# Load image and processor
image = ImageAsset("cherry_blossom").pil_image.convert("RGB")
processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
# Build multimodal prompt
chat = [
{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "What is the content of this image?"}]},
{"role": "assistant", "content": []}
]
prompt = processor.apply_chat_template(chat, add_generation_prompt=True)
# Initialize model
llm = LLM(model=model_name, trust_remote_code=True)
# Run inference
inputs = {"prompt": prompt, "multi_modal_data": {"image": [image]}}
outputs = llm.generate(inputs, SamplingParams(temperature=0.2, max_tokens=64))
# Display result
print("RESPONSE:", outputs[0].outputs[0].text)
🔧 技術細節
模型創建
本模型使用 llm-compressor 創建,代碼如下:
模型創建代碼
import base64
from io import BytesIO
import torch
from datasets import load_dataset
from transformers import AutoProcessor, Gemma3ForConditionalGeneration
from llmcompressor.modifiers.quantization import GPTQModifier
from llmcompressor.transformers import oneshot
# Load model.
model_id = "google/gemma-3-27b-it"
model = Gemma3ForConditionalGeneration.from_pretrained(
model_id,
device_map="auto",
torch_dtype="auto",
)
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
# Oneshot arguments
DATASET_ID = "neuralmagic/calibration"
DATASET_SPLIT = {"LLM": "train[:1024]"}
NUM_CALIBRATION_SAMPLES = 1024
MAX_SEQUENCE_LENGTH = 2048
# Load dataset and preprocess.
ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
ds = ds.shuffle(seed=42)
dampening_frac=0.07
def data_collator(batch):
assert len(batch) == 1, "Only batch size of 1 is supported for calibration"
item = batch[0]
collated = {}
import torch
for key, value in item.items():
if isinstance(value, torch.Tensor):
collated[key] = value.unsqueeze(0)
elif isinstance(value, list) and isinstance(value[0][0], int):
# Handle tokenized inputs like input_ids, attention_mask
collated[key] = torch.tensor(value)
elif isinstance(value, list) and isinstance(value[0][0], float):
# Handle possible float sequences
collated[key] = torch.tensor(value)
elif isinstance(value, list) and isinstance(value[0][0], torch.Tensor):
# Handle batched image data (e.g., pixel_values as [C, H, W])
collated[key] = torch.stack(value) # -> [1, C, H, W]
elif isinstance(value, torch.Tensor):
collated[key] = value
else:
print(f"[WARN] Unrecognized type in collator for key={key}, type={type(value)}")
return collated
# Recipe
recipe = [
GPTQModifier(
targets="Linear",
ignore=["re:.*lm_head.*", "re:.*embed_tokens.*", "re:vision_tower.*", "re:multi_modal_projector.*"],
sequential_update=True,
sequential_targets=["Gemma3DecoderLayer"],
dampening_frac=dampening_frac,
)
]
SAVE_DIR=f"{model_id.split('/')[1]}-quantized.w4a16"
# Perform oneshot
oneshot(
model=model,
tokenizer=model_id,
dataset=ds,
recipe=recipe,
max_seq_length=MAX_SEQUENCE_LENGTH,
num_calibration_samples=NUM_CALIBRATION_SAMPLES,
trust_remote_code_model=True,
data_collator=data_collator,
output_dir=SAVE_DIR
)
模型評估
本模型使用 lm_evaluation_harness 進行 OpenLLM v1 文本基準測試,評估命令如下:
評估命令
OpenLLM v1
lm_eval \
--model vllm \
--model_args pretrained="<model_name>",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=<n>,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True,enforce_eager=True \
--tasks openllm \
--batch_size auto
準確率
類別 | 指標 | google/gemma-3-27b-it | RedHatAI/gemma-3-27b-it-quantized.w8a8 | 恢復率 (%) |
---|---|---|---|---|
OpenLLM V1 | ARC Challenge | 72.53% | 72.35% | 99.76% |
OpenLLM V1 | GSM8K | 92.12% | 91.66% | 99.51% |
OpenLLM V1 | Hellaswag | 85.78% | 84.97% | 99.06% |
OpenLLM V1 | MMLU | 77.53% | 76.77% | 99.02% |
OpenLLM V1 | Truthfulqa (mc2) | 62.20% | 62.57% | 100.59% |
OpenLLM V1 | Winogrande | 79.40% | 79.79%% | 100.50% |
OpenLLM V1 | 平均得分 | 78.26% | 78.02% | 99.70% |
視覺評估 | MMMU (val) | 50.89% | 51.78% | 101.75% |
視覺評估 | ChartQA | 72.16% | 72.20% | 100.06% |
視覺評估 | 平均得分 | 61.53% | 61.99% | 100.90% |
📄 許可證
本模型使用 gemma 許可證。
Clip Vit Large Patch14
CLIP是由OpenAI開發的視覺-語言模型,通過對比學習將圖像和文本映射到共享的嵌入空間,支持零樣本圖像分類
圖像生成文本
C
openai
44.7M
1,710
Clip Vit Base Patch32
CLIP是由OpenAI開發的多模態模型,能夠理解圖像和文本之間的關係,支持零樣本圖像分類任務。
圖像生成文本
C
openai
14.0M
666
Siglip So400m Patch14 384
Apache-2.0
SigLIP是基於WebLi數據集預訓練的視覺語言模型,採用改進的sigmoid損失函數,優化了圖像-文本匹配任務。
圖像生成文本
Transformers

S
google
6.1M
526
Clip Vit Base Patch16
CLIP是由OpenAI開發的多模態模型,通過對比學習將圖像和文本映射到共享的嵌入空間,實現零樣本圖像分類能力。
圖像生成文本
C
openai
4.6M
119
Blip Image Captioning Base
Bsd-3-clause
BLIP是一個先進的視覺-語言預訓練模型,擅長圖像描述生成任務,支持條件式和非條件式文本生成。
圖像生成文本
Transformers

B
Salesforce
2.8M
688
Blip Image Captioning Large
Bsd-3-clause
BLIP是一個統一的視覺-語言預訓練框架,擅長圖像描述生成任務,支持條件式和無條件式圖像描述生成。
圖像生成文本
Transformers

B
Salesforce
2.5M
1,312
Openvla 7b
MIT
OpenVLA 7B是一個基於Open X-Embodiment數據集訓練的開源視覺-語言-動作模型,能夠根據語言指令和攝像頭圖像生成機器人動作。
圖像生成文本
Transformers 英語

O
openvla
1.7M
108
Llava V1.5 7b
LLaVA 是一款開源多模態聊天機器人,基於 LLaMA/Vicuna 微調,支持圖文交互。
圖像生成文本
Transformers

L
liuhaotian
1.4M
448
Vit Gpt2 Image Captioning
Apache-2.0
這是一個基於ViT和GPT2架構的圖像描述生成模型,能夠為輸入圖像生成自然語言描述。
圖像生成文本
Transformers

V
nlpconnect
939.88k
887
Blip2 Opt 2.7b
MIT
BLIP-2是一個視覺語言模型,結合了圖像編碼器和大型語言模型,用於圖像到文本的生成任務。
圖像生成文本
Transformers 英語

B
Salesforce
867.78k
359
精選推薦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