小さなモデルが誤った選択となる場合

読了まで約38 分分、6 節 節の 5 例 例。

第2026.11.9版 2026年11月20日時点で例が通過 36 例中 36 例が合格 変更点

AIによる翻訳。英語版は人による検証済みである。 当社の書籍の作り方

英語版の書籍(版2026.11.9)から翻訳した。 原文を読む

この章を読み終えると、次のことができるようになる。小さなルーターが代役(スタンドイン)に今なお負ける場面と、ホスト型モデルのほうが優れると見込まれる場面を述べられる。日付を付して示した入力から、各選択肢の月間コストを数えられる。自前のマシンのほうが安価な経路になる処理量を求められる。そして、コストよりも先にこの問題を決める要件を挙げられる。

小さなルーターは、メッセージの大半でより大きなモデルに勝っていても、一部のメッセージ、一部のチーム、一部の処理量に対しては誤った選択となりうる。銀行のサポート受信箱(第1章)には 77 個のチームがある。この本は9つの章をかけて、その受信箱のための分類器ヘッドを作った。判断に迷うメッセージを引き渡すルートと、ルーターのバージョンを管理して引き渡したメッセージを担当者に送るチェックとともにそのヘッドを提供し、蒸留した生徒モデルと int8 のコピーを試して、どちらも本番投入せずに測定した。ルーターを測定する各章では、ルーターを代役と比較して採点している(第1章)。

この部分はまだ翻訳されていないため、英語で表示している。

Where the small model still loses

最終変更:版2026.11.2

Chapter 2 set the stand-in's score as the baseline. This section puts the router beside it on the same messages: all 1001 messages of test_1001, the fixed sample that every chapter's samples come from (chapter 2). The router is the classifier banking77-lora-v1, run live.

router-on-test-1001.py Python 3.12.15 · peft 0.21.3 · torch 2.15.0+cpu · torchao 0.18.0+cpu · transformers 5.23.0 合格
"""The router and the stand-in on all 1,001 messages of test_1001, the committed test order. The prose rests on thelines for the router's wrong answers sent as answers and for the messages the stand-in gets right and the router wrong.The stand-in's answers are recorded; the router runs live on 2 threads, and its first 200 messages are the test_200 sample."""import osos.environ["HF_HUB_OFFLINE"] = "1"os.environ["TRANSFORMERS_OFFLINE"] = "1"import torch  # noqa: E402torch.set_num_threads(2)import router_lib  # noqa: E402router_lib.setup_runtime()# Runs the router live on the sample and reads the stand-in's answers from its recording, then scores both.c = router_lib.compare_router_and_standin("test_1001")n = c["messages"]print(f"messages on test_1001: {n}")print(f"router banking77-lora-v1 correct: {c['router_correct']}/{n} ({c['router_correct'] / n:.1%})")print(f"stand-in correct: {c['standin_correct']}/{n} ({c['standin_correct'] / n:.1%})")print(f"router handed off: {c['handed_off']}/{n} ({c['handed_off'] / n:.1%})")print(f"right for the stand-in, wrong for the router: {c['standin_right_router_wrong']}/{n}")print(f"of those, handed off by the router: {c['of_those_handed_off']}/{c['standin_right_router_wrong']}")print(f"wrong for the router and sent as an answer: {c['router_wrong_sent']}/{n} ({c['router_wrong_sent'] / n:.1%})")print(f"right for the router, wrong for the stand-in: {c['router_right_standin_wrong']}/{n}")
出力python router-on-test-1001.py
messages on test_1001: 1001
router banking77-lora-v1 correct: 847/1001 (84.6%)
stand-in correct: 560/1001 (55.9%)
router handed off: 146/1001 (14.6%)
right for the stand-in, wrong for the router: 48/1001
of those, handed off by the router: 22/48
wrong for the router and sent as an answer: 76/1001 (7.6%)
right for the router, wrong for the stand-in: 335/1001

On the whole set the router is ahead, right on 847/1001 (84.6%) against the stand-in's 560/1001 (55.9%), which is the baseline from chapter 2. Yet the stand-in is right and the router wrong on 48/1001 messages. The router hands off some of those, so a person sees them, and the rest reach the caller as wrong answers. The reverse disagreement, where the router is right and the stand-in wrong, has its own count in the output.

The count that matters most for the inbox is the wrong answers the router sends to a caller: 76/1001 (7.6%). Those are messages it kept, because their confidence cleared the threshold. Chapter 5 chose that threshold on the dev split, and chapter 9 says where what the router hands off goes, which is a person.

