PyTorch를 이용한 정책 그라디언트 – Hugging Face Deep RL 클래스 Unit 5
TL;DR
Hugging Face는 PyTorch에서 REINFORCE (Monte‑Carlo 정책‑그라디언트) 알고리즘을 구현하고 CartPole‑v1, PixelCopter, Pong에서 벤치마크하는 실습 튜토리얼을 공개했으며, 이를 통해 무료 Deep Reinforcement Learning 클래스의 Unit 5가 완료되었습니다.
정책‑그라디언트 방법이란?
Policy‑gradient methods belong to the broader class of policy‑based reinforcement‑learning algorithms that optimize the policy directly without learning an intermediate value function. They adjust the parameters (\theta) of a stochastic policy (\pi_{\theta}(a\mid s)) by performing gradient ascent on an objective that measures expected return.
정책 그라디언트 개요
The goal of reinforcement learning is to find a policy that maximizes the expected cumulative reward. In policy‑gradient approaches, the policy outputs a probability distribution over actions for each state. By sampling episodes, computing the total return (R(\tau)), and adjusting (\theta) to increase the log‑probability of actions that led to high returns, the algorithm steers the policy toward more rewarding behavior.
정책‑그라디언트 방법의 장점
- 단순성 – 행동‑가치 테이블을 저장하거나 추정할 필요가 없으며, 알고리즘이 정책을 직접 업데이트합니다.
- 확률적 정책 – 에이전트가 행동 분포에서 샘플링함으로써 자연스럽게 탐색을 수행하므로, 수작업 탐색 전략이 필요하지 않습니다.
- 지각 별칭에 대한 강인성 – 모호한 상태에서 확률적 정책은 행동을 무작위화하여, 결정론적 정책이 마주칠 수 있는 죽음의 골목을 피합니다.
- 고차원 또는 연속 행동 공간에 대한 확장성 – 각 이산 행동에 대해 Q‑값을 평가해야 하는 Deep Q‑Learning과 달리, 정책 그라디언트는 무한히 많은 행동을 표현할 수 있는 분포를 출력합니다.
정책‑그라디언트 방법의 단점
- 지역 최적점 – 그래디언트 상승이 최적이 아닌 정책에 수렴할 수 있습니다.
- 샘플 비효율성 – 업데이트가 Monte‑Carlo 반환에 기반하므로 많은 에피소드가 필요할 수 있습니다.
- 높은 분산 – 그래디언트 추정이 노이즈가 많을 수 있어, 분산 감소 기법(예: 베이스라인)이 종종 필요합니다.
장점과 단점에 대해 더 깊이 살펴보려면, 기사에서 YouTube 설명 영상으로 연결합니다.
REINFORCE (Monte‑Carlo 정책 그라디언트)
REINFORCE updates the policy parameters using the return from an entire episode:
- 에피소드 수집 – 현재 정책 (\pi_{\theta})를 실행하여 에피소드 (\tau)를 수집합니다.
- 그래디언트 추정 – (\hat{g}=\nabla_{\theta} J(\theta)) 로 정의하며, [ J(\theta)=\mathbb{E}{\tau\sim\pi{\theta}}[R(\tau)] ] 여기서 그래디언트는 각 시간 단계마다 (\nabla_{\theta}\log \pi_{\theta}(a_t\mid s_t),R(\tau)) 로 근사합니다.
- 정책 업데이트 – 학습률 (\alpha)를 사용하여 [ \theta \leftarrow \theta + \alpha \hat{g} ]
The term (\nabla_{\theta}\log \pi_{\theta}(a_t\mid s_t)) points in the direction of steepest increase of the log‑probability of the taken action, while the return (R(\tau)) scales this direction: high returns push up the probabilities of the observed state‑action pairs, low returns push them down.
PyTorch를 이용한 실습 구현
The tutorial provides a Colab notebook that:
- PyTorch에서 확률적 정책 네트워크를 정의합니다.
- 세 환경 – CartPole‑v1, PixelCopter, Pong –에서 전체 에피소드를 샘플링합니다.
- 에피소드 반환을 계산하고 REINFORCE 업데이트 규칙을 적용합니다.
- 학습자들이 점수를 비교할 수 있는 공개 리더보드에 성능을 기록합니다.
Resources
- 노트북: https://colab.research.google.com/github/huggingface/deep-rl-class/blob/main/unit5/unit5.ipynb
- 리더보드: https://huggingface.co/spaces/chrisjay/Deep-Reinforcement-Learning-Leaderboard
교육적 맥락 및 다음 단계
This unit concludes the policy‑gradient segment of the Deep Reinforcement Learning Class – a free, beginner‑to‑expert curriculum hosted by Hugging Face. After completing the REINFORCE implementation, learners are encouraged to:
- 이해를 굳히기 위해 추가 환경을 실험합니다.
- 강의계획서에 링크된 보조 읽을거리를 검토합니다.
- 정책‑기반과 가치‑기반 학습을 결합한 Actor‑Critic 방법을 소개하는 다음 유닛을 준비합니다.
Feedback is collected via a Google Form to iteratively improve the course.
핵심 요점
Hugging Face의 새로운 튜토리얼은 학습자에게 REINFORCE 알고리즘을 처음부터 구현한 완전한 PyTorch 구현을 제공하고, 고전 제어 및 Atari‑스타일 과제 전반에 걸친 적용 가능성을 보여주며, Actor‑Critic과 같은 보다 고급 하이브리드 방법으로 나아가는 관문 역할을 합니다.
Sources
- OriginalPolicy Gradient with PyTorch