Visual Guide to the Training Flow
シリーズ: イメージでわかる
モデルが「答え合わせをしながら少しずつ賢くなる」流れを、テスト勉強のたとえでやさしく説明するページです。
A gentle explanation of how models learn by making predictions, checking errors, and gradually updating themselves — told through a "studying for a test" analogy.
推論は「答えを出すこと」。学習は「答え合わせをしながら中身を直すこと」。
Inference means "producing an answer." Training means "checking answers and fixing yourself."
AI モデルには推論(inference)と学習(training)の2つのフェーズがあります。
An AI model has two phases: inference and training.
推論は、すでにできあがったモデルに新しいデータを入れて答えをもらうこと。テストを受けて答えを書く段階です。
Inference feeds new data into a finished model and gets an answer. It's like taking a test.
学習は、問題を解き、答え合わせをし、間違えたところを直す――これを何百回もくり返してモデルを賢くする段階です。
Training is solving problems, checking answers, fixing mistakes — repeating this hundreds of times to make the model smarter.
1回の学習サイクルは、たった5ステップ。これをひたすらくり返します。
One training cycle is just 5 steps. The model repeats them over and over.
学習データ(問題文)をモデルに渡す。テスト勉強でいう「問題を読む」段階。
Pass training data (the question) to the model. Like reading a test question.
モデルが今の「実力」で答えを出す。最初はデタラメに近い。テストで「とりあえず書いてみる」のと同じ。
The model answers using its current ability. At first, it's mostly random. Like writing your best guess on a test.
予想と正解がどれだけ外れたかを計算する。この「外れ具合」を loss(損失) と呼ぶ。答え合わせして×がいくつあるか数えるイメージ。
Calculate how far the prediction was from the correct answer. This "distance" is called loss. Like grading your test and counting how many you got wrong.
loss をもとに、「どの重みがどれだけ間違いに貢献したか」を逆方向にたどって調べる。テスト勉強で「どの知識があいまいだったか」を特定するようなもの。
Using the loss, trace backward to find "which weights contributed how much to the error." Like figuring out which knowledge gaps caused your mistakes.
optimizer が、間違いが減る方向へ重みを少しだけ動かす。全部の重みを一気に大きく変えると壊れるので、少しずつ。ノートに赤ペンで「ここはこう覚え直す」と書くようなイメージ。
The optimizer nudges each weight slightly in the direction that reduces the error. Moving too much at once would break things, so it's always a small step. Like writing corrections in red pen: "re-learn this part."
ひとことで言うと「どれだけ外れたかを表す点数」です。
In one sentence: a score that tells you "how far off the prediction was."
モデルが「5」と予想したのに正解が「8」だったら、外れ具合は 3。この外れ具合を数値にしたものが loss です。
If the model predicts "5" but the answer is "8," the miss is 3. Loss is that miss turned into a number.
loss が大きい → まだまだ外れている → もっと直す必要がある。
A large loss → still far off → more correction needed.
loss が小さい → かなり近い → あまり直さなくてよい。
A small loss → pretty close → less correction needed.
学習の目標は、この loss をできるだけ小さくすることです。
The goal of training is to make this loss as small as possible.
間違いが減る方向へ、少しずつ調整されます。
They are adjusted a little at a time, always in the direction that reduces the error.
「重み(weight)」とは、モデルの中にある大量の数値のことです。畳み込みのフィルタも、Attention の中で使われる行列も、その正体は重みです。
"Weights" are the massive collection of numbers inside a model. The filters in convolution and the matrices used in Attention are all weights.
学習では、loss を減らす方向を計算し(ステップ4:バックプロパゲーション)、その方向にほんの少しだけ重みを動かします(ステップ5:最適化)。
During training, we compute the direction that reduces loss (Step 4: backpropagation) and nudge the weights just a little that way (Step 5: optimization).
いきなり大きく変えると学習が壊れるので、「学習率(learning rate)」という小さい係数をかけて、ちょっとずつ動かします。
Jumping too far breaks training, so a small multiplier called the learning rate ensures each step is tiny.
最初はデタラメだった予想が、回数を重ねるとどんどん正解に近づきます。
Predictions that started out random get closer and closer to the right answer.
学習データ全体を1回通すことを 1 エポック(epoch)と呼びます。たいてい何十〜何百エポックくり返します。
One pass through the entire training dataset is called 1 epoch. Typically, models train for tens to hundreds of epochs.
くり返すたびに loss は下がっていきます。ただし、ある程度から先は下がりにくくなります(テスト勉強でも、90点から100点にするのは50点から90点にするより大変ですよね)。
Loss drops with each repetition, but progress slows over time. (Getting from 90 to 100 on a test is harder than getting from 50 to 90, right?)
学習データには正解しすぎるのに、見たことないデータには間違えるようになることがあります。これを過学習(overfitting)といいます。テスト勉強でいうと、「過去問を丸暗記したけど、初めて見る問題に弱い」状態です。
The model may get training data perfectly right but fail on unseen data. This is called overfitting. In study terms: memorizing past exams but struggling with new questions.
学習 = 直す。推論 = 使う。これだけ覚えれば OK。
Training = fix yourself. Inference = use what you've learned. That's the key difference.
| 学習(Training) | Training | 推論(Inference) | Inference | ||
|---|---|---|---|---|---|
| 目的 | Purpose | モデルを育てる | Grow the model | 答えを出す | Produce answers |
| 正解データ | Ground truth | 必要(答え合わせするため) | Needed (for grading) | 不要 | Not needed |
| 重みの変化 | Weight changes | 毎回更新される | Updated every cycle | 変化しない(固定) | Frozen |
| 計算の方向 | Compute direction | 前方 + 後方(バックプロパゲーション) | Forward + backward (backpropagation) | 前方のみ | Forward only |
| 計算コスト | Compute cost | とても大きい | Very large | 学習より軽い | Lighter than training |
| たとえ | Analogy | テスト勉強 | Studying for a test | 本番のテスト | Taking the actual test |
学習の5ステップは、ROCm 上ではそれぞれ専用のライブラリが担当します。
Each of the 5 training steps maps to a specific ROCm library.
ステップ2(フォワードパス)で重み行列と入力の掛け算を担当。学習でも推論でも、いちばん時間がかかる計算をここが引き受けます。
Handles weight × input matrix multiplications in Step 2 (forward pass). This is the most time-consuming computation in both training and inference.
ステップ2で畳み込みや活性化を実行し、ステップ4(バックプロパゲーション)では勾配計算用の畳み込みも担当します。GPU ごとに最速の solver(計算のやり方)を選んでくれます。
Runs convolution and activation in Step 2, and also handles gradient convolutions in Step 4 (backpropagation). Selects the fastest solver (way of doing the computation) for each GPU.
学習では中間結果(勾配・活性値)を大量に保存するため、メモリ確保・転送を HIP が管理します。学習時は推論時よりもずっと多くの VRAM を使います。
Training stores massive intermediate results (gradients, activations), so HIP manages memory allocation and transfers. Training uses far more VRAM than inference.
5ステップの流れ全体を制御するフレームワーク。loss 計算、バックプロパゲーション、optimizer の呼び出しはすべて PyTorch が取りまとめ、裏で rocBLAS・MIOpen・HIP を呼び分けます。
The framework that orchestrates the entire 5-step loop. Loss computation, backpropagation, and optimizer calls are all coordinated by PyTorch, which delegates to rocBLAS, MIOpen, and HIP behind the scenes.
深層学習ページの「フィルタは訓練で決まる」 → ステップ4〜5で重みが更新されるから。
Deep Learning page says "filters are decided during training" → because weights are updated in Steps 4–5.
Attention ページの「重みは学習で決まる」 → Query・Key・Value の行列も学習で育つ。
Attention page says "weights are learned" → Q, K, V matrices are grown through training.
行列とAI ページの「パラメータが更新される」 → 行列の要素一つひとつが重みであり、学習で更新される。
Matrices & AI page says "parameters get updated" → each element of a matrix is a weight, updated during training.
INT8/FP32 ページの「学習時と推論時の違い」 → 学習は FP32 で精度を保ち、推論で INT8 に圧縮して高速化する、という使い分け。
INT8/FP32 page says "training vs inference differ" → training uses FP32 for precision; inference may compress to INT8 for speed.