Mistral 3.1与Gemma 3对比评测:哪个模型更好?

Mistral 3.1与Gemma 3对比评测

人工智能领域正在迅速发展,小型、轻量级模型因其高效性和可扩展性而日益突出。继谷歌 DeepMind 推出 27B 模型 Gemma 3 之后,Mistral AI 现在又发布了拥有 24B 参数的 Mistral 3.1 轻量级模型。这个全新、快速、可定制的模型重新定义了轻量级模型的功能。它可在单个处理器上高效运行,从而提高了速度,并使小型团队和组织更易于使用。在这篇 Mistral 3.1 与 Gemma 3 的对比中,我们将探讨它们的功能,评估它们在基准测试中的性能,并进行一些实际测试,以找出更好的模型。

什么是Mistral 3.1?

Mistral 3.1 是 Mistral AI 最新推出的大型语言模型(LLM),旨在以更低的计算要求提供更高的性能。它代表了向结构紧凑但功能强大的人工智能模型的转变,使高级人工智能功能更容易获得,更具成本效益。与需要大量资源的大型模型不同,Mistral 3.1 兼顾了可扩展性、速度和经济性,是实际应用的理想之选。

Mistral 3.1的主要功能

  • 轻便高效:可在单个 RTX 4090 或配备 32GB 内存的 Mac 上流畅运行,是设备上人工智能解决方案的理想选择。
  • 快速响应的对话式人工智能:针对需要快速、准确响应的虚拟助手和聊天机器人进行了优化。
  • 低延迟功能调用:支持自动化工作流和代理系统,以最小的延迟执行功能。
  • 微调能力:可专门用于法律人工智能、医疗诊断和技术支持,提供特定领域的专业知识。
  • 多模态理解:在图像处理、文档验证、诊断和物体检测方面表现出色,是各行各业的多面手。
  • 开源和可定制:提供基本检查点和指示检查点,可进一步为高级应用进行下游定制。

如何访问Mistral 3.1

Mistral 3.1 可通过多个平台获取。您可以通过 Hugging Face 下载并在本地运行,也可以使用 Mistral AI API 访问。

1. 通过Hugging Face访问Mistral 3.1

您可以从 Hugging Face 下载 Mistral 3.1 Base 和 Mistral 3.1 Instruct 以直接使用。以下是操作方法:

第 1 步:安装 vLLM Nightly

打开终端,运行此命令安装 vLLM(同时安装所需的 mistral_common 软件包):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly --upgrade
pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly --upgrade
pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly --upgrade

你可以通过运行下面命令验证安装:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
python -c "import mistral_common; print(mistral_common.__version__)"
python -c "import mistral_common; print(mistral_common.__version__)"
python -c "import mistral_common; print(mistral_common.__version__)"

第 2 步:准备 Python 脚本

创建一个新的 Python 文件(如offline_inference.py )并添加以下代码。确保将 model_name 变量设置为正确的模型 ID(例如,“mistralai/Mistral-Small-3.1-24B-Instruct-2503”):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
from vllm import LLM
from vllm.sampling_params import SamplingParams
# Define a system prompt (you can modify it as needed)
SYSTEM_PROMPT = "You are a conversational agent that always answers straight to the point, always end your accurate response with an ASCII drawing of a cat."
# Define the user prompt
user_prompt = "Give me 5 non-formal ways to say 'See you later' in French."
# Set up the messages for the conversation
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_prompt},
]
# Define the model name (make sure you have enough GPU memory or use quantization if needed)
model_name = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
# Initialize the LLM from vLLM with the specified model and tokenizer mode
llm = LLM(model=model_name, tokenizer_mode="mistral")
# Set sampling parameters (adjust max_tokens and temperature as desired)
sampling_params = SamplingParams(max_tokens=512, temperature=0.15)
# Run the model offline and get the response
outputs = llm.chat(messages, sampling_params=sampling_params)
# Print the generated text from the model's response
print(outputs[0].outputs[0].text)
from vllm import LLM from vllm.sampling_params import SamplingParams # Define a system prompt (you can modify it as needed) SYSTEM_PROMPT = "You are a conversational agent that always answers straight to the point, always end your accurate response with an ASCII drawing of a cat." # Define the user prompt user_prompt = "Give me 5 non-formal ways to say 'See you later' in French." # Set up the messages for the conversation messages = [ {"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": user_prompt}, ] # Define the model name (make sure you have enough GPU memory or use quantization if needed) model_name = "mistralai/Mistral-Small-3.1-24B-Instruct-2503" # Initialize the LLM from vLLM with the specified model and tokenizer mode llm = LLM(model=model_name, tokenizer_mode="mistral") # Set sampling parameters (adjust max_tokens and temperature as desired) sampling_params = SamplingParams(max_tokens=512, temperature=0.15) # Run the model offline and get the response outputs = llm.chat(messages, sampling_params=sampling_params) # Print the generated text from the model's response print(outputs[0].outputs[0].text)
from vllm import LLM
from vllm.sampling_params import SamplingParams
# Define a system prompt (you can modify it as needed)
SYSTEM_PROMPT = "You are a conversational agent that always answers straight to the point, always end your accurate response with an ASCII drawing of a cat."
# Define the user prompt
user_prompt = "Give me 5 non-formal ways to say 'See you later' in French."
# Set up the messages for the conversation
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_prompt},
]
# Define the model name (make sure you have enough GPU memory or use quantization if needed)
model_name = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
# Initialize the LLM from vLLM with the specified model and tokenizer mode
llm = LLM(model=model_name, tokenizer_mode="mistral")
# Set sampling parameters (adjust max_tokens and temperature as desired)
sampling_params = SamplingParams(max_tokens=512, temperature=0.15)
# Run the model offline and get the response
outputs = llm.chat(messages, sampling_params=sampling_params)
# Print the generated text from the model's response
print(outputs[0].outputs[0].text)

