RLHF · PBRL | PEBBLE:透過 human preference 學習 reward model

MoonOut發表於2023-11-09



0 abstract

Conveying complex objectives to reinforcement learning (RL) agents can often be difficult, involving meticulous design of reward functions that are sufficiently informative yet easy enough to provide. Human-in-the-loop RL methods allow practitioners to instead interactively teach agents through tailored feedback; however, such approaches have been challenging to scale since human feedback is very expensive. In this work, we aim to make this process more sample- and feedback-efficient. We present an off-policy, interactive RL algorithm that capitalizes on the strengths of both feedback and off-policy learning. Specifically, we learn a reward model by actively querying a teacher's preferences between two clips of behavior and use it to train an agent. To enable off-policy learning, we relabel all the agent's past experience when its reward model changes. We additionally show that pre-training our agents with unsupervised exploration substantially increases the mileage of its queries. We demonstrate that our approach is capable of learning tasks of higher complexity than previously considered by human-in-the-loop methods, including a variety of locomotion and robotic manipulation skills. We also show that our method is able to utilize real-time human feedback to effectively prevent reward exploitation and learn new behaviors that are difficult to specify with standard reward functions.

摘要:

  • RL 的 reward function:對於複雜的目標,難以設計資訊量足夠 + 易於實現的 reward function。Human-in-the-loop RL 允許人的互動性教學,但是過於昂貴。
  • method:
    • 提出了一個 off-policy 的 interactive RL 演演算法,透過主動查詢 teacher 對兩個行為片段(clips of behavior)的 preference,來學習一個 reward model,並用它來訓練 RL agent。
    • 為了實現 off-policy learning,當 reward model 變化時,對 agent 的所有 past experience 進行 relabel。
    • 使用無監督探索(unsupervised exploration)來 pre-train agent,可以大幅提高查詢里程(the mileage of its queries)(?)
  • 實驗結果:
    • 可以應對 locomotion 和 robotic manipulation,先前的 Human-in-the-loop 方法難以應對。
    • 可以利用人類的實時反饋(real-time human feedback)來阻止 reward exploitation。
    • 學習難以用標準 reward function 指定的新行為。

1 intro

  • reward shaping 是 RL 應用的大問題。sparse reward 不容易訓練成功,dense reward 需要對 agent 狀態進行密集地觀測。
  • 儘管可以密集觀測 agent 狀態,但由於 reward exploitation,可能仍然很難構建合適的 reward function。
    • reward exploitation 指的是 agent 使用意想不到的方式達成高 reward(hack 了 reward function)。一個解決方案是 imitation learning,但獲得適合模仿的專家軌跡也很昂貴。
  • human-in-the-loop (HiL) RL 或許是個避免 reward exploitation 的好方法。
  • PEBBLE: unsupervised PrE-training and preference-Based learning via relaBeLing Experience。
    • 包含兩個模組(見圖 1):unsupervised pre-training、off-policy learning。
    • 首先,agent 僅使用內在動機(intrinsic motivation)進行探索,得到一些 experience,產生連貫的 behaviors。這種 unsupervised pre-training 提高了 teacher’s initial feedback 的 efficiency。
    • 然後,supervisor 對於一對 clips of agent behavior 給出自己的 preference,作為訓練 reward model 的資料,最後使用 RL 來最大化該 reward function 的 return。
  • RL 需要大量 supervised data,重用(reuse)資料可以提高 RL 的 sample efficiency。
    • 先前的 HiL RL 通常使用 on-policy 演演算法,為減輕 on-line learning 引起的獎勵非平穩性。
    • pebble 是 off-policy 的,在每次更新 reward model 時,都會 relabel agent 的所有 past experience。
  • main contributions:
    • 首次證明,unsupervised pre-training 和 off-policy learning,可以顯著提高 HiL RL 的 sample-efficiency 和 feedback-efficiency。
    • 在 DeepMind 和 Meta-world 的 locomotion 與 robotic manipulation 任務上,outperform PBRL(preference-based RL)baselines。
    • 證明 pebble 可以學習 典型獎勵函式難以有效設計的行為。
    • pebble 可以避免 reward exploitation,並且相比使用 engineered reward function 訓練的 agent,行為更理想。
  • Learning from human feedback:
    • 第一段是一些古早工作。
    • 透過 human feedback,學習一個 reward model:① 可以學習一個任務是否成功的 classifier,基於它構建獎勵函式。② 直接對實數形式的 human feedback 進行迴歸(regression),不太可行,因為 human feedback 不太可靠。
  • human feedback 是 01 判斷的形式:
    • 比較行為的好與壞,被稱作 preference-based learning。
    • 第三段有大量相關工作。Christiano et al.(2017)提出了 on-line 的 PBRL,但樣本效率太低,隨後的 demonstrations (Ibarz et al., 2018) 和 non-binary rankings (Cao et al., 2020) 有改善一些。
    • pebble 使用 off-policy 經驗回放 + unsupervised pre-training 來提高樣本效率。
  • RL 的無監督預訓練(Unsupervised pre-training for RL):
    • 透過無監督預訓練,提取強大的行為先驗(behavioral priors)。
    • 具體的,鼓勵智慧體透過最大化各種內在獎勵,來擴充套件可見狀態的邊界,比如 env dynamics 的預測誤差、基於計數的狀態新穎性、互資訊、狀態熵。
    • 聽起來像 RL exploration(本站關於 RL exploration 的綜述部落格)。

