「Phi-4-mini-flash-reasoning」を試す
公式ブログ
最先端のアーキテクチャが推論モデルの速度を再定義
マイクロソフトは、Phi モデルファミリーの新製品**「Phi-4-mini-flash-reasoning」**を発表いたします。この新モデルは、計算能力、メモリ、レイテンシが厳しく制約されるシナリオ向けに専用設計されており、エッジデバイス、モバイルアプリケーション、その他のリソース制約の厳しい環境において、高度な推論機能を提供するように開発されています。この新モデルはPhi-4-miniをベースにしていますが、新しいハイブリッドアーキテクチャを採用し、最大10倍の処理速度と平均2~3倍の遅延削減を実現し、推論性能を犠牲にすることなく大幅に高速な推論を可能にします。効率性と柔軟性を求める現実世界のソリューションを駆動するために、Phi-4-mini-flash-reasoningは本日よりAzure AI Foundry、NVIDIA API Catalog、およびHugging Faceで利用可能です。]
モデル
Colaboratory L4で。
パッケージインストール
!pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu124
!pip install transformers==4.46.1 accelerate==1.4.0
!pip install flash_attn==2.7.4.post1 --no-build-isolation
!pip install causal-conv1d==1.5.0.post8
mambaのビルドに失敗するので、mambaのGitHubレポジトリのIssueを参考に、ここはレポジトリからインストール。
!git clone https://github.com/state-spaces/mamba.git
%cd mamba
!CAUSAL_CONV1D_FORCE_BUILD=TRUE CAUSAL_CONV1D_SKIP_CUDA_BUILD=TRUE CAUSAL_CONV1D_FORCE_CXX11_ABI=TRUE pip install --no-build-isolation .
モデルとトークナイザーをロード
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
torch.random.manual_seed(0)
model_id = "microsoft/Phi-4-mini-flash-reasoning"
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="cuda",
torch_dtype="auto",
trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
VRAMは8GBぐらい
Thu Jul 10 14:40:28 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.15 Driver Version: 550.54.15 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA L4 Off | 00000000:00:03.0 Off | 0 |
| N/A 43C P0 28W / 72W | 7607MiB / 23034MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
では推論
messages = [{
"role": "user",
"content": "3*x^2+4*x+5=1 はどうやって解く?"
}]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt",
)
outputs = model.generate(
**inputs.to(model.device),
max_new_tokens=32768,
temperature=0.6,
top_p=0.95,
do_sample=True,
)
outputs = tokenizer.batch_decode(outputs[:, inputs["input_ids"].shape[-1]:])
print(outputs[0])
<think>
嗯,我现在要解这个方程3x² +4x +5=1。好,首先我应该把方程整理一下,看看能不能简化。原式是3x² +4x +5=1,对吧?那我可以两边都减1,这样右边就变成0了,左边就是3x² +4x +5-1,也就是3x² +4x +4=0。对吧?这样的话,方程就变成了标准的二次方程形式ax² +bx +c=0,其中a是3,b是4,c是4。
接下来,我应该用求根公式来解这个方程。求根公式是x等于负B加或减平方根号下B²-4AC的两倍起子,除以2A。对吧?所以代入这里的值的话,B是4,A是3,C是4。那判别式D就是B²-4AC,也就是4² -4*3*4。计算一下,4的平方是16,4乘3是12,12乘4是48。所以D=16-48=-32。哎,判别式是负数的话,那这个方程的解就是复数了,对吧?
不过题目里没有说要实数解还是允许复数解,所以可能需要继续算下去。接下来,根就是[-4 ± √(-32)]/(2*3)。平方根下的负数可以写成i乘以根号下正数,所以√(-32)=i√32。然后√32可以简化,32是16乘2,所以√32=√16*√2=4√2。所以整个根就是[-4 ± i*4√2]/6。然后分子和分母都可以约分,分子有公因数4,分母是6,可以分成2和3。所以分子每个项都除以2,得到[-2 ± i*2√2]/3。或者写成-2/3 ± (2√2/3)i。这样应该就是最简形式了。
不过,我是不是哪里算错了?再检查一遍。原方程3x²+4x+5=1,移项后3x²+4x+4=0,没错。判别式D=4²-4*3*4=16-48=-32,没错。所以根确实是复数解,按照求根公式得出的结果是对的。或者有没有其他解法?比如配方法?也许试试看配方法会不会更简单。
配方法的话,首先系数a是3,所以先把方程两边都除以3,得到x² + (4/3)x + (4/3) = 0。不过这样可能不太好处理,或者保持原式,用配方法来做。原方程是3x² +4x +4=0。配方步骤应该是先把x的系数提取出来,比如3(x² + (4/3)x) +4=0。然后在括号里配方,x² + (4/3)x,需要加一个数使得平方完毕。系数的一半是(4/3)/2=2/3,平方就是(2/3)²=4/9。所以需要加4/9,但是要保持等式成立,所以后面要减掉同样的量。于是方程变成3[(x² + (4/3)x +4/9) -4/9] +4=0,也就是3(x + 2/3)^2 -3*(4/9) +4=0。计算一下,3*(4/9)=4/3,所以方程变为3(x + 2/3)^2 -4/3 +4=0。然后-4/3 +4等于-4/3 +12/3=8/3。所以方程是3(x + 2/3)^2 +8/3=0。移项得到3(x + 2/3)^2 = -8/3,两边除以3,得到(x + 2/3)^2 = -8/9。这时候开平方的话,右边是负数,所以解为x + 2/3 = ±√(-8/9)=±i√(8/9)=±i*(2√2)/3。然后两边减2/3,得到x= -2/3 ± (2√2/3)i,和之前的结果一样。所以两种方法都得到了同样的解,说明答案正确。
或者还可以用求根公式直接代入,结果应该一致。看来我的计算是对的,所以最终的解应该是x等于负二分之三加减二乘平方根二分之三i,也就是写成-2/3 ± (2√2/3)i。或者也可以写成分数形式,分母统一。总之,这个方程的解是复数,没有实数解,因为判别式是负数。所以正确的解应该就是这个复数解了。有没有可能哪里出错了?比如系数计算或者符号问题?再检查一遍原方程:3x²+4x+5=1,移项后3x²+4x+4=0,没错。判别式计算正确,得到-32,没错。根的表达式代入也没问题,所以应该没问题。
总结一下,这个二次方程的解是复数,两个复数根,分别是x等于负二分之三加上或减去二分之二平方根二乘以i,也就是写成x = (-2 ± 2i√2)/3,或者简化为x = -2/3 ± (2√2/3)i。这应该就是正确的解了。
</think>
要解方程 \(3x^2 + 4x + 5 = 1\),首先移项整理为标准二次方程形式:
\[
3x^2 + 4x + 4 = 0
\]
使用求根公式 \(x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\),其中 \(a = 3\),\(b = 4\),\(c = 4\)。计算判别式:
\[
\Delta = 4^2 - 4 \cdot 3 \cdot 4 = 16 - 48 = -32
\]
由于判别式为负数,解为复数。代入公式得:
\[
x = \frac{-4 \pm \sqrt{-32}}{6} = \frac{-4 \pm 4i\sqrt{2}}{6} = \frac{-2 \pm 2i\sqrt{2}}{3}
\]
进一步简化为:
\[
x = -\frac{2}{3} \pm \frac{2\sqrt{2}}{3}i
\]
**答案**:
\(\boxed{x = -\dfrac{2}{3} \pm \dfrac{2\sqrt{2}}{3}i}\)<|end|>
思考過程も回答も中国語になってる。「回答は日本語で。」とかを指示しても中国語になる。
一応モデルカードには以下とあるので、中国語は多少なりとも学習データに含まれているが、日本語は含まれていないということなのかも。
- サービスの品質:Phi モデル は、主に英語のテキストと一部の多言語テキストを用いてトレーニングされています。英語以外の言語では、パフォーマンスが低下するほか、英語以外の言語間でパフォーマンスのばらつきが生じる場合があります。トレーニングデータでの使用頻度が低い英語の方言は、標準的なアメリカ英語よりもパフォーマンスが低下する場合があります。
モデルカード通りに英語だとこうなる
messages = [{
"role": "user",
"content": "How to solve 3*x^2+4*x+5=1?"
}]
(snip)
<think>
Okay, so I need to solve the equation 3x² + 4x + 5 = 1. Hmm, let's see. First, I remember that to solve a quadratic equation, I should get everything on one side so that the equation equals zero. That way, I can maybe factor it or use the quadratic formula. Let me try subtracting 1 from both sides to move that over.
So, subtracting 1 from both sides gives me 3x² + 4x + 5 - 1 = 0. Simplifying that, 5 - 1 is 4, so now the equation is 3x² + 4x + 4 = 0. Alright, now it's in the standard quadratic form ax² + bx + c = 0, where a is 3, b is 4, and c is 4.
Next, I need to figure out how to solve this quadratic. I know that if it factors nicely, that would be the easiest way, but I don't remember off the top of my head if 3x² + 4x + 4 factors. Let me check. The product of a and c is 3*4 = 12. I need two numbers that multiply to 12 and add up to b, which is 4. Let's see: 2 and 6 multiply to 12 but add to 8. 3 and 4 multiply to 12 and add to 7. Hmm, 12 is also 12 and 1, but that adds to 13. Doesn't look like there are numbers that multiply to 12 and add to 4. So factoring might not work here.
Since factoring doesn't seem possible, I should use the quadratic formula. The quadratic formula is x = [-b ± √(b² - 4ac)] / (2a). Let me plug in the values. Here, a is 3, b is 4, and c is 4.
First, compute the discriminant, which is b² - 4ac. Let's calculate that step by step. b squared is 4² = 16. Then, 4ac is 4*3*4. Let me compute that: 4*3 is 12, and 12*4 is 48. So, the discriminant is 16 - 48. That equals -32. Wait, the discriminant is negative? That means there are no real solutions, only complex ones.
So, the solutions will be complex numbers. Let me proceed with the quadratic formula. The formula becomes x = [-4 ± √(-32)] / (2*3). The square root of -32 can be written as √(32)*i, where i is the imaginary unit. Simplifying √32, since 32 is 16*2, so √32 is √16*√2 = 4√2. Therefore, √(-32) is 4√2 i.
Now, substituting back into the formula: x = [-4 ± 4√2 i]/6. I can simplify this fraction by dividing numerator and denominator by 2. Dividing numerator terms by 2: -4/2 = -2, and 4√2 i /2 = 2√2 i. The denominator 6 divided by 2 is 3. So, the simplified solutions are x = [-2 ± 2√2 i]/3.
Alternatively, I can factor out a 2 in the numerator: x = [2(-1 ± √2 i)] / 3, which can be written as x = (-1 ± √2 i)/1.5, but it's probably better to leave it as fractions. So, the final solutions are x = (-2 + 2√2 i)/3 and x = (-2 - 2√2 i)/3.
Wait, let me double-check my steps to make sure I didn't make a mistake. Starting from the original equation: 3x² +4x +5 =1. Subtract 1: 3x² +4x +4=0. Correct. Discriminant: 4² -4*3*4 =16 -48= -32. Yes. Then sqrt(-32)=4√2 i. Right. Then plug into the formula: (-4 ±4√2 i)/6. Divide numerator and denominator by 2: (-2 ±2√2 i)/3. Yes, that's correct.
So, the solutions are complex numbers: (-2 ± 2√2 i)/3. I think that's it. Let me just write them in the standard form a + bi. So, splitting the numerator: -2/3 ± (2√2)/3 i. So, the solutions are x = (-2/3) + (2√2/3)i and x = (-2/3) - (2√2/3)i.
Yep, that looks right. No real solutions because the discriminant is negative, but two complex solutions. I don't think I made any mistakes here. Let me confirm once more. Original equation: 3x² +4x +5=1. Subtract 1: 3x² +4x +4=0. Discriminant: 16 -48= -32. Quadratic formula gives (-4 ± sqrt(-32))/6. Simplify sqrt(-32) as 4i√2. Then divide numerator and denominator by 2: (-2 ±2i√2)/3. Correct. So the answer is x equals negative two-thirds plus or minus two root two over three i. Yep, that's the solution.
</think>
To solve the quadratic equation \(3x^2 + 4x + 5 = 1\), follow these steps:
1. **Rearrange the equation** to standard form \(ax^2 + bx + c = 0\):
\[
3x^2 + 4x + 5 - 1 = 0 \implies 3x^2 + 4x + 4 = 0
\]
Here, \(a = 3\), \(b = 4\), and \(c = 4\).
2. **Calculate the discriminant** (\(D = b^2 - 4ac\)):
\[
D = 4^2 - 4(3)(4) = 16 - 48 = -32
\]
Since \(D < 0\), there are no real solutions, but two complex solutions.
3. **Apply the quadratic formula** \(x = \frac{-b \pm \sqrt{D}}{2a}\):
\[
x = \frac{-4 \pm \sqrt{-32}}{2 \cdot 3} = \frac{-4 \pm 4\sqrt{2}i}{6}
\]
Simplify by dividing numerator and denominator by 2:
\[
x = \frac{-2 \pm 2\sqrt{2}i}{3}
\]
**Solutions**:
\[
x = -\frac{2}{3} + \frac{2\sqrt{2}}{3}i \quad \text{and} \quad x = -\frac{2}{3} - \frac{2\sqrt{2}}{3}i
\]
The final answers are \(\boxed{x = -\frac{2}{3} \pm \frac{2\sqrt{2}}{3}i}\).<|end|>
知識は足りなさそうだけど、少なくとも日本語は理解はできてるっぽいのだけどね。
messages = [{
"role": "user",
"content": "日本で2番目に高い山の高さと富士山の差は?"
}]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt",
)
outputs = model.generate(
**inputs.to(model.device),
max_new_tokens=32768,
temperature=0.6,
top_p=0.95,
do_sample=True,
)
outputs = tokenizer.batch_decode(outputs[:, inputs["input_ids"].shape[-1]:])
print(outputs[0])
<think>
Okay, so I need to find out the difference in height between the second highest mountain in Japan and Mount Fuji. Let me start by recalling which mountain is the second tallest in Japan. I think Fuji is the first, so the second should be Mount Ebishoike or maybe another one. Wait, I remember that Ebishoike is often cited as the second tallest, but I've also heard that the list can vary slightly depending on the source. Let me check that.
From what I remember, the official list from the Japan Meteorological Agency (JAG) might list Mount Ebishoike as the second highest, standing at around 3,772 meters. But I've also heard that some sources might consider Mount Komiwa or others. Wait, no, Komiwa is in Fuji National Park but I think it's not as tall. Let me confirm. Ebishoike is in Fuji National Park as well, right? And it's part of the same volcanic mountain system as Fuji. So if Fuji is 3,776 meters high, then Ebishoike at 3,772 meters would be the second. The difference would be 4 meters. But wait, are there any other mountains that might be considered taller than Ebishoike?
Alternatively, there's Mount Tetrigon (or Tetrigon-dai), which was believed to be taller than Fuji for a long time, but it turned out that Tetrigon-dai is actually about 3,646 meters, which is shorter than Fuji. So Fuji is the highest. Then the second would be Ebishoike. So the height difference between Ebishoike and Fuji would be 3,776 m minus 3,772 m, which is 4 meters. But I should double-check these numbers to make sure I'm not mixing up the exact figures. Let me look up the exact elevations.
According to JAG, Fuji is 3,776 meters (3,770 feet) above sea level. Ebishoike is listed as 3,772 meters (3,670 feet). So the difference is indeed 4 meters. However, some historical records thought Tetrigon-dai (3,646 m) was taller than Fuji, but that's a myth. So the current recognized second highest is Ebishoike. Therefore, the answer should be 3,776 - 3,772 = 4 meters. So the difference is 4 meters.
</think>
The second highest mountain in Japan is Mount Ebishoike, with a height of 3,772 meters. Mount Fuji, the highest, stands at 3,776 meters. The difference between their heights is:
**3,776 m (Fuji) − 3,772 m (Ebishoike) = 4 m**
因此,日本第二高山和富士山的高度差为 \boxed{4} 米。<|end|>
日本語訳
<think>
では、日本で2番目に高い山と富士山の標高の差を調べなければなりません。まず、日本で2番目に高い山がどこかを思い出してみましょう。富士山が1番目なので、2番目はエビシオイケ山か、あるいは別の山かもしれません。待ってください、エビシオイケ山はよく2番目に高い山として挙げられますが、出典によってはリストが少し異なる場合もあると聞いたことがあります。確認してみましょう。私の記憶では、気象庁(JAG)の公式リストでは、江ノ島山が2番目に高い山として記載されており、標高は約3,772メートルとなっています。しかし、一部の出典では、小見山や他の山が2番目に高い山として挙げられていると聞いたことがあります。待ってください、小見山は富士国立公園内にありますが、標高はそれほど高くないと思います。確認します。エビシオイケも富士国立公園内にありますよね?そして、富士と同じ火山山系の一部です。もし富士が3,776メートルなら、エビシオイケの3,772メートルが2番目になります。差は4メートルです。しかし、エビシオイケよりも高い山は他にありませんか?
代わりに、テトリゴン山(またはテトリゴン台)という山があり、長年富士よりも高いとされていましたが、実際はテトリゴン台は約3,646メートルで、富士よりも低いことが判明しました。したがって、富士が最も高い山です。したがって、2番目はエビシオイケとなります。エビシオイケと富士山の標高差は3,776メートルから3,772メートルを引いた4メートルとなります。ただし、数値を間違えていないか確認する必要があります。正確な標高を確認してみましょう。
JAGによると、富士山の標高は3,776メートル(3,770フィート)です。エビシオイケは3,772メートル(3,670フィート)と記載されています。したがって、差は確かに4メートルです。ただし、歴史的な記録ではテトリゴンダイ(3,646メートル)が富士よりも高いとされていた時期もありますが、これは伝説です。したがって、現在認められている2番目に高い山はエビシオイケです。したがって、答えは3,776 - 3,772 = 4メートルです。したがって、差は4メートルです。
</think>日本で2番目に高い山は、標高3,772メートルの恵比寿池山です。最も高い富士山は3,776メートルです。その標高の差は:
3,776 m(富士山)− 3,772 m(エビスホイケ)= 4 m
したがって、日本第二高山と富士山の標高差は \boxed{4} メートルです。<|end|>