where-the-router-still-loses.py Python 3.12.15 · peft 0.21.3 · torch 2.15.0+cpu · torchao 0.18.0+cpu · transformers 5.23.0 合格
"""Where the router still loses: test_200 scored for the router and the stand-in. The prose rests on the count ofmessages the stand-in gets right and the router wrong, and on the wrong answers the router sends as answers.The stand-in's answers are recorded; the router runs live on 2 threads."""import osos.environ["HF_HUB_OFFLINE"] = "1"os.environ["TRANSFORMERS_OFFLINE"] = "1"import json  # noqa: E402import torch  # noqa: E402torch.set_num_threads(2)import router_lib  # noqa: E402router_lib.setup_runtime()ADAPTER = router_lib.HERE / "data" / "recorded" / "lora-full"# The threshold chapter 5 chose on dev, as the adapter's manifest records it.threshold = json.loads((ADAPTER / "manifest.json").read_text())["handoff_threshold"]# Keyed by test row index, not by position in the sample, so each lookup uses the sample's row numbers.answers = router_lib.standin_rows()test = router_lib.read_rows("test")  # (text, label index) per rowsample = router_lib.read_sample("test_200")golds = [test[i][1] for i in sample]  # index 1 is the gold team, as an indexstandin_preds = [answers[i]["label"] for i in sample]  # the label is the team's index, the same form as the gold labeltokenizer, model = router_lib.load_classifier(ADAPTER / "adapter")preds, confs = router_lib.classify(model, tokenizer, [test[i][0] for i in sample])n = len(sample)router_right = [p == g for p, g in zip(preds, golds)]standin_right = [p == g for p, g in zip(standin_preds, golds)]handed_off = [router_lib.handoff(c, threshold) for c in confs]  # true below the threshold; a NaN confidence is handed off toolost = [i for i in range(n) if standin_right[i] and not router_right[i]]sent_wrong = sum(not r and not h for r, h in zip(router_right, handed_off))  # wrong and not handed off: what a caller receivesprint(f"messages on test_200: {n}")print(f"router banking77-lora-v1 correct: {sum(router_right)}/{n} ({sum(router_right) / n:.1%})")print(f"stand-in correct: {sum(standin_right)}/{n} ({sum(standin_right) / n:.1%})")print(f"router threshold from manifest: {threshold:.2f}")print(f"router handed off: {sum(handed_off)}/{n} ({sum(handed_off) / n:.1%})")print(f"right for the stand-in, wrong for the router: {len(lost)}/{n} ({len(lost) / n:.1%})")print(f"of those, handed off by the router: {sum(handed_off[i] for i in lost)}/{len(lost)}")print(f"wrong for the router and sent as an answer: {sent_wrong}/{n} ({sent_wrong / n:.1%})")print(f"right for the router, wrong for the stand-in: {sum(r and not s for r, s in zip(router_right, standin_right))}/{n}")
出力python where-the-router-still-loses.py
messages on test_200: 200
router banking77-lora-v1 correct: 172/200 (86.0%)
stand-in correct: 109/200 (54.5%)
router threshold from manifest: 0.63
router handed off: 33/200 (16.5%)
right for the stand-in, wrong for the router: 6/200 (3.0%)
of those, handed off by the router: 3/6
wrong for the router and sent as an answer: 11/200 (5.5%)
right for the router, wrong for the stand-in: 69/200

test_200 is the first 200 messages of test_1001, a prefix the count script checks, so these counts are part of the full run and not a second sample. On it, the stand-in is right and the router wrong on 6/200 (3.0%) messages, and the router hands off 3/6 of them.

The hand-off holds back the wrong answers. The router sends 11/200 (5.5%) wrong answers on these 200 messages. On the messages it keeps, its accuracy is 156/167 (93.4%), and 33/200 (16.5%) of all 200 go to a person.

Forcing a small model onto the team list keeps every answer a team, and does not make the answer right. Chapter 4 asked the two smaller models for a team that way. The table gives each prompted variant's count on the 200 messages of test_200:

Prompted variant Right on test_200
SmolLM2-135M-Instruct, raw prompt 9/200 (4.5%)
SmolLM2-135M-Instruct, chat template 11/200 (5.5%)
SmolLM2-360M-Instruct, raw prompt 12/200 (6.0%)

The raw 135M model gave one answer more often than any other (card_arrival, 165/200), and that team is the gold team for 0/200 of the messages. A model that leans on one answer is a prior, not a router. Chapter 4 shows why a prompt cannot make up for a model this size.

The stand-in fails in patterns too. Across all 1001 messages, its answers never name 4 of the 77 teams, so every message whose gold team is one of them goes to another team. Two confusions tie for its most common error. The clearest is the team Refund_not_showing_up, which is answered as request_refund on 13/13 of its messages. A pair like that is where a labelled set has to be read before any model is trusted on it, and chapter 2 lists the pairs for every candidate.

A student copies its teacher, including the teacher's mistakes. Chapter 6 distilled the stand-in's answers into a student. The teacher agreed with the gold label on 549/1000 (54.9%) of the training rows it labelled, so the student learned from labels that were wrong almost half the time. The student reached 69/200 (34.5%) on test_200, and the same recipe trained on the gold labels of the same rows reached 77/200 (38.5%).