3 Preliminaries

  • 簡單介紹 RL。

  • Soft Actor-Critic(SAC):off-policy,最大化 reward 和 policy entropy 的加權,交替進行 ① 軟策略評估(公式 1)② 軟策略改進(公式 2)。

  • Reward learning from preferences:

    • segment σ: 一段 trajectory \(\{s_k,a_k,\cdots,s_{k+H},a_{k+H}\}\)

    • 對於 segments σ0 和 σ1,有一個 preference y ∈{ (0,1), (1,0), (0.5,0.5) }。

    • judgment 的形式為 (σ0, σ1, y) 的三元組。

    • 獎勵函式 \(\hat r_{\psi}\) 滿足下式,其中 \(σ^1\succ σ^0\) 代表 σ1 比 σ0 更可取。

    • \[P_\psi[σ^1\succ σ^0] = \frac{\exp\sum_t \hat r_{\psi}(s_t^1,a_t^1)}{\sum_{i\in\{0,1\}}\exp\sum_t \hat r_{\psi}(s_t^i,a_t^i)} \]

    • 可以解釋為,我們假設,human 偏好某一 segment 的機率,取決於一個 underlying reward function 在 segment 的每一 (st,at) 上指數求和。

    • 更新 \(\hat r_{\psi}\) 的 loss function:

    • \[L^{reward}=-E_{(σ^0,σ^1,y)\sim D}\bigg[ y(0)\log P_\psi[σ^0\succ σ^1] + y(1)\log P_\psi[σ^1\succ σ^0] \bigg] \]

4 PEBBLE

建立 policy \(\pi_\phi\) 、Q function \(Q_\theta\) 、reward function \(\hat r_\psi\) ,它們的更新過程如下:

  • Step 0 (unsupervised pre-training):只使用 intrinsic motivation 來預訓練 policy \(\pi_\phi\) ,去 explore 並收集不同的 experiences。(4.1 節)
  • Step 1 (reward learning):透過從 teacher 那裡獲得反饋,學習 reward function \(\hat r_\psi\)
  • Step 2 (agent learning):使用 off-policy RL 演演算法,更新 policy \(\pi_\phi\) 和 Q-function \(Q_\theta\) ,並重新標記(relabel)以減輕非平穩獎勵函式(non-stationary reward function) \(\hat r_\psi\) 的影響(參見第 4.3 節)。
  • 重複 Step 1 和 Step 2。

