SlideShare a Scribd company logo
1 of 36
Download to read offline
분산 강화학습

(Distributed Prioritized
Experience Replay)

구현
김정주 (haje01@gmail.com)
“그들은 원한다면 정보와 지각을 공유할 수 있다. 그리고 어떤 부분을 공유할지도 정할 수 있다.”
http://annatar92.tumblr.com/post/157764169831/a-tachikoma-タチコマ-is-an-ai-walkerroller-tank-in
소개
강화학습 동향
•알고리즘 고도화와 다중 에이전트 연구가 함께 진행

•알고리즘: TRPO, PPO, UNREAL

•다중 에이전트

•병렬: A3C, A2C

•분산: Ape-X, IMPALA
다중 에이전트 목적
•학습 시간을 빠르게

•성능을 높게 👍
우선 경험 리플레이

(Prioritized Experience Replay)
•경험 리플레이는 강화학습에서 널리 사용 (뉴럴넷 활용)

•우선 경험 리플레이는 가장 놀라운 경험에 집중

•척도(예: TD Error)에 따라 샘플의 우선도 계산
P(i) =
pα
i
∑k
pα
k
Ape-X 특징
•액터(Actor, CPU)는 리플레이와 우선도를 공유 메모리에 추가

•단일 러너(Learner, GPU)는 이 메모리에서 샘플링하여 학습

•개별 환경을 가진 다양한 액터가 경험을 생성

•서로 다른 epsilon 값으로 e-greedy 정책을 사용
ϵi = ϵ1+ i
N − 1 α
Ape-X 특징 (2)
•액터의 메모리는 주기적으로 최신 네트웍 모수로 갱신

•원칙적으로 액터/러너 둘 다 분산 가능하지만, 실험결과 수백개의
액터가 CPU에서 동작하고, 단일 러너가 GPU에 있는 것이 가장 유
용한 경험을 샘플링 함
Ape-X DQN
•개선된 DQN 사용

•Double Q-Learning, Multistep-Bootstrap targets,
Dueling-Network

•Q-러닝 계열은 Off-Policy이기에, 데이터 생성 정책은 자유

•실재로는 행위 정책의 선택이 탐험과 함수 근사의 질에 영향

•각 액터는 다른 정책을 실행, 가장 효율적인 경험을 선택하는 우선
화(Prioritized) 기재에 따라 다양한 전략에서 경험 생성
Ape-X 구조도
Actor 슈도 코드
Learner 슈도 코드
논문의 구현
•TensorFlow + Tesla P100

•액터당 139 FPS (학습과정이 없어 빠른 듯)

•360개 액터(90 대?): 139 x 360 = 50K FPS

•4프레임 스킵을 고려하면 초당 12.5K개 전이(스텝)

•공유 메모리는 인메모리 KV 스토리지

•순환 버퍼에서 우선도 샘플링
논문의 구현
•공유된 리플레이 버퍼는 200만 전이

•학습율 0.00025/4, 감쇄 0.95의 RMSProp Optimizer

•Actor

•전이 100개씩 버퍼링 후 50개 단위 보내짐 (100/(139/4) =
약 2.8 초당 1번)

•매 400 프레임 (약 2.8초)당 러너의 패러미터 복사
논문의 구현
•Learner

•50,000 전이 이상이 되면 학습시작

•512개 전이의 16 배치까지 비동기로 사전 추출

•초당 배치 19개 분 업데이트 계산(512x19=9,728 전이)

•초당 평균 이 9.7K 전이를 위한 경사 업데이트

•타겟 네트웍을 2,500 배치에 한 번씩 갱신 (2500/19 = 131
초, 약 2분에 1번)
(mini) 배치가 512 !
•강화학습은 탐험과 이용의 아슬아슬한 타협

•큰 배치는 학습이 빠를 수 있으나, 현재 데이터에 오버피팅 되기 쉽다

•이를 막기 위해 분산 SGD, 중요도 샘플링, 우선 경험 리플레이 방법
을 테스트

•제거(Ablation) 분석에서 우선 경험 리플레이가 가장 효과적
벤치마크
벤치마크
Rainbow에 비해 학습 시간은 1/2, 프레임은 114배, 점수는 2배
액터 수의 영향
액터 수를 8에서 256까지 늘리는 것에 따라 일정하게 성능이 향상. 

수행된 학습 업데이트 수는 액터 수에 의존하지 않는 것에 주목
구현 도전
https://github.com/haje01/distper
구현 스펙
•Ape-X DQN

•PyTorch + AWS EC2 p2.xlarge (Tesla K80)

•ZeroMQ

•Terraform
논문 구현과 차이점
•Prioritized DQN으로 구현

•KV 스토리지 대신 ZeroMQ

•Publish-Subscribe 패턴으로 모델 배포

•러너, 버퍼, 액터 개별 프로세스 구현

•Send, Sample, Prefetch를 위한 스레드 없음

•실험 대상: Atari 57 Games -> Pong
논문 구현과 차이점
•액터별 초당 약 60 전이