The student also falls below its teacher, which reached 109/200 (54.5%) on test_200, and below the gold-label control, by a gap this sample cannot settle (chapter 6). The student is right where the control is wrong on 24/200 messages, and the control where the student is wrong on 32/200.

A new team is another place the small model loses. A classifier head has one output for each team it was trained on, so a team without an output cannot be routed by it. Adding one means labelled messages for that team, a training run with the recipe from chapter 5, and the checks from chapter 9 before the router sends a message to it. Whether a prompt change could add a new team is a question for the reader to test. This book did not measure a hosted model, and the table later in this chapter lists the question as open.

Put together, the small models here did three things: a prompted model leaned on one answer, a student copied its teacher's mistakes, and a team with no output could not be routed. None of these is a fault in the router's arithmetic. The stand-in did one thing more: it never named 4 teams and confused a pair. That is the stand-in's, not either option's. A larger threshold trades the router's 11/200 (5.5%) wrong answers on test_200 for hand-offs (chapter 5), but it gives no team an output and fixes neither the teacher's errors nor the stand-in's. Each changes what a caller sees: a wrong team, a handed-off message, or no team at all.

Working rule: Before you route with a small model, run it and the hosted model on the same fixed sample. Count the messages each gets right that the other gets wrong, and the wrong answers that would reach a caller. Count a prompted model's answers against the team list, and count how often its most common answer is the gold team. Do not route a team that has no labelled messages of its own, and do not train a student on a teacher's labels before you have counted how often the teacher agrees with the gold labels.

請求額とマシンを数える

最終変更:版2026.11.9

ホスト型モデルはメッセージ単位で料金が課される。ホスト型モデルの月額は、メッセージ数に1メッセージあたりの費用を掛けたものである。1メッセージの費用は、入力トークン数に入力単価を掛けたものと、出力トークン数に出力単価を掛けたものの和になる。100万トークンあたりで書かれた価格表は、100万で割るとトークン1個あたりの価格になる。ルーティングのメッセージは、プロンプトとメッセージの両方が数えられるため入力側が長く、答えがチーム名1つであるため出力側は短い。

マシンは、稼働しているかどうかにかかわらず料金がかかる。マシンの月額は、稼働時間に時間単価を掛けたものである。マシンが1か月にルーティングできるメッセージ数は、スループット(1秒あたりのメッセージ数)に1か月の秒数と稼働率を掛けたものである。稼働率とは、1か月のうちマシンが稼働している割合のことである。したがって、マシンのメッセージあたりの費用はルーティングするメッセージ数に左右され、比較は量を決めてはじめて答えを出す。

以下の3つの式は、どの2つの選択肢の組にも成り立つ。

hosted cost per month = messages × (input tokens × input price + output tokens × output price)
machine cost per month = hours × machine cost per hour
machine capacity per month = messages per second × seconds per month × utilisation

各入力には値が必要であり、各価格には日付と出典が必要である。本書はホスト型の価格を引用しない。読者が確認できる出典と日付の両方を備えた価格を、本書は持っていないからである。比較を行う当日に、利用するプロバイダの価格ページを読み、価格、その日付、そのアドレスを数値の横に書き留めること。

入力トークンにはトークナイザも必要である。同じテキストでも、ホスト型プロバイダの数え方とオープンモデルの数え方は異なることがあり、本書はそれを測定していない。ルーティングのプロンプトとは、ホスト型モデルがメッセージごとに受け取るものであり、77のチーム名の一覧とメッセージから成る。それを router_prompt が組み立てる。月額の例では、SmolLM2-135M-Instruct のトークナイザでこれを数え、1メッセージあたり 587 トークンとなる。この例は、その数をプロバイダの数の代用として明示している。

スループットは、マシンに依存するため、記録から得なければならない入力である。記録にはマシン名が記され、測定した速度が保存されている。a cloud machine with 4 vCPUs and 15 GiB of memory 上、スレッド数 4 で、代用モデルは1回の呼び出しにつき1メッセージの条件で毎秒 0.32 メッセージをルーティングした。ルーターの分類器 banking77-lora-v1 は、float32 で同じ呼び出しサイズのとき毎秒 19.0 メッセージをルーティングした。16件のバッチでの速度も出力に含まれている。

条件が揃っているのは、1回の呼び出しにつき1件の組だけである。16件のバッチでは、分類器は1回の順伝播で16メッセージを受け取る。一方、代用モデルは1回の呼び出しで1メッセージを、ルーターのプロンプト全体とともに受け取る。そのため、バッチでの比 104.0 はモデルの大きさとバッチ処理の効果が混ざっており、本章は比較にこれを用いない。比較には、1回の呼び出しにつき1件の比 60.8 を用いる。各コピーは、1メッセージのウォームアップのあと、test_200 の200メッセージを1回だけ計時して処理した。トークン化は計時区間に含まれる。比は丸める前の速度から求めたものであるため、表示された速度の商とは正確には一致しない。

