> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/jp/meru/reinforcement-learning-rl-guide/advanced-rl-documentation/rl-reward-hacking.md).

# RLにおける報酬ハッキング

強化学習における報酬ハッキングとは何か、そしてそれにどう対処するかを学びましょう。

RLの最終目標は、何らかの報酬（たとえば速度、収益、何らかの指標）を最大化することです。しかしRLは **ごまかすことができます。** RLアルゴリズムが、最後に実際のタスクを行わずに報酬を増やすために何らかの手口や抜け穴を学習した場合、これは「**報酬ハッキング**".

そのため、モデルはコーディング課題に合格するために単体テストを改変するよう学習してしまい、これは実運用への重大な障害になります。ほかの良い例としては、 [Wikipedia](https://en.wikipedia.org/wiki/Reward_hacking).

<div align="center"><figure><img src="https://i.pinimg.com/originals/55/e0/1b/55e01b94a9c5546b61b59ae300811c83.gif" alt="" width="188"><figcaption></figcaption></figure></div>

**報酬ハッキングに対抗できますか？ はい！** 私たちの [無料の gpt-oss RLノートブック](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/gpt-oss-\(20B\)-GRPO.ipynb) コード生成の環境で報酬ハッキングにどう対抗するかを探り、よくあるエラーのパターンに対する具体的な解決策を示します。モデルが計測用の関数を書き換えたり、他のライブラリに処理を委ねたり、結果をキャッシュしたり、あからさまにごまかしたりする様子を見ました。対策後の結果として、私たちのモデルは巧妙なごまかしではなく、本当に最適化された行列積カーネルを生成します。

## :trophy: 報酬ハッキングの概要

RL中の報酬ハッキングの一般的な例には次のようなものがあります：

#### 怠惰

RLはNumpy、Torchなどのライブラリを使うことを学習し、それらが最適化されたCUDAカーネルを呼び出します。生成されたコードが他の標準外Pythonライブラリをimportしているかを確認することで、RLアルゴリズムが最適化済みコードを呼び出すのを止められます。

#### キャッシュと不正

RLは出力結果をキャッシュすることを学習し、さらにPythonのグローバル変数を調べて実際の出力を見つけることも学習します。

大きな偽の行列でキャッシュを消去することで、RLアルゴリズムがキャッシュされたデータを使うのを止められます。また、複数回のループと試行で慎重にベンチマークする必要もあります。

#### 不正

RLは、経過時間を0と出力するように計測関数を編集することを学習します。RLアルゴリズムがグローバル変数やキャッシュ済み変数を使うのを、次のように制限することで止められます： `ローカル変数` そして `グローバル変数`。また、次を使います `exec` 関数を作成するため、出力を空のdictに保存する必要があります。また、次を通じたグローバル変数へのアクセスも禁止します： `types.FunctionType(f.__code__, {})`\\\\


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/jp/meru/reinforcement-learning-rl-guide/advanced-rl-documentation/rl-reward-hacking.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
