为什么微软的 Phi-4 14B 比 GPT-4o 和 o1 强太多了 —— 看结果就知道了

🚀 本文由一位4年实战出身的AI软硬件一体化解决者整理,专注从芯片、电路、GPU部署 → Linux系统、推理引擎 → 模型训练应用的完整链路。如果你也想搞懂AI模型部署、做自己的项目,建议收藏本文细读,有问题欢迎交流。

2024 年 1 月 7 日,微软在 Hugging Face 上发布了小型语言模型(SLM)“Phi-4”。这个模型采用 MIT 协议发布,可以自由用于商业用途并加以修改。

Phi-4 是微软“Phi”系列的最新模型,虽然是轻量级的,但在某些领域表现出色。特别是在数学推理方面,它的准确度甚至超过了一些大规模语言模型(LLM),在专门任务上的应用也因此受到关注。

Phi-4 通过高质量的数据和全新的后训练技术提升了准确度,并已发布至 Azure AI Foundry 和 Hugging Face。

这个模型的规模是 14B,如果是 4-bit 量化模型,基本上在一张还可以的显卡上就能跑起来。Meta 的 Llama3.2 和 Google 的 Gemma2 这两个开源模型的最小版本分别是 1B 和 2B,那这个就大了一整圈。

我不太清楚微软对“小型”的定义是什么,不过反正这是个可以自由使用、很好上手的模型。

在这个逐步引导里,我们会讲清楚 Phi-4 是什么、Phi-4 有什么特别之处、怎么在本地用 Phi-4、以及为什么它比 LLM 表现更好。

Phi-4 是什么?

Phi-4 是一种尝试,展示一种与传统 AI 模型不同的路径。它的特点是参数量相对较小,仅有 140 亿,但相比 Google 的 Gemini Pro 1.5 等大规模 AI 模型却表现出更强的性能。

尤其值得注意的是它在数学推理方面的高能力。在由美国数学协会(MAA)主办的美国数学竞赛(AMC)上,Phi-4 在需要逻辑思维的问题(比如复杂方程求解和数学证明)中超过了大模型。

这个结果说明它在那些对数字计算精度要求极高的领域(比如科研、工程、金融建模)中有使用的可能性。

Phi-4 有什么特别之处?

Phi-4 的基准测试结果如下:

  • 在 MATH 和 MGSM 测试中得分超过 80%,比 Google Gemini Pro 和 OpenAI 的 GPT-4o-mini 表现更好。
  • 数学推理技能表现优异,这在金融、工程和科研领域非常重要。
  • 在程序测试 HumanEval 上表现良好。

另外,Phi-4 的架构和训练过程非常强调精度与效率。它是一个 140 亿参数的纯解码器 Transformer 模型,在一个共计 9.8 万亿 token 的混合真实与合成数据集上训练而成。

在训练方法上,微软团队使用了监督微调和 DPO(直接偏好优化)方法,以确保性能可靠,同时解决公平性和稳定性等问题。

微软强调 Phi-4 的训练过程遵循负责任的 AI 开发原则,并进行了大量的安全评估,包括攻击测试,以降低偏见、有害内容和错误信息的风险。

本地安装

💡 像这种本地部署场景,其实正是我这类AI开发从业者最常解决的问题之一。项目落地中遇到性能瓶颈、模型运行不了、参数不清楚……我们都踩过坑,也做过商业化落地。想搞AI项目但不知道怎么配套软硬件?可以看完这部分内容后私信我聊聊。

在 Hugging Face 上的模型体积相当大,大概有 30GB,我的电脑跑起来有点吃力。

我当时在想是不是可以通过 4-bit 量化之类的方法让它能跑起来,结果发现 Ollama 已经提供了一个量化成 Q4_K_M 的模型,真是谢天谢地,于是我借用了它,并想分享一下我记的操作笔记。

下载

ollama run phi4

注意:模型加载到内存后会超过 10GB,所以如果你在 CPU 上跑,需要有至少那么多的内存空闲;如果你在 GPU 上跑,那 GPU 显存也必须至少这么多,否则会报错。

如果模型下载成功,你会看到这个提示:

>>> Send a message (/? for help)

看到这个提示之后,就可以试着发送消息啦。如果你是在 GPU 加速环境下跑,响应速度会非常快。

>>> Hello!

Hello! Please let me know how I can assist you. If you have any questions, feel free to ask.

>>> Send a message (/? for help)

就这么简单,我现在就能在本地用 Phi-4 啦!这真的太方便了!

现在,你可以用 Ollama 在自己电脑上轻松跑起 Phi-4!甚至还有 REST API!