Step 3:离线运行脚本

  1. 保存脚本。
  2. 在保存脚本的目录下打开终端。
  3. 运行脚本:python offline_inference.py

模型将加载到本地,并根据您的提示生成响应。

重要注意事项

  • 硬件要求:在 GPU 上以全精度运行完整的 24B 模型通常需要超过 60 GB 的 GPU 内存。如果您的硬件达不到这个要求,请考虑
    • 使用模型的缩小或量化版本。
    • 使用有足够内存的 GPU。
  • 离线模式与服务器模式:该代码使用 vLLM Python API 来离线运行模型(即完全在本地计算机上运行,无需设置服务器)。
  • 修改提示:你可以根据自己的需要修改 SYSTEM_PROMPT 和 user_prompt。对于生产或更高级的使用,您可能希望添加一个系统提示,以帮助指导模型的行为。

2. 通过API访问Mistral 3.1

您也可以通过 API 访问 Mistral 3.1。具体步骤如下。

  1. 访问网站:访问 Mistral AI 登录或使用所有必要的详细信息登录。

访问 Mistral AI 登录

  1. 访问 API 部分:点击“Try the API”,探索可用选项。

访问 API

  1. 导航至 API:登录后,点击“API”管理或生成新密钥。

导航至 API

  1. 选择计划:当被要求生成 API 时,点击“Choose a Plan”以继续访问 API。

选择计划 选择计划

  1. 选择 “免费实验计划”:点击“Experiment for Free”,免费试用 API。

Experiment for Free

  1. 注册免费访问:完成注册流程,创建账户并访问 API。

创建账户并访问 API

  1. 创建新的 API 密钥:点击“Create New Key”,为您的项目生成新的 API 密钥。
  1. 配置 API 密钥:提供一个密钥名称,以便于识别。您甚至可以选择设置有效期,以提高安全性。

配置 API 密钥

  1. 最后确定并取回 API 密钥:点击“Create New Key”生成密钥。现在您的 API 密钥已经创建,可以在您的项目中使用。

确定并取回 API 密钥

您可以将此 API 密钥集成到您的应用程序中,以便与 Mistral 3.1 进行交互。

什么是Gemma 3?

Gemma 3 是由谷歌 DeepMind 设计的最先进的轻量级开放模型,可在高效利用资源的同时提供高性能。它基于为 Gemini 2.0 提供动力的相同研究和技术,以紧凑的形式提供先进的人工智能功能,使其成为各种硬件设备上应用的理想选择。Gemma 3 有 1B、4B、12B 和 27B 四种参数规格,使开发人员能够构建快速、可扩展和可访问的人工智能解决方案。

