💡

Amazon Bedrock で Qwen3 235B の Reasoning を試す

に公開

Qwen モデルが Amazon Bedrock で利用可能に

9/18 に以下4つのQwenモデルがAmazon Bedrockで利用可能になりました。

  • Qwen3-Coder-480B-A35B-Instruct
  • Qwen3-Coder-30B-A3B-Instruct
  • Qwen3-235B-A22B-Instruct-2507
  • Qwen3-32B (Dense)

詳細は以下のブログをご参照ください。
https://aws.amazon.com/jp/blogs/news/qwen-models-are-now-available-in-amazon-bedrock/

Qwen3 235B モデルにて思考モードを試す

さて、このQwen3シリーズは、思考モードと非思考モードという 2 つのモードを設定できます。思考モードはいわゆるreasoningに値するモードで、順序立てて思考してくれるモードとなります。

早速AWSマネジメントコンソールにて試してみましょう。

まず、プレイグラウンドにてQwen3 32Bモデルを選択いただくと、以下のように「モデル推論」というトグルボタンが確認できます。これを有効化いただくことで思考モードを試すことができます。
Qwen3-32B

一方、Qwen3 235Bモデルを選択してみると、そのボタンが出てきません。

Qwen3-235B

ドキュメント上記載がなかったのですが、AWS CLIを用いて検証した結果、"reasoning_effort": "high"というパラメータを付与するとreasoningが有効化されることがわかりました。

サンプルのインプットとして以下のjsonファイルを用意し、上記のパラメータを付与してみます。

qwen_japanese_reasoning.json
{"messages": [{"role": "user", "content": "次の問題を段階的に解いてください:ある会社の3つの部署A、B、Cがあります。部署Aの従業員 数は部署Bより25%多く、部署Cの従業員数は部署Aより40%少ないです。全従業員数が180人の場合、各部署の従業員数を求めてください。"}], "reasoning_effort": "high"}

これを指定してAWS CLIでAPIコールを行なってみましょう。

% aws bedrock-runtime invoke-model \
  --model-id qwen.qwen3-235b-a22b-2507-v1:0 \
  --body file://qwen_japanese_reasoning.json \
  --content-type application/json \
  --accept application/json \
  --region us-west-2 \
  --cli-binary-format raw-in-base64-out \
  japanese_reasoning_response.json

そうすると、<reasoning>タグで括られた思考ステップを確認することができます。

出力

% jq -r '.choices[0].message.content' japanese_reasoning_response2.json
<reasoning>Okay, let me try to solve this problem step by step. So, there are three departments in a company: A, B, and C. The problem says that department A has 25% more employees than department B. Then, department C has 40% fewer employees than department A. And the total number of employees in all three departments is 180. We need to find the number of employees in each department.

First, I need to set up variables for each department. Let me think... Maybe I should let B be the reference since A is related to B. Let me assign a variable to department B. Let's say the number of employees in B is x. Then, since A has 25% more than B, A would be x plus 25% of x. So, A = x + 0.25x = 1.25x. Right?

Then, department C is 40% less than A. So if A is 1.25x, then C would be A minus 40% of A. So that's 1.25x - 0.4*1.25x. Let me calculate that. 0.4 times 1.25... Let's see, 0.4 * 1.25 = 0.5. Wait, so 1.25x minus 0.5x? Wait, no, hold on. Wait, 40% of A is 0.4 * 1.25x = 0.5x. Therefore, C = 1.25x - 0.5x = 0.75x. Hmm, so C is 0.75x?

Wait, let me check that again. If C is 40% less than A, then it's 100% - 40% = 60% of A. So maybe it's 0.6 * A. Which would be 0.6 * 1.25x. Let me calculate that. 0.6 * 1.25. Well, 1.25 is 5/4, so 0.6 * 5/4 = (0.6*5)/4 = 3/4 = 0.75. Oh, right, so 0.75x. So that matches. So C is 0.75x. Okay, so that makes sense.