•16개 액터 (테스크 노드 4 대)

•공유된 리플레이 버퍼는 50만 전이

•학습율 0.00025 / 4의 Adam Optimizer 

•Actor

•전이 100 개씩 버퍼링 후 보내짐 (약 2초당 1번)

•약 10초당 한 번 러너의 패러미터 복사
논문 구현과 차이점
•Learner

•1만 전이 이상이 되면 학습시작

•초당 256 배치 약 4개 분 업데이트 계산(1024 전이)

•타겟 네트웍을 200 배치에 한 번씩 갱신 (약 1분에 1번)
구현 구조도
배포 문제
•다양한 경험이 필요 -> 많은 테스크 노드

•하나씩 설치하고 관리하기는 힘듦

•AWS + Terraform 👏
Terraform을 통한 배포
$ terraform init
$ terraform apply
$ terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ aws_instance.actor_node
id: <computed>
ami: "ami-b9e357d7"
associate_public_ip_address: <computed>
availability_zone: <computed>
ebs_block_device.#: <computed>
...
tags.Name: "distper-actor"
tenancy: <computed>
volume_tags.%: <computed>
vpc_security_group_ids.#: <computed>
+ aws_instance.learner_node
id: <computed>
ami: "ami-b9e357d7"
associate_public_ip_address: <computed>
availability_zone: <computed>
ebs_block_device.#: <computed>
ephemeral_block_device.#: <computed>
...
tags.Name: "distper-learner"
vpc_security_group_ids.#: <computed>
+ aws_security_group.distper
id: <computed>
arn: <computed>
description: "Security group for DistPER."
egress.#: "1"
egress.2281976595.cidr_blocks.#: "0"
...
ingress.2030822154.to_port: "22"
name: "distper-sg"
owner_id: <computed>
revoke_rules_on_delete: "false"
tags.%: "2"
tags.Name: "distper-sg"
vpc_id: <computed>
배포 결과
학습 결과 (4 액터)
학습이 진행됨에 따라 epsilon이 낮은 쪽이 높은 점수
epsilon=0.064 epsilon=0.025
epsilon=0.4 epsilon=0.016
학습 결과 (16 액터)
학습 결과 (16 액터)
플레이
소감
•논문을 읽는 것과 구현하는 것의 차이는 크다

•강화학습은 아주 민감하다

•학습 결과를 기록하자

•Software 1.0 스킬이 필요
감사합니다.
참고자료
•https://arxiv.org/abs/1803.00933

•https://arxiv.org/abs/1511.05952

•https://github.com/Shmuma/ptan

•https://github.com/rlcode

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