这就意味着,一个接近 70B 参数性能的模型可以在一台笔记本上跑起来,借助 Ollama 的 REST API 功能,可以很快设置好一个环境,让别的应用和库本地调用。未来怎么用它,还有很多玩法值得期待。

Phi-4 vs GPT-4o vs o1

我们来对比一下 o1 和 GPT-4o,并验证一下 Phi-4 的表现到底如何。

接下来我想给出一些应用问题,看看和 GPT-4o 以及 o1 的结果是不是不一样,以及是否更简洁。

我们要测试的问题如下:

  1. 求以下数列的第 20 项:1, 1, 2, 3, 5, 8, …
  2. 某银行提供年利率 5%,半年复利一次。如果存入 100 万美元 10 年后是多少?
  3. 一个长方体体积是 120 立方厘米,高为 6cm,宽为 4cm,求它的长?

问题 1:测试准确率、简洁性、响应时间
问题 2:测试利率计算准确度
问题 3:测试几何推理能力

接下来我们来解题,输入以下内容:

The sequence given is the Fibonacci sequence, where each term is the sum of the two preceding ones, starting with 1 and 1. The first few terms are:

( F_1 = 1 )
( F_2 = 1 )
( F_3 = F_1 + F_2 = 1 + 1 = 2 )
( F_4 = F_2 + F_3 = 1 + 2 = 3 )
( F_5 = F_3 + F_4 = 2 + 3 = 5 )
( F_6 = F_4 + F_5 = 3 + 5 = 8 )
We need to find the 20th term, ( F_{20} ).

Continuing the sequence:

( F_7 = F_5 + F_6 = 5 + 8 = 13 )
( F_8 = F_6 + F_7 = 8 + 13 = 21 )
( F_9 = F_7 + F_8 = 13 + 21 = 34 )
( F_{10} = F_8 + F_9 = 21 + 34 = 55 )
( F_{11} = F_9 + F_{10} = 34 + 55 = 89 )
( F_{12} = F_{10} + F_{11} = 55 + 89 = 144 )
( F_{13} = F_{11} + F_{12} = 89 + 144 = 233 )
( F_{14} = F_{12} + F_{13} = 144 + 233 = 377 )
( F_{15} = F_{13} + F_{14} = 233 + 377 = 610 )
( F_{16} = F_{14} + F_{15} = 377 + 610 = 987 )
( F_{17} = F_{15} + F_{16} = 610 + 987 = 1597 )
( F_{18} = F_{16} + F_{17} = 987 + 1597 = 2584 )
( F_{19} = F_{17} + F_{18} = 1597 + 2584 = 4181 )
( F_{20} = F_{18} + F_{19} = 2584 + 4181 = 6765 )
Thus, the 20th value of the sequence is ( \boxed{6765} ).

Phi-4

The sequence given is the Fibonacci sequence, where each term is the sum of the two preceding ones, starting with 1 and 1. The first few terms are:

( F_1 = 1 )
( F_2 = 1 )
( F_3 = F_1 + F_2 = 1 + 1 = 2 )
( F_4 = F_2 + F_3 = 1 + 2 = 3 )
( F_5 = F_3 + F_4 = 2 + 3 = 5 )
( F_6 = F_4 + F_5 = 3 + 5 = 8 )
We need to find the 20th term, ( F_{20} ).

Continuing the sequence:

( F_7 = F_5 + F_6 = 5 + 8 = 13 )
( F_8 = F_6 + F_7 = 8 + 13 = 21 )
( F_9 = F_7 + F_8 = 13 + 21 = 34 )
( F_{10} = F_8 + F_9 = 21 + 34 = 55 )
( F_{11} = F_9 + F_{10} = 34 + 55 = 89 )
( F_{12} = F_{10} + F_{11} = 55 + 89 = 144 )
( F_{13} = F_{11} + F_{12} = 89 + 144 = 233 )
( F_{14} = F_{12} + F_{13} = 144 + 233 = 377 )
( F_{15} = F_{13} + F_{14} = 233 + 377 = 610 )
( F_{16} = F_{14} + F_{15} = 377 + 610 = 987 )
( F_{17} = F_{15} + F_{16} = 610 + 987 = 1597 )
( F_{18} = F_{16} + F_{17} = 987 + 1597 = 2584 )
( F_{19} = F_{17} + F_{18} = 1597 + 2584 = 4181 )
( F_{20} = F_{18} + F_{19} = 2584 + 4181 = 6765 )
Thus, the 20th value of the sequence is ( \boxed{6765} ).

GPT-4o

The sequence given is the **Fibonacci sequence**, where each term is the sum of the two preceding terms:

