🚀 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 |