cost-ratio-from-recording.py Python 3.12.15 · torch 2.15.0+cpu · transformers 5.23.0 合格
"""The throughput rates and ratios as recorded, and the machine they were measured on. The prose rests on theone-per-call ratio line, the like-for-like comparison; the batched lines differ in call size. Reads the recording only; no model runs."""import jsonimport router_libfolder = router_lib.HERE / "data" / "recorded" / "throughput"ratios = json.loads((folder / "ratios.json").read_text())rates = router_lib.recorded_rates()manifest = json.loads((folder / "manifest.json").read_text())print(f"machine: {manifest['machine'].split(', ')[0]}")  # the machine's description is cut at its first comma, which keeps the name and drops the restprint(f"threads: {manifest['settings']['n_threads']}")print(f"messages on test_200: {ratios['messages']}")print(f"stand-in rate, one per call (messages a second): {rates['standin_one_message_per_call']}")print(f"classifier fp32 rate, one per call (messages a second): {rates['classifier_fp32_one_message_per_call']}")print(f"classifier fp32 rate, batches of 16 (messages a second): {rates['classifier_fp32_batches_of_16']}")print(f"classifier int8 rate, batches of 16 (messages a second): {rates['classifier_int8_batches_of_16']}")# Each ratio is computed from unrounded rates, so it is not the quotient of the printed rates.print(f"fp32 over stand-in, one per call, throughput ratio: {ratios['classifier_fp32_one_at_a_time_over_standin']}")print(f"fp32 over stand-in, batches of 16, throughput ratio: {ratios['classifier_fp32_over_standin']}")print(f"int8 over stand-in, batches of 16, throughput ratio: {ratios['classifier_int8_over_standin']}")print(f"int8 over fp32, batches of 16, throughput ratio: {ratios['classifier_int8_over_fp32']}")print(f"predictions agreeing, fp32 and int8: {ratios['agreement_fp32_int8']}/{ratios['messages']}")
出力python cost-ratio-from-recording.py
machine: a cloud machine with 4 vCPUs and 15 GiB of memory
threads: 4
messages on test_200: 200
stand-in rate, one per call (messages a second): 0.32
classifier fp32 rate, one per call (messages a second): 19.0
classifier fp32 rate, batches of 16 (messages a second): 33.0
classifier int8 rate, batches of 16 (messages a second): 29.0
fp32 over stand-in, one per call, throughput ratio: 60.8
fp32 over stand-in, batches of 16, throughput ratio: 104.0
int8 over stand-in, batches of 16, throughput ratio: 91.8
int8 over fp32, batches of 16, throughput ratio: 0.9
predictions agreeing, fp32 and int8: 200/200

このマシンのこのスレッド数では、int8 のコピーは float32 より速くなかった。16件のバッチでの float32 に対する比は 0.9 である。第7章は、バイト数が少なくても速度が決まるわけではないと述べたが、この記録はその速度を測定している。2つのコピーは 200/200 の予測で一致した。記録はそのスレッド数で実行されたものであり、本書のサービング予算は2 vCPU である。そのため、読者の使う速度は、自分のマシンで自分のスレッド数により取った記録から得るべきである。

請求額の計算にはルーターの速度が必要であり、記録がそれを与える。代用モデルと同じ方法で計時した、1回の呼び出しにつき1メッセージでの分類器の速度である。このルートは1リクエストで1メッセージを扱うため、請求額の計算にはこの速度を用いる。読者は、これを自分のマシンで取った速度に置き換える。