4.1 Accelerating Learning via Unsupervised Pre-training - 透過無監督預訓練加速學習

關於 intrinsic reward:

  • 原始形式:狀態熵 \(H(s)=-E_{s\sim p(s)}[\log p(s)]\) ,鼓勵訪問更廣泛的狀態(應該是希望狀態熵越大越好)。
  • 簡化版本,基於粒子的熵估計: \(\hat H(s)\propto\sum_i\log(\|s_i-s_i^k\|)\) ,其中 \(s_i^k\) 是 si 的第 k 個最近鄰,這意味著,最大化狀態與其最近鄰之間的距離,會增加整體狀態熵。
  • 設計 reward: \(r^{int}(s_t)=\log(\|s_t-s_t^k\|)\) ,將當前狀態的 intrinsic reward 定義為與其 k-th nearest neighbor 之間的距離。(該思想參考了一篇 21 年的文章,將每個 transition 視作一個 particle 粒子)
  • 對於每個樣本 (st,at),計算它與 replay buffer 中所有樣本之間的 k-NN 距離,並將其除以標準差的執行估計值,對 intrinsic reward 進行歸一化,最終得到 r int,將其作為 pre-train 過程的 RL reward。

【演演算法 1(EXPLORE: Unsupervised exploration)無監督探索。基於 SAC 框架,將 reward 換成 r int。】

最後會初始化得到 replay buffer B 和初始 policy \(\pi_\phi\)

4.2 Selecting Informative Queries - 選擇資訊量大的 queries

  • 如何選擇兩個 segment(或者叫 segment pair),拿去問人類的 preference,能獲得最多、最有效、幫助最大的資訊呢?
  • 也就是說,如何選擇 informative queries?(query 指的是拿 segment pair 問人類 preference 的過程)
  • 理想情況下,應該計算 EVOI(expect value of information)(不知道是什麼),但比較難算,因為需要對更新後的 policy 的所有可能 trajectories 求期望,所以,會有一些近似方法。
  • pebble 使用了 17 年的一個抽樣方案:
    • ① 均勻抽樣 uniform sampling;
    • ② 基於整合的抽樣 ensemble-based sampling,在 ensemble reward models 中選擇具有高方差的 pairs of segment。
    • 我們探索了第三種方法 ③ 基於熵的抽樣,試圖消除最接近 decision boundary 的 pairs of segments 的歧義。也就是說,我們對一大批 segment pairs 進行取樣,並選擇最大化的 H(Pψ) 的 segment pair,其中 H(Pψ) 是 section 3 中提到的、基於 reward model 的 segment preference 機率。
  • 這些 sampling methods 的有效性,在 Section 5 中評估。

4.3 Using Off-policy RL with Non-Stationary Reward - 在非平穩獎勵中使用 off-policy RL

  • 需要注意,reward function \(\hat r_\psi\) 可能是非平穩(non-stationary)的,因為我們在訓練期間會更新它。
  • 先前工作使用 on-policy 來接近這個問題,但 sample efficiency 太低了。
  • pebble 使用了 off-policy RL 框架,在每次更新 reward model 時,使用新的 reward model 對所有 transition 的 reward 進行 relabel。

【演演算法 2(PEBBLE)】

  • 第 7-19 行在學習 reward model。
  • 第 20-23 行在收集新資料,使用更新後的 reward model,對所有 replay buffer 裡的 transitions 進行 relabel。
  • 第 24-27 行在最佳化 sac loss,是在學 RL。
  • 反覆跑 7-19、20-23、24-27 的過程。

5 Experiments

四個問題:

  1. pebble 在 sample efficiency 和 feedback efficiency 方面,與現有方法相比如何?
  2. pebble 中提出的每種技術,貢獻分別是什麼?
  3. pebble 能否學習到,典型獎勵函式 難以針對性設計的新行為?
  4. pebble 能否減輕 reward exploitation 的影響?