So now, total employees are A + B + C = 1.25x + x + 0.75x. Let me add those up. 1.25x + 1x is 2.25x, plus 0.75x is 3.0x. Wait, so total is 3x = 180? Then x would be 60. So then B is 60, A is 1.2560 = 75, and C is 0.7560 = 45. Let's check: 75 + 60 + 45 = 180. 75+60 is 135, plus 45 is 180. Perfect. So that adds up.

Wait, but let me verify each percentage again to make sure I didn't make a mistake. A is 25% more than B. B is 60. 25% of 60 is 15, so 60 + 15 = 75. That's correct for A. Then C is 40% less than A. A is 75. 40% of 75 is 30, so 75 - 30 = 45. Yep, that's 45. And total is 75 + 60 + 45 = 180. So that seems right.

Wait, but let me think if there's another way to approach this, just to double-check. Maybe using fractions instead of decimals. 25% is 1/4. So if B is x, then A is x + (1/4)x = (5/4)x. Then 40% less than A. 40% is 2/5, so 40% less means 3/5 of A. So 3/5 of A would be (3/5)*(5/4)x = (15/20)x = (3/4)x. Which is the same as 0.75x. Then total is (5/4)x + x + (3/4)x. Converting to quarters: (5/4)x + (4/4)x + (3/4)x = 12/4 x = 3x. Same result. So 3x=180, x=60. Yep, same answer.

Hmm, so I think this is correct. Let me see if there's a chance I messed up the percentages. Sometimes it's easy to confuse the base. For example, when C is 40% less than A, it's important that it's based on A's number, not B's. But since we did it as 0.6A, which we converted properly to 0.61.25x, that should be okay. And cross-checking with fractions confirmed it. So I don't think there's an error here.

Another check: suppose someone thought that "40% less than A" was 40% of B or something else. But the problem says "部署Cの従業員数は部署Aより40%少ないです。" Which translates to "Department C's employee count is 40% fewer than department A's." So it's definitely 40% of A, so subtracting from A, so 60% of A.

Another possible mistake: thinking that 25% more A than B means B is 25% less than A, but that's a common mistake. However, in this case, the problem says "A is 25% more than B", so correctly we did A = 1.25B, not B = 0.75A. So that's correct.

So, yes, the numbers check out. So A is 75, B is 60, C is 45. Sum is 180. Perfect.