monthly-bill-from-labelled-inputs.py Python 3.12.15 · torch 2.15.0+cpu · transformers 5.23.0 合格
"""The monthly bill for a hosted model and for the router on one machine, from inputs the reader sets. The hosted bill,the machine's bill and the cheaper-route line are the point the prose rests on. The prices, volume, machine costand utilisation are example values, not published prices; the token counts are live and the router's rate is recorded."""import osos.environ["HF_HUB_OFFLINE"] = "1"os.environ["TRANSFORMERS_OFFLINE"] = "1"import torch  # noqa: E402torch.set_num_threads(2)import router_lib  # noqa: E402router_lib.setup_runtime()inputs = router_lib.bill_inputs_recorded()test = router_lib.read_rows("test")messages = [test[i][0] for i in router_lib.read_sample("test_200")]  # index 0 is the text; the label is index 1# The hosted prompt, counted with the 135M model's tokenizer as a stand-in for the provider's.input_tokens = router_lib.router_prompt_tokens(messages)# Prices are per million tokens, hence the division at the end.per_message = (input_tokens * inputs["price_per_million_input_tokens"]               + inputs["output_tokens_per_message"] * inputs["price_per_million_output_tokens"]) / 1_000_000hosted_month = inputs["messages_per_month"] * per_messagemachine_month = inputs["machine_cost_per_hour"] * inputs["hours_per_month"]capacity = inputs["router_messages_per_second"] * 3600 * inputs["hours_per_month"] * inputs["utilisation"]print(f"example input, messages per month: {inputs['messages_per_month']}")print(f"example input, price per million input tokens, USD: {inputs['price_per_million_input_tokens']}")print(f"example input, price per million output tokens, USD: {inputs['price_per_million_output_tokens']}")print(f"example input, output tokens per message: {inputs['output_tokens_per_message']}")print(f"example input, machine cost per hour, USD: {inputs['machine_cost_per_hour']}")print(f"example input, hours per month: {inputs['hours_per_month']}")print(f"example input, utilisation: {inputs['utilisation']}")print(f"recorded input, router messages per second, one per call: {inputs['router_messages_per_second']}")print(f"input tokens per message, hosted prompt (counted with SmolLM2-135M-Instruct, a stand-in tokenizer): {input_tokens}")print(f"example hosted price per message (example prices), USD: {per_message:.6f}")print(f"example hosted bill per month (example prices), USD: {hosted_month:.2f}")print(f"example machine bill per month (example cost per hour), USD: {machine_month:.2f}")print(f"machine capacity per month (recorded rate, example utilisation): {capacity:.0f}")print(f"example machine cost per message at capacity (example cost per hour), USD: {machine_month / capacity:.6f}")print(f"example volume within machine capacity: {'yes' if inputs['messages_per_month'] <= capacity else 'no'}")  # above capacity, one machine cannot carry the volume and this bill does not holdprint(f"example values, cheaper route at the input volume: {'hosted' if hosted_month < machine_month else 'machine'}")
出力python monthly-bill-from-labelled-inputs.py
example input, messages per month: 100000
example input, price per million input tokens, USD: 1.0
example input, price per million output tokens, USD: 4.0
example input, output tokens per message: 6
example input, machine cost per hour, USD: 0.4
example input, hours per month: 730
example input, utilisation: 0.5
recorded input, router messages per second, one per call: 19.0
input tokens per message, hosted prompt (counted with SmolLM2-135M-Instruct, a stand-in tokenizer): 587
example hosted price per message (example prices), USD: 0.000611
example hosted bill per month (example prices), USD: 61.10
example machine bill per month (example cost per hour), USD: 292.00
machine capacity per month (recorded rate, example utilisation): 24966000
example machine cost per message at capacity (example cost per hour), USD: 0.000012
example volume within machine capacity: yes
example values, cheaper route at the input volume: hosted

これらの例の入力では、ホスト型のルートのほうが安い。例の量に対するホスト型の月額は 61.10 USD であり、自前のマシンは量にかかわらず月額 292.00 USD かかる。

記録された速度と例の稼働率では、マシンは1か月に 24966000 メッセージをルーティングでき、全能力で稼働したときのメッセージあたりの費用は 0.000012 USD である。月あたり 100000 メッセージという例の量は、この能力をはるかに下回っており、損益分岐の節で2つの請求額が交わる点を求める。これらの入力にある1時間あたりの費用は、記録されたマシンに合うものであり、2 vCPU のマシンには、そのマシン自身の記録された速度が必要である。

この請求額の計算にある入力は、どれも成り立たなくなる可能性がある。価格は変わるため、ある月に読んだ価格はその月についての事実にすぎない。ここでの稼働率は、まだ起きていないトラフィックについての仮定であり、受信箱の量は、銀行が販売する商品や、その待ち行列を埋める出来事に応じて動く。ある四半期に月の半分は遊休状態だったマシンが、次の四半期には終日稼働していることもある。したがって、毎月、実際の量、日付付きの価格、マシンが測定した稼働率を使って数え直すこと。一度だけ行った比較は、それを行った月の記録でしかない。

実践ルール: 2つの請求額は、確認済みの入力と、価格を調べたマシンを用いて比較する。各価格は、出典とそれを読んだ日付とともに書く。入力トークンは、比較対象のホスト型モデルのトークナイザで数え、スループットは、購入しようとするマシンで取った記録から得る。値が例である場合は、その横にそう明記し、決定の前に置き換える。

データを社内にとどめる

この節はコストの比較ではなく、本書のどの数値もここでの判断を左右しない。受信箱が受け取る各メッセージは、顧客が書いたテキストである。ホスト型モデルがそれに応答するとき、テキストは銀行のマシンを離れ、プロバイダのマシンへ渡る。メッセージ1件ごとに、ホスト型の呼び出しはメッセージ本文と77のチーム名の一覧を送信する。銀行はこれを望まない場合がある。理由は銀行ごとに異なり、顧客のデータ、契約、誰が何を読めるかという規則などである。これらの理由は、ホスト型の請求額のほうが低い場合でも成り立つ。

