Rl Post Trainingのロゴ

Rl Post Training

組織人気
benchflow-ai
rl-post-training

言語モデルのRLベースの事後学習(GRPO、PPO、REINFORCE、DPO)に関する診断ガイドです。改善が見られない、損失に異常がある、報酬が停滞している、勾配がNaNになるなど、強化学習によるファインチューニング中に予期しない動作を示すトレーニングパイプラインのデバッグ時に、積極的に活用してください。診断を完了と判断する前に、報酬、アドバンテージ、対数確率、損失、生成・デコードの各段階をすべて確認します。1、2か所を修正しただけで終えるのは、よくある失敗です。対数確率の計算、アドバンテージ推定、数値安定性、報酬処理、生成・デコードパイプラインの問題を扱います。

Add to TypingMind

概要

公開者benchflow-ai
リポジトリskillsbench
スキル名rl-post-training
スター
1.8K
フォーク
371
同梱ファイル
3
ライセンスApache-2.0
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 3個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    benchflow-aiがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Rl Post Training」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/benchflow-ai/skillsbench/tree/main/tasks/debug-trl-grpo/environment/skills/rl-post-training
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/benchflow-ai/skillsbench.git /tmp/skillsbench
mkdir -p .claude/skills
cp -r /tmp/skillsbench/tasks/debug-trl-grpo/environment/skills/rl-post-training .claude/skills/rl-post-training
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでRl Post Trainingを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にRl Post Trainingを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Rl Post Trainingは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

RL Post-Training — Concepts & Diagnostic Guide

Core Concepts

RL post-training optimizes a language model's policy using reward signals. The standard pipeline:

prompt → generate completions → score with reward → compute advantages → policy gradient update

Each stage has distinct failure modes. When a model "shows no improvement," the bug could be anywhere in this pipeline.

Diagnostic Methodology

When RL training produces no improvement, work through these stages in order. Each stage depends on the previous one being correct.

Stage 1: Verify Reward Signal

  • Are rewards non-constant? If all rewards are identical, there is no learning signal.
  • Do rewards correlate with completion quality? Spot-check decoded completions against their scores.
  • Is the reward function being called on the correct text? Check that decoding/stripping preserves the content the reward function needs to evaluate.

Stage 2: Verify Advantage Computation

  • Are advantages non-zero when rewards vary? If they collapse to ~0, the policy gradient vanishes.
  • Check the magnitude and dtype of every numerical-stability constant in the advantage path (additive epsilons, clipping bounds). Compare each to what the math requires.
  • Check the group size G. G ≤ 2 makes std either undefined or extremely noisy.

Stage 3: Verify Log-Probability Computation

  • Verify bounds: log-probs of valid tokens must be non-positive.
  • Compare your implementation against F.log_softmax on a small deterministic input — a numerical match rules out sign errors, wrong gathering axis, and off-by-one subtraction.
  • On a near-one-hot input, confirm the dominant token's log-prob is close to 0 (not close to the min).

Stage 4: Verify Loss Computation

  • Is the loss changing across steps? Flat loss suggests zero gradients upstream.
  • Log the KL term and the policy-gradient term separately. Either dominating the other is diagnostic.
  • Check the fraction of clipped samples. Near-100% clipping means the clip range is starving the signal.

Stage 5: Verify Generation and Decoding

  • Are padding and decoder artefacts stripped from the text the reward function sees?
  • Does every completion shape your model can emit survive the decoding path with non-empty output where a human would expect non-empty output? Include degenerate cases (no formatting markers, only a prefix, only a suffix) in the round-trip test.
  • Print or log a sample of the actual strings handed to the reward function — mismatches between "what the model generated" and "what the reward saw" are often visible at a glance.

Fixing, Not Rewriting

A bug in a branched function is a bug in one branch, not a verdict on the whole function. Before editing:

  • Enumerate the input shapes the function handles today and the output each branch produces. The branches exist because callers rely on them.
  • Identify which input-output pairs violate the intended contract. Those are the only branches you need to change.
  • If your diff collapses a multi-branch function to a one-liner, you have almost certainly broken a contract a different caller depends on. Re-read the call sites before committing.

The same principle applies to epsilon values, sign conventions, and clipping bounds — if a constant looks wrong, replace it with a correct constant; don't remove the surrounding numerical-stability logic.

Key Mathematical Invariants

These invariants should always hold. If any is violated, there is a bug.

InvariantWhat it meansHow to check
log_prob <= 0Log of a probability is non-positiveassert (log_probs <= 1e-6).all()
log-probs match F.log_softmaxManual implementation equals the referencetorch.allclose(manual, F.log_softmax(...).gather(...))
sum(softmax(logits)) == 1Probabilities sum to 1assert torch.allclose(softmax.sum(-1), ones)
0 < epsilon << 1Additive epsilons exist for numerical stability onlyassert 0 < epsilon < 1
advantages != 0 when rewards varyNon-constant rewards yield non-zero advantagesassert advantages.abs().max() > 0.1
Decoding preserves contentEvery generation shape the model emits survives the decode path with the content a human reader would expectRound-trip representative samples; confirm non-empty where non-empty is expected

Common Pitfall Categories

Detailed pitfall catalog with examples is in references/common-pitfalls.md. Summary:

  1. Sign errors in log-space — log-softmax, KL divergence, DPO log-ratio
  2. Numerical stability constants out of range — additive epsilons, clip bounds, temperature
  3. String processing in decoding — cleanup that blanks shapes the rules didn't anticipate
  4. Reward / decoding format mismatch — reward function sees text with the shape it needs removed
  5. Reference model drift — reference model not frozen, or gradients flowing through it
  6. Gradient flow breakage — detached tensors, in-place ops, .item()/numpy round-trips in the loss path
  7. Configuration misuse — SFT-scale LR, KL coefficient dominating, clip range too tight, G too small

Available References

FileContentsWhen to load
references/common-pitfalls.mdCatalog of pitfall categories with symptoms and detection strategiesWhen you have a suspicious area and want to match it against known pattern shapes
references/diagnostic-workflow.mdStage-by-stage diagnostic procedures with verification snippetsWhen you need guidance on which invariant to check in which order
scripts/verify_pipeline.pyRunnable diagnostic that prints log-prob / advantage / decoding values on small fixed inputs so you can compare them against the invariants aboveBefore declaring a fix done: run this and inspect the output, paying attention to lines marked ?

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Rl Post Training」では何ができますか?

言語モデルのRLベースの事後学習(GRPO、PPO、REINFORCE、DPO)に関する診断ガイドです。改善が見られない、損失に異常がある、報酬が停滞している、勾配がNaNになるなど、強化学習によるファインチューニング中に予期しない動作を示すトレーニングパイプラインのデバッグ時に、積極的に活用してください。診断を完了と判断する前に、報酬、アドバンテージ、対数確率、損失、生成・デコードの各段階をすべて確認します。1、2か所を修正しただけで終えるのは、よくある失敗です。対数確率の計算、アドバンテージ推定、数値安定性、報酬処理、生成・デコードパイプラインの問題を扱います。

TypingMindでRl Post Trainingを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Rl Post Trainingはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにRl Post Trainingをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/benchflow-ai/skillsbench/tree/main/tasks/debug-trl-grpo/environment/skills/rl-post-trainingを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Rl Post Trainingを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Rl Post Trainingで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもRl Post Trainingを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Rl Post Training」は無料ですか?

はい。benchflow-aiがApache-2.0ライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