Just to recap the steps:

  1. Let B = x.

  2. A = 1.25x (since it's 25% more than B).

  3. C = A - 40%A = 0.6A = 0.61.25x = 0.75x.

  4. Total = A + B + C = 1.25x + x + 0.75x = 3x = 180 => x=60.

  5. Therefore, B=60, A=75, C=45.

All steps make sense and checks confirm the answer. So I think this is correct.
</reasoning>

問題の整理

  • 部署Aの従業員数は、部署Bより25%多い
  • 部署Cの従業員数は、部署Aより40%少ない
  • 全従業員数は180人
  • 各部署の従業員数を求める

解法のステップ

1. 変数の設定

部署Bの従業員数を基準として変数 $ x $ で表す:

  • 部署B:$ x $
  • 部署A:部署Bより25%多い → $ A = 1.25x $
  • 部署C:部署Aより40%少ない → $ C = 0.6 \times A = 0.6 \times 1.25x = 0.75x $

2. 全従業員数の式

全従業員数は、3つの部署の合計であるため:
$$
A + B + C = 1.25x + x + 0.75x = 3x
$$

3. 方程式の解法

全従業員数が180人のため:
$$
3x = 180 \quad \Rightarrow \quad x = 60
$$

4. 各部署の従業員数の計算

  • 部署B:$ x = 60 $
  • 部署A:$ 1.25x = 1.25 \times 60 = 75 $
  • 部署C:$ 0.75x = 0.75 \times 60 = 45 $

検算

  • 部署A:75人
  • 部署B:60人
  • 部署C:45人
    合計:$ 75 + 60 + 45 = 180 $(一致)

また、以下の条件も適切に満たされている:

  • 部署Aは部署Bの25%多く:$ 60 \times 1.25 = 75 $
  • 部署Cは部署Aの40%少なく:$ 75 \times 0.6 = 45 $

答え

  • 部署A:75人
  • 部署B:60人
  • 部署C:45人

また一方で、"reasoning_effort": "high" を付与せず実行するとどうでしょうか。

qwen_japanese_normal.json
{"messages": [{"role": "user", "content": "次の問題を段階的に解いてください:ある会社の3つの部署A、B、Cがあります。部署Aの従業員 数は部署Bより25%多く、部署Cの従業員数は部署Aより40%少ないです。全従業員数が180人の場合、各部署の従業員数を求めてください。"}]}
% aws bedrock-runtime invoke-model \
  --model-id qwen.qwen3-235b-a22b-2507-v1:0 \
  --body file://qwen_japanese_normal.json \
  --content-type application/json \
  --accept application/json \
  --region us-west-2 \
  --cli-binary-format raw-in-base64-out \
  japanese_reasoning_normal.json

すると、Reasoningなしで回答を始めています。

出力

% jq -r '.choices[0].message.content' japanese_reasoning_normal.json
では、問題を段階的に丁寧に解いていきましょう。


ステップ1:問題の内容を整理

  • 部署Aの人数は、部署Bより 25%多い
  • 部署Cの人数は、部署Aより 40%少ない
  • 全体の従業員数は 180人
  • 求めるもの:A、B、Cの従業員数。

ステップ2:変数を設定

未知数を文字で表します。
ここでは、部署Bの人数を基準にすることが簡単です。

  • 部署Bの人数を $ x $ 人とします。

ステップ3:部署Aの人数を表す

「部署Aは部署Bより25%多い」というのは、
部署Aの人数は部署Bの人数の $ 1 + 0.25 = 1.25 $ 倍。

よって、

  • 部署Aの人数 = $ 1.25x $

ステップ4:部署Cの人数を表す

「部署Cは部署Aより40%少ない」
→ つまり、部署Cの人数は部署Aの人数の $ 1 - 0.4 = 0.6 $ 倍。

したがって、

  • 部署Cの人数 = $ 0.6 \times (1.25x) = 0.75x $

ステップ5:合計人数の式を立てる

全従業員数は A + B + C = 180 人なので、

A + B + C = 1.25x + x + 0.75x = 3x
3x = 180

ステップ6:方程式を解く

x = \frac{180}{3} = 60

ステップ7:各部署の人数を求める

  • Bの人数:$ x = 60 $人
  • Aの人数:$ 1.25 \times 60 = 75 $人
  • Cの人数:$ 0.75 \times 60 = 45 $人

ステップ8:確認(合計が180になっているか?)

75 + 60 + 45 = 180 \quad \text{✓ 正しい}

ステップ9:条件の確認

  • AはBより25%多い?
    Bは60人。25%多い → $ 60 \times 1.25 = 75 $ → ○
  • CはAより40%少ない?
    Aは75人。40%少ない → $ 75 \times 0.6 = 45 $ → ○
  • 合計180人 → ○

✅ 最終的な答え:

  • 部署A:75人
  • 部署B:60人
  • 部署C:45人

以上が段階的な解法です。

CloudWatch Logsにログを出力していましたが、reasoningの有無で出力トークン数に違いが現れていることも確認できます。

# reasoning ありの場合
 "usage": {
   "completion_tokens": 2388,
   "prompt_tokens": 95,
   "total_tokens": 2483
}

# reasoning なしの場合
 "usage": {
   "completion_tokens": 714,
   "prompt_tokens": 93,
   "total_tokens": 807
}

おわりに

パラメータの有無で挙動が変わることが確認できました。
複雑なタスクについては思考モード(reasoningあり)で、単純なタスクは非思考モード(reasoningなし)で実行することで、コストとパフォーマンスのトレードオフを管理することができます。

アマゾン ウェブ サービス ジャパン (有志)

Discussion