本書のメッセージは BANKING77 の公開メッセージであるため、本書自身の実行からはプライバシーについて何もわからない。この要件は銀行に属するものであり、それが適用されるかどうかを言えるのは銀行だけである。

銀行のマシンにとどまる小さなモデルは、動作する場所によってこの要件を満たす。ルータ、その重み、そのログは銀行の管理下に置かれ、第9章のバージョン管理とファイル検査は、経路が読み込むすべてのアダプタに適用される。int8 コピーのような派生コピーには、それ自身のマニフェストもピン留めもないため、提供を始める前にその両方が必要である。社内にとどめることには、請求書ではない固有のコストがある。銀行はマシンを運用し、パッチを当て続け、経路の検査を動かし続けなければならない。ほかの何が変わっても経路に残る引き継ぎ(第8章)もその一つである。

請求額は、量、価格、日付に応じて動く数値である。要件は動かない。そのため、まず要件を確定し、そのうえで要件を満たす選択肢だけを比較する。銀行のマシンで動く小さなモデルは、そのような選択肢の一つである。そこで動くより大きなオープンモデルも、もう一つの選択肢である。代役モデルもその一つであり、このマシンでは1回の呼び出しにつき1件ずつ、毎秒0.32件のメッセージを振り分けた。分類器は同じ条件で毎秒19.0件であった。この差はスループットで測ったコストであり、60.8倍に相当する。金銭のコストではない。受信箱が見込む量で要件を満たす選択肢が一つもなければ、コスト比較が決めるものは何も残らない。要件を満たす小さなモデルであっても、最初の節にある精度と引き継ぎの集計には合格しなければならず、要件を満たしたことはそれらを免除する理由にならない。

実践ルール: コストより先にデータ要件を確定する。要件は、それを所有する人々とともに要件として書き留め、節約としても費用としても数えない。メッセージが銀行のマシンにとどまらなければならない場合は、そこで動くモデルを選び、そのうえで、本章の最初の節と同じように精度と引き継ぎを数える。

表で選ぶ

最終変更:版2026.11.2

上の問いはすべてがコストに関するものではなく、その多くは、誰かが記録を実行する前に答えを出せる。下の表は、これらの問いを並べたものである。各問いについて、小型ルーターではどうなるか、ホスト型モデルではどうなるか、受信箱について何を数えるべきかを示す。

問い 小型ルーター ホスト型モデル 測定するもの
メッセージは銀行のマシン内に留まらなければならないか。 満たす。銀行のマシン上で動作する 満たさない。テキストが提供元に送られる 数ではなく要件である。最初に決める
すべての回答がチームでなければならないか。 満たせる。ヘッドか制約付きデコーディングによる(4章) プロンプトと検査で一覧内に収める場合に限る 固定したサンプルで、チーム一覧に含まれない回答の数
チーム一覧はどのくらいの頻度で変わるか。 新しいチームには、ラベル付きメッセージと訓練の実行が必要である(9章) プロンプトの変更で足りるか。試して確かめる問いである 新しいチームを振り分けるために必要なラベル付きメッセージと手順
1か月に何件のメッセージがあるか。 処理能力の上限までは月額固定の料金である メッセージごとの料金であり、件数とともに増える 最後の節の損益分岐点の件数
各チームにラベル付きメッセージはいくつあるか。 各チームについて、訓練とテストに足りる数がある(2章) プロンプトの場合は、少数かまったくない 訓練分割で数えた、チームごとのラベル付きメッセージ数
タスクは自由記述や幅広い知識を必要とするか。 チーム一覧に限られ、自由記述の回答は本書の最初の試行で失敗した 試して確かめる問いである 同じ固定サンプルでの正解率と、その件数

この表は数えるべきものの一覧であり、採点表ではない。行は順に読む。最初の行の要件、次にチーム一覧、そして件数の順である。どの行も、次の問いに進む前にその問いを終わらせうるからである。最後の列で「数ではなく要件」から始まるセルは、数を数える前に下すべき決定を示している。それ以外のセルはすべて、自分のサンプルで数える数を示しており、その分母を併せて出力する。自由記述の行は4章の最初の試行に基づく。135Mモデルの制約なしの回答がチーム名だったのは、0/20件のメッセージであった。

実践ルール: 選ぶ前に、すべての行に自分の受信箱で答える。行が数を求めている場合は、固定したサンプルで数え、その分母を出力する。行が要件を挙げている場合は、数より先に要件に判断させ、その要件を決定の中に要件として書き込む。

損益分岐点を把握する

最終変更:版2026.11.9

