🚀 Gemma 3 for OpenArc 來襲!
本項目 OpenArc 是一個適用於 OpenVINO 的推理引擎,現已支持該模型,並通過與 OpenAI 兼容的端點為文本到文本 以及 文本與視覺任務提供推理服務!該版本將於今日或明日發佈。
我們擁有一個不斷壯大的 Discord 社區,社區成員都對使用英特爾技術進行人工智能/機器學習感興趣。

📦 安裝指南
此模型已使用以下 Optimum-CLI 命令轉換為 OpenVINO IR 格式:
optimum-cli export openvino -m ""input-model"" --task image-text-to-text --weight-format int8 ""converted-model""
要運行測試代碼,需執行以下步驟:
- 安裝特定設備的驅動程序
- 從源代碼為 OpenVINO 構建 Optimum-Intel
- 準備一些高質量的圖像
pip install optimum[openvino]+https://github.com/huggingface/optimum-intel
💻 使用示例
基礎用法
import time
from PIL import Image
from transformers import AutoProcessor
from optimum.intel.openvino import OVModelForVisualCausalLM
model_id = "Echo9Zulu/gemma-3-4b-it-int8_asym-ov"
ov_config = {"PERFORMANCE_HINT": "LATENCY"}
print("Loading model... this should get faster after the first generation due to caching behavior.")
print("")
start_load_time = time.time()
model = OVModelForVisualCausalLM.from_pretrained(model_id, export=False, device="CPU", ov_config=ov_config)
processor = AutoProcessor.from_pretrained(model_id)
end_load_time = time.time()
image_path = r""
image = Image.open(image_path)
image = image.convert("RGB")
conversation = [
{
"role": "user",
"content": [
{
"type": "image"
},
{"type": "text", "text": "Describe this image."},
],
}
]
text_prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
inputs = processor(text=[text_prompt], images=[image], padding=True, return_tensors="pt")
input_token_count = len(inputs.input_ids[0])
print(f"Sum of image and text tokens: {len(inputs.input_ids[0])}")
start_time = time.time()
output_ids = model.generate(**inputs, max_new_tokens=1024)
generated_ids = [output_ids[len(input_ids) :] for input_ids, output_ids in zip(inputs.input_ids, output_ids)]
output_text = processor.batch_decode(generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True)
num_tokens_generated = len(generated_ids[0])
load_time = end_load_time - start_load_time
generation_time = time.time() - start_time
tokens_per_second = num_tokens_generated / generation_time
average_token_latency = generation_time / num_tokens_generated
print("\nPerformance Report:")
print("-"*50)
print(f"Input Tokens : {input_token_count:>9}")
print(f"Generated Tokens : {num_tokens_generated:>9}")
print(f"Model Load Time : {load_time:>9.2f} sec")
print(f"Generation Time : {generation_time:>9.2f} sec")
print(f"Throughput : {tokens_per_second:>9.2f} t/s")
print(f"Avg Latency/Token : {average_token_latency:>9.3f} sec")
print(output_text)
測試代碼的作用是什麼?
測試代碼展示瞭如何在 Python 中進行推理,以及代碼中哪些部分對於性能基準測試至關重要。文本生成與包含圖像的文本生成面臨不同的挑戰;例如,視覺編碼器通常會採用不同的策略來處理圖像的各種屬性。在實際應用中,這可能會導致更高的內存使用、更低的吞吐量或較差的結果。
📄 許可證
本項目採用 Apache-2.0 許可證。
模型信息
屬性 |
詳情 |
基礎模型 |
google/gemma-3-4b-it |
標籤 |
OpenArc、OpenVINO、Optimum-Intel、image-text-to-text |