\[F(n) = F(n-1) + F(n-2) \quad \text{for } n \geq 3\]
with \( F(1) = 1 \) and \( F(2) = 1 \).

We need to compute the **20th value** of this sequence.

The first few terms are:
1. \( F(1) = 1 \)
2. \( F(2) = 1 \)
3. \( F(3) = 2 \)
4. \( F(4) = 3 \)
5. \( F(5) = 5 \)
6. \( F(6) = 8 \)
7. \( F(7) = 13 \)
8. \( F(8) = 21 \)
9. \( F(9) = 34 \)
10. \( F(10) = 55 \)
11. \( F(11) = 89 \)
12. \( F(12) = 144 \)
13. \( F(13) = 233 \)
14. \( F(14) = 377 \)
15. \( F(15) = 610 \)
16. \( F(16) = 987 \)
17. \( F(17) = 1597 \)
18. \( F(18) = 2584 \)
19. \( F(19) = 4181 \)
20. \( F(20) = 6765 \)


Thus, the 20th value in the sequence is: 6765

o1

The given sequence is the Fibonacci sequence, defined by:

\[F_1 = 1, \quad F_2 = 1, \quad \text{and} \quad F_{n} = F_{n-1} + F_{n-2} \text{ for } n > 2.\]

To find the 20th term, let's list them out (or recall the known values):

1. \( F_
1 = 1 \)
2. \( F_2 = 1 \)
3. \( F_
3 = 2 \)
4. \( F_4 = 3 \)
5. \( F_
5 = 5 \)
6. \( F_6 = 8 \)
7. \( F_
7 = 13 \)
8. \( F_8 = 21 \)
9. \( F_
9 = 34 \)
10. \( F_{10} = 55 \)
11. \( F_
{11} = 89 \)
12. \( F_{12} = 144 \)
13. \( F_
{13} = 233 \)
14. \( F_{14} = 377 \)
15. \( F_
{15} = 610 \)
16. \( F_{16} = 987 \)
17. \( F_
{17} = 1597 \)
18. \( F_{18} = 2584 \)
19. \( F_
{19} = 4181 \)
20. \( F_{20} = 6765 \)

Therefore, the 20th value in the sequence is: 6765

所有模型都能给出正确答案,但 Phi-4 的解题方式对数学基础不太好的人比较友好。响应时间上也没啥大差别。

我们继续试第二题,使用这个提示词:

A bank offers an annual interest rate of 5%, compounded semi-annually.
What is the final amount if 1 million dollar is deposited for 10 years?

Phi-4

To calculate the final amount when interest is compounded semi-annually, we can use the compound interest formula:

[ A = P \left(1 + \frac{r}{n}\right)^{nt} ]

where:

( A ) is the final amount
( P ) is the principal amount (initial deposit)
( r ) is the annual interest rate (in decimal form)
( n ) is the number of times the interest is compounded per year
( t ) is the number of years
For this problem:

( P = 1,000,000 ) dollars
( r = 0.05 ) (5% as a decimal)
( n = 2 ) (compounded semi-annually)
( t = 10 ) years
Plugging the values into the formula:

[ A = 1,000,000 \left(1 + \frac{0.05}{2}\right)^{2 \times 10} ]

[ A = 1,000,000 \left(1 + 0.025\right)^{20} ]

[ A = 1,000,000 \times (1.025)^{20} ]

Now, calculate ( (1.025)^{20} ):

[ (1.025)^{20} \approx 1.638616 ]

Therefore:

[ A \approx 1,000,000 \times 1.638616 ]

[ A \approx 1,638,616 ]

The final amount after 10 years is approximately $1,638,616.

GPT-4o

To calculate the final amount with compound interest, you can use the formula:

\[ A = P \left(1 + \frac{r}{n}\right)^{nt} \]

where:
- \( A \) is the final amount,
- \( P \) is the principal amount (initial deposit),
- \( r \) is the annual nominal interest rate (as a decimal),
- \( n \) is the number of times the interest is compounded per year,
- \( t \) is the number of years.

Given:
- \( P = 1,000,000 \) dollars,
- \( r = 0.05 \) (5%),
- \( n = 2 \) (since the interest is compounded semi-annually),
- \( t = 10 \).

Plug these values into the formula:

\[ A = 1,000,000 \left(1 + \frac{0.05}{2}\right)^{2 \times 10} \]
\[ A = 1,000,000 \left(1 + 0.025\right)^{20} \]
\[ A = 1,000,000 \times (1.025)^{20} \]

Now calculate \( (1.025)^{20} \):

\[ (1.025)^{20} \approx 1.6386164403 \]

Now find the final amount \( A \):