損益分岐点とは、ホスト型モデルの月額料金とマシンの月額料金が等しくなる件数のことである。これを下回る件数では、設定した入力値のもとでホスト型モデルのほうが安い。これを上回る件数では、その件数がマシンの処理能力の範囲内にあるかぎり、マシンのほうが安い。マシンの料金は、稼働していても遊休していても支払うことになる。そのため、損益分岐点はその料金をメッセージ1件あたりのホスト型の価格で割って求める。

月間の損益分岐メッセージ数 = 月額のマシン料金 ÷ メッセージ1件あたりのホスト型の価格

この式では、ホスト型の価格からマシンのメッセージ1件あたりのコストを差し引かない。処理能力いっぱいで稼働させたときのマシンの1件あたりコストは、固定料金を処理能力で割った値であり、その料金はすでに分子で1回数えられている。同じコストをもう一度差し引くと、マシンを二重に数えることになる。また、この式が成り立つのは処理能力の範囲内に限られる。それを超えると、1台のマシンでは件数をさばけないため、2台目のマシンについて、その料金と処理能力を用いて改めて計算する。

break-even-from-recorded-ratio.py Python 3.12.15 · torch 2.15.0+cpu · transformers 5.23.0 合格
"""The monthly volume at which one machine's bill equals the hosted bill for the router's prompts. The break-even lineis the point the prose rests on, and it holds only inside the capacity line, which the last line checks. The prices andthe machine's cost are example values, as in the bill; the router's rate is recorded on the machine."""import mathimport osos.environ["HF_HUB_OFFLINE"] = "1"os.environ["TRANSFORMERS_OFFLINE"] = "1"import torch  # noqa: E402torch.set_num_threads(2)import router_lib  # noqa: E402router_lib.setup_runtime()inputs = router_lib.bill_inputs_recorded()  # example prices and cost per hour, with the router's rate from the recordingtest = router_lib.read_rows("test")  # (text, label index) for every test row, in file ordermessages = [test[i][0] for i in router_lib.read_sample("test_200")]  # index 0 is the text; the label is index 1# Mean count of the whole router prompt, team list included, with SmolLM2-135M's tokenizer.input_tokens = router_lib.router_prompt_tokens(messages)# Prices are per million tokens, hence the division at the end.per_message = (input_tokens * inputs["price_per_million_input_tokens"]               + inputs["output_tokens_per_message"] * inputs["price_per_million_output_tokens"]) / 1_000_000machine_month = inputs["machine_cost_per_hour"] * inputs["hours_per_month"]capacity = inputs["router_messages_per_second"] * 3600 * inputs["hours_per_month"] * inputs["utilisation"]# The machine's bill is the same each month up to its capacity, so the hosted bill# equals it at messages = machine bill / hosted price per message.# Rounded up: the first whole message count at which the machine is no dearer.breakeven = math.ceil(machine_month / per_message)print(f"input tokens per message, hosted prompt (counted with SmolLM2-135M-Instruct, a stand-in tokenizer): {input_tokens}")print(f"example hosted price per message (example prices), USD: {per_message:.6f}")print(f"example machine bill per month (example cost per hour), USD: {machine_month:.2f}")print(f"machine capacity per month (recorded rate, example utilisation): {capacity:.0f}")print(f"example break-even messages per month (example prices and cost per hour): {breakeven}")print(f"break-even within machine capacity: {'yes' if breakeven <= capacity else 'no'}")
出力python break-even-from-recorded-ratio.py
input tokens per message, hosted prompt (counted with SmolLM2-135M-Instruct, a stand-in tokenizer): 587
example hosted price per message (example prices), USD: 0.000611
example machine bill per month (example cost per hour), USD: 292.00
machine capacity per month (recorded rate, example utilisation): 24966000
example break-even messages per month (example prices and cost per hour): 477906
break-even within machine capacity: yes

例の値では、マシンの料金 292.00 USD に対する損益分岐点は月 477906 件である。この件数は、マシンの処理能力である月 24966000 件の範囲内にある(検査の出力は yes である)。この処理能力は、記録された1呼び出しあたりの処理速度に、例の稼働率を適用したものである。

損益分岐点は(1呼び出しあたりの)処理速度には依存せず、マシンの料金とホスト型の価格だけで決まる。月 100000 件という件数はこれを大きく下回っているため、ホスト型の料金のほうが低い。

コストの分岐点は判断そのものではなく、残りの判断は受信箱が決める。コストの問いに答えられるのは、データを建物の外に出さないという要件が決着した後である。メッセージを内部にとどめる必要がある場合、問題は、どの小型モデルが正答数と引き継ぎ件数の基準を満たすかであり、損益分岐点は、そのマシンの費用が各件数でホスト型モデルと比べてどうなるかを示す。要件がホスト型モデルの利用を認め、かつ件数が損益分岐点を下回るなら、例の価格ではホスト型モデルのほうがコストの低い選択肢である。損益分岐点を上回る場合は、件数がマシンの処理能力の範囲内にあり、ルーターの誤答が問い合わせ元に届く件数を、サポート担当者が許容できるなら、マシンのほうがコストの低い選択肢である。引き継ぎは、料金がどうであれ人間の担当者に回す。最初の200件のメッセージのうち、ルーターは 33/200 (16.5%) 件を引き継いだ。