분산 강화학습(Distributed Prioritized Experience Replay) 구현

  • 1. 분산 강화학습 (Distributed Prioritized Experience Replay) 구현 김정주 (haje01@gmail.com)
  • 2. “그들은 원한다면 정보와 지각을 공유할 수 있다. 그리고 어떤 부분을 공유할지도 정할 수 있다.” http://annatar92.tumblr.com/post/157764169831/a-tachikoma-タチコマ-is-an-ai-walkerroller-tank-in
  • 4. 강화학습 동향 •알고리즘 고도화와 다중 에이전트 연구가 함께 진행 •알고리즘: TRPO, PPO, UNREAL •다중 에이전트 •병렬: A3C, A2C •분산: Ape-X, IMPALA
  • 5. 다중 에이전트 목적 •학습 시간을 빠르게 •성능을 높게 👍
  • 6. 우선 경험 리플레이 (Prioritized Experience Replay) •경험 리플레이는 강화학습에서 널리 사용 (뉴럴넷 활용) •우선 경험 리플레이는 가장 놀라운 경험에 집중 •척도(예: TD Error)에 따라 샘플의 우선도 계산 P(i) = pα i ∑k pα k
  • 7. Ape-X 특징 •액터(Actor, CPU)는 리플레이와 우선도를 공유 메모리에 추가 •단일 러너(Learner, GPU)는 이 메모리에서 샘플링하여 학습 •개별 환경을 가진 다양한 액터가 경험을 생성 •서로 다른 epsilon 값으로 e-greedy 정책을 사용 ϵi = ϵ1+ i N − 1 α
  • 8. Ape-X 특징 (2) •액터의 메모리는 주기적으로 최신 네트웍 모수로 갱신 •원칙적으로 액터/러너 둘 다 분산 가능하지만, 실험결과 수백개의 액터가 CPU에서 동작하고, 단일 러너가 GPU에 있는 것이 가장 유 용한 경험을 샘플링 함
  • 9. Ape-X DQN •개선된 DQN 사용 •Double Q-Learning, Multistep-Bootstrap targets, Dueling-Network •Q-러닝 계열은 Off-Policy이기에, 데이터 생성 정책은 자유 •실재로는 행위 정책의 선택이 탐험과 함수 근사의 질에 영향 •각 액터는 다른 정책을 실행, 가장 효율적인 경험을 선택하는 우선 화(Prioritized) 기재에 따라 다양한 전략에서 경험 생성
  • 13. 논문의 구현 •TensorFlow + Tesla P100 •액터당 139 FPS (학습과정이 없어 빠른 듯) •360개 액터(90 대?): 139 x 360 = 50K FPS •4프레임 스킵을 고려하면 초당 12.5K개 전이(스텝) •공유 메모리는 인메모리 KV 스토리지 •순환 버퍼에서 우선도 샘플링
  • 14. 논문의 구현 •공유된 리플레이 버퍼는 200만 전이 •학습율 0.00025/4, 감쇄 0.95의 RMSProp Optimizer •Actor •전이 100개씩 버퍼링 후 50개 단위 보내짐 (100/(139/4) = 약 2.8 초당 1번) •매 400 프레임 (약 2.8초)당 러너의 패러미터 복사
  • 15. 논문의 구현 •Learner •50,000 전이 이상이 되면 학습시작 •512개 전이의 16 배치까지 비동기로 사전 추출 •초당 배치 19개 분 업데이트 계산(512x19=9,728 전이) •초당 평균 이 9.7K 전이를 위한 경사 업데이트 •타겟 네트웍을 2,500 배치에 한 번씩 갱신 (2500/19 = 131 초, 약 2분에 1번)
  • 16. (mini) 배치가 512 ! •강화학습은 탐험과 이용의 아슬아슬한 타협 •큰 배치는 학습이 빠를 수 있으나, 현재 데이터에 오버피팅 되기 쉽다 •이를 막기 위해 분산 SGD, 중요도 샘플링, 우선 경험 리플레이 방법 을 테스트 •제거(Ablation) 분석에서 우선 경험 리플레이가 가장 효과적
  • 18. 벤치마크 Rainbow에 비해 학습 시간은 1/2, 프레임은 114배, 점수는 2배
  • 19. 액터 수의 영향 액터 수를 8에서 256까지 늘리는 것에 따라 일정하게 성능이 향상. 수행된 학습 업데이트 수는 액터 수에 의존하지 않는 것에 주목
  • 21. 구현 스펙 •Ape-X DQN •PyTorch + AWS EC2 p2.xlarge (Tesla K80) •ZeroMQ •Terraform
  • 22. 논문 구현과 차이점 •Prioritized DQN으로 구현 •KV 스토리지 대신 ZeroMQ •Publish-Subscribe 패턴으로 모델 배포 •러너, 버퍼, 액터 개별 프로세스 구현 •Send, Sample, Prefetch를 위한 스레드 없음 •실험 대상: Atari 57 Games -> Pong
  • 23. 논문 구현과 차이점 •액터별 초당 약 60 전이 •16개 액터 (테스크 노드 4 대) •공유된 리플레이 버퍼는 50만 전이 •학습율 0.00025 / 4의 Adam Optimizer •Actor •전이 100 개씩 버퍼링 후 보내짐 (약 2초당 1번) •약 10초당 한 번 러너의 패러미터 복사
  • 24. 논문 구현과 차이점 •Learner •1만 전이 이상이 되면 학습시작 •초당 256 배치 약 4개 분 업데이트 계산(1024 전이) •타겟 네트웍을 200 배치에 한 번씩 갱신 (약 1분에 1번)
  • 26. 배포 문제 •다양한 경험이 필요 -> 많은 테스크 노드 •하나씩 설치하고 관리하기는 힘듦 •AWS + Terraform 👏
  • 27. Terraform을 통한 배포 $ terraform init $ terraform apply
  • 28. $ terraform apply An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: + aws_instance.actor_node id: <computed> ami: "ami-b9e357d7" associate_public_ip_address: <computed> availability_zone: <computed> ebs_block_device.#: <computed> ... tags.Name: "distper-actor" tenancy: <computed> volume_tags.%: <computed> vpc_security_group_ids.#: <computed> + aws_instance.learner_node id: <computed> ami: "ami-b9e357d7" associate_public_ip_address: <computed> availability_zone: <computed> ebs_block_device.#: <computed> ephemeral_block_device.#: <computed> ... tags.Name: "distper-learner" vpc_security_group_ids.#: <computed> + aws_security_group.distper id: <computed> arn: <computed> description: "Security group for DistPER." egress.#: "1" egress.2281976595.cidr_blocks.#: "0" ... ingress.2030822154.to_port: "22" name: "distper-sg" owner_id: <computed> revoke_rules_on_delete: "false" tags.%: "2" tags.Name: "distper-sg" vpc_id: <computed>
  • 30. 학습 결과 (4 액터) 학습이 진행됨에 따라 epsilon이 낮은 쪽이 높은 점수 epsilon=0.064 epsilon=0.025 epsilon=0.4 epsilon=0.016
  • 31. 학습 결과 (16 액터)
  • 32. 학습 결과 (16 액터)
  • 34. 소감 •논문을 읽는 것과 구현하는 것의 차이는 크다 •강화학습은 아주 민감하다 •학습 결과를 기록하자 •Software 1.0 스킬이 필요