\[ A \approx 1,000,000 \times 1.6386164403 \]
\[ A \approx 1,638,616.44 \]

The final amount after 10 years will be approximately \$1,638,616.44.

o1

To calculate the final amount for a \$1,000,000 deposit with an annual interest rate of 5% compounded semi-annually over 10 years, you can use the compound interest formula:

\[
A = P \left(1 + \frac{r}{n}\right)^{nt}
\]

Where:
- \( A \) = the amount of money accumulated after n years, including interest.
- \( P \) = the principal amount (\$1,000,000).
- \( r \) = the annual interest rate (decimal) (5% or 0.05).
- \( n \) = the number of times that interest is compounded per year (2 for semi-annually).
- \( t \) = the time the money is invested for in years (10).

Plugging in the values:

\[
A = 1,000,000 \times \left(1 + \frac{0.05}{2}\right)^{2 \times 10} = 1,000,000 \times (1.025)^{20}
\]

Calculating \( (1.025)^{20} \):

\[
(1.025)^{20} \approx 1.63862
\]

Now, multiply this by the principal:

\[
A \approx 1,000,000 \times 1.63862 = 1,638,620
\]

**Final Amount:** After 10 years, the investment will grow to approximately **\$1,638,620**.

三个模型都能算对。o1 明显更快,只用了 11.38 毫秒。GPT-4o 和 Phi-4 慢一些,Phi-4 比 GPT-4o 还稍慢。

最后一个测试:几何推理能力

使用这个提示词:

If the volume of a rectangular prism is 120 cubic centimetres,
its height is 6 cm, and its width is 4 cm, what is its length?

Phi-4

To find the length of the rectangular prism, we can use the formula for the volume of a rectangular prism:

[ \text{Volume} = \text{Length} \times \text{Width} \times \text{Height} ]

Given:

Volume = 120 cubic centimeters
Height = 6 cm
Width = 4 cm
Substitute the known values into the formula:

[ 120 = \text{Length} \times 4 \times 6 ]

Simplify the equation:

[ 120 = \text{Length} \times 24 ]

To solve for the Length, divide both sides by 24:

[ \text{Length} = \frac{120}{24} ]

Calculate the division:

[ \text{Length} = 5 ]

Thus, the length of the rectangular prism is 5 cm.

GPT-4o

To find the length of the rectangular prism, you can use the formula for the volume of a rectangular prism:

\[ \text{Volume} = \text{length} \times \text{width} \times \text{height} \]

You are given the volume (120 cubic centimeters), the height (6 cm), and the width (4 cm). Plug these values into the formula:

\[ 120 = \text{length} \times 4 \times 6 \]

First, calculate \(4 \times 6\):

\[ 120 = \text{length} \times 24 \]

Next, solve for the length by dividing both sides of the equation by 24:

\[ \text{length} = \frac{120}{24} \]

\[ \text{length} = 5 \]

Thus, the length of the rectangular prism is 5 centimeters.

o1

To find the **length** of the rectangular prism, you can use the formula for the volume of a rectangular prism:

\[
\text{Volume} = \text{Length} \times \text{Width} \times \text{Height}
\]

Given:
- **Volume (V)** = 120 cubic centimetres (cm³)
- **Height (h)** = 6 centimetres (cm)
- **Width (w)** = 4 centimetres (cm)

**Step 1: Write down the formula with the known values.**

\[
120 = \text{Length} \times 4 \times 6
\]

**Step 2: Simplify the equation to solve for Length.**

\[
\text{Length} = \frac{120}{4 \times 6}
\]

\[
\text{Length} = \frac{120}{24}
\]

\[
\text{Length} = 5 \text{ cm}
\]

**Answer:** The length of the rectangular prism is **5 centimetres**.

三个模型都答对了,但 o1 和 Phi-4 的推理方式更像人类那种一步步思考的方式。让我惊讶的是 GPT-4o 在推理能力上没 o1 和 Phi-4 强。

总结:

我对比了 Phi-4、GPT-4o 和 o1,速度基本差不多。Phi-4 是开源的,我本身更喜欢开源。虽然 o1 更快更强,我还是更愿意用 Phi-4。我觉得 Phi-4 和其他模型的差距不大,而且它小到可以在我的笔记本上运行,这点对我很重要,因为我没有性能强大的电脑。

📌 总结完这篇之后,如果你也想把类似 Phi-4 这种模型跑在自己的机器上,甚至部署为产品、连上数据库、配接口……那恭喜你,已经走在大多数人前面了。

我也整理了不少相关图文方案与完整开发流程,适合AI从业者和初学者,欢迎来百度搜索关键词「AI软硬件一体解决者」,或者直接私信我。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值