Hub documentation

Hugging Face에서 Stable-Baselines3 사용

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Hugging Face에서 Stable-Baselines3 사용

stable-baselines3는 PyTorch로 구현된 강화 학습 알고리즘의 신뢰할 수 있는 구현 모음입니다.

Hub에서 Stable-Baselines3 탐색

모델 페이지 왼쪽에서 필터링하여 Stable-Baselines3 모델을 찾을 수 있습니다.

Hub의 모든 모델에는 유용한 기능이 함께 제공됩니다:

  1. 설명, 학습 구성 및 기타 항목이 포함된 자동 생성된 모델 카드
  2. 검색 가능성을 높이는 메타데이터 태그.
  3. 다른 모델과 비교하기 위한 평가 결과.
  4. 에이전트가 수행하는 모습을 볼 수 있는 비디오 위젯입니다.

라이브러리 설치

stable-baselines3 라이브러리를 설치하려면 두 개의 패키지를 설치해야 합니다:

  • stable-baselines3: Stable-Baselines3 라이브러리.
  • huggingface-sb3: Hub에서 Stable-baselines3 모델을 로드하고 업로드하기 위한 추가 코드.
pip install stable-baselines3
pip install huggingface-sb3

기존 모델 사용

load_from_hub 함수를 사용하여 Hub에서 모델을 다운로드할 수 있습니다.

checkpoint = load_from_hub(
    repo_id="sb3/demo-hf-CartPole-v1",
    filename="ppo-CartPole-v1.zip",
)

두 가지 매개변수를 정의해야 합니다:

  • --repo-id: 다운로드하려는 Hugging Face 저장소의 이름.
  • --filename: 다운로드할 파일

모델 공유

두 가지 다른 함수를 사용하여 모델을 쉽게 업로드할 수 있습니다:

  1. package_to_hub(): Hub에 전체 저장소를 푸시하기 전에 모델을 저장하고, 평가하며, 모델 카드를 생성하고, 에이전트의 리플레이 비디오를 기록합니다.
package_to_hub(model=model, 
               model_name="ppo-LunarLander-v2",
               model_architecture="PPO",
               env_id=env_id,
               eval_env=eval_env,
               repo_id="ThomasSimonini/ppo-LunarLander-v2",
               commit_message="Test commit")

다음의 7개 매개변수를 정의해야 합니다:

  • --model: 학습된 모델.
  • --model_architecture: 모델의 아키텍처 이름 (DQN, PPO, A2C, SAC…).
  • --env_id: 환경 이름.
  • --eval_env: 에이전트를 평가하는 데 사용되는 환경.
  • --repo-id: 생성하거나 업데이트하려는 Hugging Face 저장소의 이름입니다. <your huggingface username>/<the repo name> 형식입니다.
  • --commit-message.
  • --filename: Hub에 업로드하려는 파일.
  1. push_to_hub(): 파일을 Hub에 간단히 업로드합니다
push_to_hub(
    repo_id="ThomasSimonini/ppo-LunarLander-v2",
    filename="ppo-LunarLander-v2.zip",
    commit_message="Added LunarLander-v2 model trained with PPO",
)

세 가지 매개변수를 정의해야 합니다:

  • --repo-id: 생성하거나 업데이트하려는 Hugging Face 저장소의 이름입니다. <your huggingface username>/<the repo name> 형식입니다.
  • --filename: Hub에 업로드하려는 파일.
  • --commit-message.

추가 리소스

  • Hugging Face Stable-Baselines3 문서
  • Stable-Baselines3 문서
Update on GitHub