5.1 Setups

  • benchmarks: DeepMind Control Suite,Meta-world。
  • 使用一個基於 real reward function 的指令碼 teacher,提供對 segment pair 的 preference。
    • 因為 scripted teacher 跑很快,所以可以多做幾次實驗,實驗結果包含 十次執行的平均值和標準差。
  • human teacher:
    • 可以教授新穎(novel)的行為(比如 揮舞腿),這些行為在 original benchmarks 中沒有定義。
    • 發現使用 engineered reward function 的 agent 可能會 reward exploitation,但使用 human feedback 的 agent 不會。
    • 對於所有實驗,每個 segment 都以 1 秒的影片剪輯呈現給人類,最多需要 1 小時的人類時間。
  • baselines:
    • Christiano 等人(2017)的工作,是同樣使用這種 preference + segment pair 的最新工作了,將它們的方法稱為 Preference PPO。
    • 使用 ground truth reward 的 SAC、PPO,它們作為 upper bound。
    • 對於 section 4.2 想選取 informative queries 時,提到的三種 sampling method,可以得到三個 reward model,我們將它們進行 ensemble(?)

5.2 Benchmark Tasks with Unobserved Rewards

  • 圖 3 - Locomotion tasks from DMControl(DeepMind Control):
    • (在圖例中標出)我們給 Preference PPO 提供更多 feedback。pebble 只需要更少的 feedbacks,就能匹配其他 baselines 的效能。
    • 綠色、黃色、棕色是 pebble,效能非常好的樣子。
  • 圖 4 - Robotic manipulation tasks from Meta-world:
    • (發現那種漂亮的帶陰影的線,其實是多個 runs 的平均)
    • 同樣,好像效能非常好,使用 5000 / 10000 feedback 的 pebble 接近幾個 upper bound oracle。

5.3 Ablation Study

  • 圖 5-a 考察了 relabeling 和 pre-training 的效果。
  • 圖 5-b 比較了 section 4.2 提到的 sampling schemes。
  • 圖 5-c 考察了 segment 長度對效能的影響,segment length = 1 是所謂 step-wise feedback。發現 50 比 1 效能更好,推測是因為長 segment 可以提供更多背景資訊。

5.4 Human Experiments

  • 圖 6 - novel behaviors:演示了 ① Cart 代理揮動杆子(使用 50 個 queries),② 四足動物代理揮舞前腿(使用 200 個 queries),③ Hopper 執行後空翻(使用 50 個 queries)。supplementary material 提供了一些影片和 queries 例項。
  • 圖 7 - reward exploitation:發現 Walker agent 只用一條腿學習走路,hack 了 reward function。然而,透過使用 200 個 human queries,我們能夠訓練 Walker 以更自然、更像人類的方式(使用雙腿)行走。

6 Discussion

  • 提出了 pebble,一種用於 HiL RL(Human-in-the-Loop RL)的 feedback-efficient 的演演算法。
  • 效能:
    • 透過利用 ① unsupervised pre-training ② off-policy RL,可以顯著提高 HiL RL 的 sample-efficiency 和 feedback-efficiency。
    • 並且,pebble 可以用於比先前工作更復雜的任務,包括各種運動(locomotion)和 robotic manipulation 。
    • 此外,透過實驗證明瞭,pebble 可以學習 novel 的行為,並避免 reward exploitation;與經過工程獎勵函式訓練的 agent 相比,pebble 可以產生更理想的行為。
  • 我們相信,pebble 透過使 PBRL 更可行,有助於擴大 RL 的影響;RL 的影響力將會從專家精心設計 reward function 的侷限,擴充套件到外行可以透過簡單的 preference 比較,來促進 RL 領域的進步。

Appendix

  • A. State Entropy Estimator
  • B. Experimental Details
  • C. Effects of Sampling Schemes
  • D. Examples of Selected Queries


相關文章