Gemma 3的主要功能

  • 在单个加速器上实现高性能:在 LMArena 的评估中,它的性能优于 Llama 3-405B 、DeepSeek-V3 和 o3-mini,是单位规模的最佳模型之一。
  • 多语言功能:支持 140 多种语言,实现人工智能驱动的全球交流。
  • 高级文本和视觉推理:可处理图像、文本和短视频,扩展交互式人工智能应用。
  • 扩展的上下文窗口:可处理多达 128k 标记,从而可进行更深入的分析并生成长篇内容。
  • 人工智能工作流程的功能调用:支持用于自动化和代理体验的结构化输出。
  • 优化效率:官方量化版本可在不影响准确性的前提下降低计算需求。
  • 内置安全的 ShieldGemma 2:提供图像安全检查,检测危险、露骨和暴力内容。

如何访问Gemma 3

Gemma 3 可通过多个平台随时访问,如 Google AI Studio、Hugging Face、Kaggle 等。

1. 通过Google AI Studio访问Gemma 3

此选项可让您在预配置的环境中与 Gemma 3 互动,而无需在自己的机器上安装任何东西。

第 1 步:打开浏览器,进入 Google AI Studio

第 2 步:使用谷歌账户登录。如果没有,请创建一个谷歌账户。

第 3 步:登录后,使用 AI Studio 的搜索栏查找使用“Gemma 3”的笔记本或演示项目。

提示: 查找标题为“Gemma 3”的项目,或查看“Community Notebooks”(社区笔记本)部分,那里通常会共享预配置演示。

第 4 步: 按以下步骤启动演示。

  • 点击笔记本打开。
  • 点击“Run”或“Launch”按钮,开始互动会话。
  • 笔记本会自动加载 Gemma 3 模型,并提供演示其功能的单元格示例。

第 5 步:按照笔记本中的说明开始使用模型。您可以修改输入文本、运行单元格并实时查看模型的响应,而无需任何本地设置。

2. 通过Hugging Face、Kaggle和Ollama访问Gemma 3

如果您想在自己的机器上使用 Gemma 3 或将其集成到您的项目中,可以从以下几个来源下载。

A. Hugging Face

第 1 步:访问 Hugging Face

第 2 步:使用搜索栏输入“Gemma 3”,然后点击与 Gemma 3 相对应的模型卡。

第 3 步:使用“Download”按钮下载模型,或通过 Git 克隆版本库。

如果使用 Python,请安装 Transformers 库:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pip install transformers
pip install transformers
pip install transformers

第 4 步:在代码中加载并使用模型。为此,你可以创建一个新的 Python 脚本(例如 gemma3_demo.py ),并添加类似下面代码段的代码:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "your-gemma3-model-id" # replace with the actual model ID from Hugging Face
model = AutoModelForCausalLM.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
prompt = "What is the best way to enjoy a cup of coffee?"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
from transformers import AutoModelForCausalLM, AutoTokenizer model_id = "your-gemma3-model-id" # replace with the actual model ID from Hugging Face model = AutoModelForCausalLM.from_pretrained(model_id) tokenizer = AutoTokenizer.from_pretrained(model_id) prompt = "What is the best way to enjoy a cup of coffee?" inputs = tokenizer(prompt, return_tensors="pt") outputs = model.generate(**inputs, max_new_tokens=50) print(tokenizer.decode(outputs[0], skip_special_tokens=True))
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "your-gemma3-model-id"  # replace with the actual model ID from Hugging Face
model = AutoModelForCausalLM.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
prompt = "What is the best way to enjoy a cup of coffee?"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

在本地运行脚本,与 Gemma 3 交互。

B. Kaggle

Step 1:在浏览器中打开 Kaggle

Step 2:使用 Kaggle 上的搜索栏搜索“Gemma 3”。查找使用该模型的笔记本或数据集。

Step 3: 点击相关笔记本,查看 Gemma 3 是如何集成的。你可以在 Kaggle 的环境中运行笔记本,也可以下载笔记本在本地机器上研究和修改。

C. Ollama

Step 1:访问 Ollama 并下载 Ollama 应用程序。

Step 2:在系统上启动 Ollama 应用程序,使用内置搜索功能在型号目录中查找 “Gemma 3”。

Step 3:点击 Gemma 3 型号,按照提示下载并安装。安装完成后,使用 Ollama 界面通过输入提示和查看响应来测试模型。

按照这些详细步骤,您既可以在 Google AI Studio 上立即试用 Gemma 3,也可以通过 Hugging Face、Kaggle 或 Ollama 下载 Gemma 3 进行开发。请选择最适合您的工作流程和硬件设置的方法。

Mistral Small 3.1与Gemma 3:功能比较

