もくじIndex

イメージでわかる 学習の流れ

Visual Guide to the Training Flow

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.

1. 「学習」ってなに?

1. What Is "Training"?

推論は「答えを出すこと」。学習は「答え合わせをしながら中身を直すこと」。

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.

📖 テスト勉強のたとえ: 📖 Studying-for-a-test analogy: テスト勉強は「問題を解く → 答え合わせ → 間違いを直す → もう一回解く」のくり返し。AI の学習もまさに同じ流れです。 Studying means "solve a problem → check the answer → fix mistakes → solve again." AI training follows exactly the same loop.

2. 学習はこう進む — 5つのステップ

2. How Training Works — 5 Steps

1回の学習サイクルは、たった5ステップ。これをひたすらくり返します。

One training cycle is just 5 steps. The model repeats them over and over.

1

入力を入れる

Feed the Input

学習データ(問題文)をモデルに渡す。テスト勉強でいう「問題を読む」段階。

Pass training data (the question) to the model. Like reading a test question.

2

予想を出す(フォワードパス)

Make a Prediction (Forward Pass)

モデルが今の「実力」で答えを出す。最初はデタラメに近い。テストで「とりあえず書いてみる」のと同じ。

The model answers using its current ability. At first, it's mostly random. Like writing your best guess on a test.

3

正解とくらべる(loss を計算する)

Compare with the Right Answer (Compute Loss)

予想と正解がどれだけ外れたかを計算する。この「外れ具合」を 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.

4

間違いの原因を探す(バックプロパゲーション)

Trace the Source of Error (Backpropagation)

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.

5

パラメータを少し直す(最適化)

Adjust Parameters a Little (Optimization)

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."

🔁 そしてステップ1に戻る。 🔁 Then back to Step 1. この5ステップを何万回・何十万回とくり返すことで、モデルはだんだん賢くなります。 By repeating these 5 steps tens or hundreds of thousands of times, the model gradually becomes smarter.
🎯 的当てのたとえ: 🎯 Target-shooting analogy: 的を狙う → 外れる → どれだけ外れたか測る(loss)→ 狙いを修正する(optimizer)→ もう一回投げる。繰り返すうちに、だんだん的の中心に近づく。 Aim at a target → miss → measure how far off (loss) → adjust your aim (optimizer) → throw again. Over time, you get closer and closer to the bullseye.

3. loss ってなに?

3. What Is "Loss"?

ひとことで言うと「どれだけ外れたかを表す点数」です。

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.

📏 テスト点数のたとえ: 📏 Test-score analogy: テストの「不正解数」が loss。不正解が 50 問あったのが、勉強を重ねて 3 問に減る。それが学習の進みかたです。 Think of loss as "the number of wrong answers." You started with 50 wrong, and after studying, it's down to 3. That's how training progresses.

4. 重みはどう変わるの?

4. How Do Weights Change?

間違いが減る方向へ、少しずつ調整されます。

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.

⚠️ よくある誤解: ⚠️ Common misconception: 「重みは人間が手動で決める」と思われがちですが、そうではありません。最初はランダムに設定し、学習のくり返しで自動的に良い値に育てるのが深層学習の特徴です。 People often think weights are set manually. They're not. Weights start random and grow into good values automatically through repeated training — that's what makes deep learning "deep."
🎯 的当てのことば: 🎯 In target-shooting terms: 重み = 狙いの角度。loss = 的から外れた距離。optimizer = 角度をちょっと直す係。learning rate = 1回に直す量。 Weight = aiming angle. Loss = distance from the bullseye. Optimizer = the coach who adjusts your angle. Learning rate = how much to adjust each time.

5. 何回もくり返すとどうなる?

5. What Happens After Many Repetitions?

最初はデタラメだった予想が、回数を重ねるとどんどん正解に近づきます。

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.

💡 学習の終了: 💡 When training ends: loss が十分小さくなり、未見データでも良い精度が出るようになったら学習は完了。できあがったモデルを「推論」に使います。 Training finishes when loss is low enough and accuracy on unseen data is good. The resulting model is then used for "inference."

6. 学習と推論のちがい

6. Training vs Inference

学習 = 直す。推論 = 使う。これだけ覚えれば 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
学習時はバックプロパゲーションのぶん計算量が約2〜3倍になり、中間結果を保存するためメモリも多く必要です。これが「学習には高性能 GPU が必要」と言われる理由です。 Backpropagation roughly doubles or triples the computation, and storing intermediate results demands more memory. That's why "training requires high-end GPUs."

7. ROCm だとどう動く?

7. How Does This Work on ROCm?

学習の5ステップは、ROCm 上ではそれぞれ専用のライブラリが担当します。

Each of the 5 training steps maps to a specific ROCm library.

rocBLAS — 行列計算の主役

rocBLAS — The Matrix Workhorse

ステップ2(フォワードパス)で重み行列と入力の掛け算を担当。学習でも推論でも、いちばん時間がかかる計算をここが引き受けます。

Handles weight × input matrix multiplications in Step 2 (forward pass). This is the most time-consuming computation in both training and inference.

MIOpen — 畳み込み・活性化関数

MIOpen — Convolution & Activation

ステップ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 ランタイム — GPU メモリ管理

HIP Runtime — GPU Memory Management

学習では中間結果(勾配・活性値)を大量に保存するため、メモリ確保・転送を HIP が管理します。学習時は推論時よりもずっと多くの VRAM を使います。

Training stores massive intermediate results (gradients, activations), so HIP manages memory allocation and transfers. Training uses far more VRAM than inference.

PyTorch (ROCm 版) — 全体の指揮者

PyTorch (ROCm build) — The Conductor

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.

⚠️ gfx900(Vega)での学習: ⚠️ Training on gfx900 (Vega): 学習は推論より計算量・メモリ使用量が大きいため、VRAM 8 GB の Vega 56/64 では大規模モデルの学習は現実的ではありません。ただし、小規模モデルのファインチューニングや実験レベルの学習は動作可能です。gfx900 で使える solver が限られる点は fallback 解説ページ、つまり予備の少し遅い道の説明を参照してください。 Training demands more compute and memory than inference, so large-model training is impractical on Vega 56/64 with 8 GB VRAM. However, fine-tuning small models or running experiments is feasible. For solver limitations on gfx900, see the fallback explanation page, which explains the slower backup routes.

他のページとのつながり

How This Connects to Other Pages

深層学習ページの「フィルタは訓練で決まる」 → ステップ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.