実践ルール: 損益分岐点は、自分のマシンの料金と、読み取ったホスト型の価格を用いて計算し、その価格の日付と出典を横に書いておく。損益分岐点を節約額として読む前に、見込みの件数が、自分のマシンで測定した処理能力の範囲内にあることを確認する。その処理能力を超える場合は、2台目のマシンを数に入れて計算し直す。損益分岐点は判断ではなくコストの分岐点として読む。ルーターを本番に出すかどうかは、これまでの節で扱った要件と正答数が引き続き決める。

この本が受信箱について下した決定

最終変更:版2026.11.2

本書が挙げる標本とマシンについて、受信箱に関係する数値は次のとおりである。各項目には、その数値を数えた章を添える。

  • 精度。 test_1001 の全件について、ルーターが正しく答えたのは 847/1001 (84.6%)、代用モデルが正しく答えたのは 560/1001 (55.9%) である(2章)。ルーターは残りを担当者に引き継ぐが、76/1001 (7.6%) 件の誤った答えは依然として発信者に届く。この件数は、ルーターを稼働させる前にサポート担当者が受け入れなければならない数である。
  • 速度。 記録したマシンで、1 回の呼び出しにつき 1 件のメッセージを処理したとき、分類器は毎秒 19.0 件で動作し、代用モデルは毎秒 0.32 件であった。比は 60.8 である(速度の測り方は7章で述べる)。int8 のコピーには、それを提供する速度上の理由がなかった。バッチサイズ 16 での float32 に対する比は 0.9 であった。したがって、経路が提供するのは引き続き float32 のアダプターである(8章)。
  • コスト。 例の入力では、月に 100000 件のメッセージにかかる費用は、ホスト型では 61.10 USD、自前のマシンでは 292.00 USD である。損益分岐点は月に 477906 件であり、これは月 24966000 件という処理能力の範囲内にある。これらは例の価格と例の時間単価であるから、損益分岐点を決定として読む前に、日付と出典を付けた自分の値に置き換えること。
  • データ要件。 メッセージが銀行のマシンの外に出てはならない場合、ホスト型モデルは選択肢から外れ、選択はそこで動作する選択肢の中から行うことになる。建物の内部にデータを留める節で述べたとおり、まずこれを確定させる。
  • 小さなモデルを選ばない場合。 ラベル付きメッセージを持たないチームには、出力側のヘッドがない。新しいチームには、9章の手順が必要である。自由記述の答えは、本書の最初の試行で失敗した(4章)。自由記述や幅広い知識についてはホスト型モデルのほうが良い結果を出すと予想されるが、それは検証すべき問いである。また、ホスト型モデルが許される場合でも、損益分岐点を下回る量では、例の価格ではホスト型モデルのほうが安い経路である。
  • 学んだこと。 データ要件とチームの一覧が、残る選択肢を決める。費用の計算がそれらの中から選ぶのは、その後である。

受信箱についての結論。 メッセージが銀行のマシンの外に出てはならず、すべてのチームがラベル付きメッセージを持つ場合は、銀行自身のマシン上の小さなルーターが選択肢となる。ただし、量が銀行自身の価格での損益分岐点を上回り、かつマシンの処理能力の範囲内にあることを条件とする。担当者への引き継ぎは、費用の計算がどうであれ経路に残す。発信者に届く誤った答えは、稼働させる前に、銀行自身の標本で数えること。

実践ルール: 選ぶ前に、この一覧を自分の受信箱について自分の数値で書き直すこと。自分の件数、日付、要件から導かれていない結論は、あなたの受信箱に対する本書の結論ではない。

この版における本章

第2026.11.9版2026年11月20日時点で例が通過この章の5 例件のうち5件が合格

英語版の書籍(版2026.11.9)から翻訳した。

この節を引用する

形式

いずれの形式も、本訳書が従う英語版の書籍を出典として示す。

いずれの形式もこの版を明示している。そのリンクは現行版を開き、節の見出しには本文が最後に変更された日付が示される。アクセス日と取得日は、これを開いた日である。

このページの内容

全10章中の第10章: 小さなモデルが誤った選択となる場合

  1. Where the small model still loses
  2. 請求額とマシンを数える
  3. データを社内にとどめる
  4. 表で選ぶ
  5. 損益分岐点を把握する
  6. この本が受信箱について下した決定

ページの先頭に戻るすべての章