现在,让我们从它们的功能开始比较。下面是根据现有数据对 Gemma 3 和 Mistral Small 3.1 的功能进行的详细比较:

功能 Mistral Small 3.1 Gemma 3
参数 24B 有 1B、4B、12B 和 27B 四种型号可供选择
上下文窗口 多达 128K tokens 多达 128K tokens
多模态能力 支持文本和图像输入 支持文本和图像输入
推理速度 更快(每秒 150 个 tokens) 比 Mistral 慢
延迟 更低的延迟(0.33 秒到第一个 token) 更高的延迟
语言支持 支持数十种语言 140 多种语言
对话风格 干练的对话风格,但可通过系统提示加以改进 更像人类和 ChatGPT 风格的回复
推理能力 在 MMLU 等推理任务中的表现优于 Gemma 3 在推理方面表现出色,但不是顶级水平
是否开源 是的 (Apache 2.0 license) 是的

Mistral Small 3.1与Gemma 3:性能比较

在本节中,我们将比较 Gemma 3 和 Mistral 3.1 在一些实际操作任务中的表现。为了进行公平的比较,我们将在两个模型上尝试相同的提示,以下是我们将尝试的任务列表:

  1. 物体检测
  2. 视觉数据提取
  3. 可视化数据提取–打印文本

任务 1: 物体检测

在这项任务中,我们将给模型一张带有动物标志的糖果图片,并要求他们识别糖果上的动物。

提示词:Identity the animal in the image

输入图像:

图片中的动物是乌龟

输出

Mistral 3.1 Gemma 3
The candies in the image appear to be M&M’s, and the animal depicted on them is a turtle. The turtle design is visible on the blue, orange, and green candies. Let’s analyze the candy in the image! The animal on the candy is a turtle. You can see the shell and the head and legs of a turtle clearly imprinted on the surface.

对比分析

两个模型都能正确识别图片中的动物是乌龟。不过,Mistral 3.1 提供了更多的背景信息,指出糖果是 M&Ms 并提到了糖果的颜色。而 Gemma 3 则对乌龟的外形进行了较为笼统的描述。

结论:两个模型都成功地识别了物体,但 Mistral 3.1 提供的背景信息要稍微详细一些。因此,Mistral 3.1 赢得本轮比赛。

得分:Mistral 3.1: 1 | Gemma 3: 0

任务 2:视觉数据提取

为了测试模型的视觉数据提取能力,我们将向他们提供一张飞机图片,并要求他们从中提取车辆代码。

提示词:What is the code on the vehicle?

输入图像:

飞机

输出:

Mistral 3.1 Gemma 3
The code on the vehicle, which is an airplane, is “D-EOJU.” Based on the image, the vehicle is a Cessna 172 Skyhawk. The registration code on the tail is D-EOJU.

对比分析:

Mistral 3.1 和 Gemma 3 成功识别了飞机的注册代码。但是,Gemma 3 不仅识别了代码,还增加了额外的细节,如飞模型号。

结论:两个模型都准确提取了代码,但 Gemma 3 提供了更多关于车辆的背景细节。因此,Gemma 3 在这一项上得分。

得分:Mistral 3.1: 1 | Gemma 3: 1

任务 3:可视化数据提取

在最后一项任务中,我们将向他们提供一张 wifi 收据的图片,并要求他们从中提取 wifi 密码。

提示词:What is the password?

输入图片:

wifi 收据的图片

输出:

Mistral 3.1 Gemma 3
The password provided in the image is **aaeu**.Here is the information from the image for clarity:– **Username:** fqpp– **Password:** aaeu– **Traffic:** 1 GB– **Price:** 0.00– **Validity:** 1 week– **Starts:** Now– **Shared Users:** 4– **Date and Time:** 27/02/2019 11:03:15 Based on the image, the password is aaeu

对比分析:

两种模型都能从图像中准确提取密码。此外,Mistral 3.1 还提供了关于用户名、流量、价格、有效性和其他相关信息的额外细节,使其输出结果更加全面。

结论:Mistral 3.1 在提取和呈现结构化数据方面表现更好,提供了更有用的上下文。因此,Mistral 3.1 在这项任务中再得一分。

得分:Mistral 3.1:2 | Gemma 3:1

最终得分 Mistral 3.1: 2 | Gemma 3: 1

性能比较摘要

以下是两款模型在我们尝试的任务中的性能总结。

任务 Mistral 3.1 性能 Gemma 3 性能 胜出者
物体检测 正确识别出动物(乌龟),并提供了额外的上下文,提到糖果是 M&M,并说明了它们的颜色。 正确识别出动物是乌龟,并描述了乌龟的外形,但未提供更多背景细节。 Mistral 3.1
视觉数据提取(车辆代码) 成功从飞机图像中提取出注册码(“D-EOJU”)。 准确提取了注册码,并识别了飞模型号(Cessna 172 Skyhawk)。 Gemma 3
可视数据提取(打印文本) 正确提取了 WiFi 密码,并提供了其他结构化数据,如用户名、流量、价格、有效期和其他详细信息。 正确提取了 WiFi 密码,但未提供其他结构化信息。 Mistral 3.1

通过比较,我们发现 Mistral 3.1 在结构化数据提取和提供简洁而翔实的回复方面表现出色。同时,Gemma 3 在物体识别方面表现出色,在某些情况下还能提供更丰富的上下文细节。

对于需要快速、结构化和精确数据提取的任务,Mistral 3.1 是更好的选择。而对于上下文和附加描述信息非常重要的任务,Gemma 3 则更具优势。因此,最佳模型取决于具体的使用情况。

Mistral Small 3.1 与 Gemma 3:基准比较

现在让我们看看这两款模型在各种标准基准测试中的表现。在这次比较中,我们将关注测试这两种模型在处理文本、多语言内容、多模态内容和长文本方面能力的基准测试。我们还将考察预训练性能基准的结果。

Gemma 3 和 Mistral Small 3.1 都是经过各种基准评估的著名人工智能模型。

文本指示基准测试

文本指示基准测试

从图中我们可以看到

  • 在大多数基准测试中,Mistral 3.1 始终优于 Gemma 3,尤其是在 GPQA Main、GPQA Diamond 和 MMLU 中。
  • HumanEval 和 MATH 两种模型的性能几乎相同。
  • SimpleQA 的差异很小,表明两种模型在这一类别中都很吃力。
  • Mistral 3.1 在推理任务和常识任务(MMLU、GPQA)中遥遥领先,而 Gemma 3 则在与代码相关的基准测试(HumanEval、MATH)中紧随其后。

多模态教学基准测试

多模态教学基准测试

图表直观地说明了这一点:

  • 在大多数基准测试中,Mistral 3.1 始终优于 Gemma 3。
  • 在 ChartQA 和 DocVQA 中,Mistral 的性能差距最大。
  • MathVista 是最接近的竞争对手,两个模型的性能几乎相当。
  • Gemma 3 在基于文档的质量保证任务中表现落后,但在一般多模态任务中表现相对接近。

多语言和长语境基准测试

多语言和长语境基准测试

从图中我们可以看出

在多语言性能方面:

  • Mistral 3.1 在欧洲和东亚语言方面处于领先地位。
  • 在中东语言和平均多语言性能方面,两种模式的性能接近。

在长语境处理方面:

  • 在长语境任务中,特别是在 RULER 32k 和 RULER 128k 中,Mistral 明显优于 Gemma 3。
  • Gemma 3 在 LongBench v2 中落后较多,但在 RULER 32k 中仍具有竞争力。

预训练性能基准测试

预训练性能基准测试

从图中我们可以看出:

  • Mistral 3.1 在常识、事实回忆和推理任务中一直表现较好。
  • Gemma 3 在 GPQA 中的表现明显不如 Mistral 3.1。
  • TriviaQA 是最均衡的基准,两种模型的表现几乎相同。

小结

Mistral 3.1 和 Gemma 3 都是功能强大的轻量级人工智能模型,各自在不同的领域表现出色。Mistral 3.1 针对速度、低延迟和强大的推理能力进行了优化,是聊天机器人、编码和文本生成等实时应用的首选。它的效率和任务专用性进一步增强了它对性能驱动型人工智能任务的吸引力。

另一方面,Gemma 3 提供了广泛的多语言支持、多模态功能和极具竞争力的上下文窗口,使其非常适合全球人工智能应用、文档摘要和不同语言内容的生成。不过,与 Mistral 3.1 相比,它在速度和效率方面有所欠缺。

最终,在 Mistral 3.1 和 Gemma 3 之间做出选择取决于具体需求。Mistral 3.1 擅长性能驱动和实时应用,而 Gemma 3 则是多语言和多模态人工智能解决方案的理想选择。

评论留言