Skip to content

Commit

Permalink
Add Hugging Face integration to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni-SM committed Jan 17, 2023
1 parent 3231a8d commit 2197161
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
6 changes: 4 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ Utils
Definition of helper functions and classes

* :doc:`Utilities <modules/skrl.utils.utilities>`, e.g. setting the random seed
* :doc:`Model instantiators <modules/skrl.utils.model_instantiators>`
* Memory and Tensorboard :doc:`file post-processing <modules/skrl.utils.postprocessing>`
* :doc:`Model instantiators <modules/skrl.utils.model_instantiators>`
* :doc:`Hugging Face integration <modules/skrl.utils.huggingface>`
* :doc:`Isaac Gym utils <modules/skrl.utils.isaacgym_utils>`
* :doc:`Omniverse Isaac Gym utils <modules/skrl.utils.omniverse_isaacgym_utils>`

Expand All @@ -233,7 +234,8 @@ Utils
:hidden:

modules/skrl.utils.utilities
modules/skrl.utils.model_instantiators
modules/skrl.utils.postprocessing
modules/skrl.utils.model_instantiators
modules/skrl.utils.huggingface
modules/skrl.utils.isaacgym_utils
modules/skrl.utils.omniverse_isaacgym_utils
24 changes: 24 additions & 0 deletions docs/source/intro/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,30 @@ The following code snippets show how to load the checkpoints through the instant
# Load the checkpoint
policy.load("./runs/22-09-29_22-48-49-816281_DDPG/checkpoints/2500_policy.pt")
In addition, it is possible to load, through the library utilities, trained agent checkpoints from the Hugging Face Hub (`huggingface.co/skrl <https://huggingface.co/skrl>`_). See the :doc:`Hugging Face integration <../modules/skrl.utils.huggingface>` for more information.

.. tabs::

.. tab:: Agent (from Hugging Face Hub)

.. code-block:: python
:emphasize-lines: 2, 13-14
from skrl.agents.torch.ppo import PPO
from skrl.utils.huggingface import download_model_from_huggingface
# Instantiate the agent
agent = PPO(models=models, # models dict
memory=memory, # memory instance, or None if not required
cfg=agent_cfg, # configuration dict (preprocessors, learning rate schedulers, etc.)
observation_space=env.observation_space,
action_space=env.action_space,
device=env.device)
# Load the checkpoint from Hugging Face Hub
path = download_model_from_huggingface("skrl/OmniIsaacGymEnvs-Cartpole-PPO")
agent.load(path)
Migrating external checkpoints
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
20 changes: 20 additions & 0 deletions docs/source/modules/skrl.utils.huggingface.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Hugging Face integration
========================

.. raw:: html

<hr>

Download model from Hugging Face Hub
------------------------------------

Several skrl-trained models (agent checkpoints) for different environments/tasks of Gym/Gymnasium, Isaac Gym, Omniverse Isaac Gym, etc. are available in the Hugging Face Hub

These models can be used as comparison benchmarks, for collecting environment transitions in memory (for offline reinforcement learning, e.g.) or for pre-initialization of agents for performing similar tasks, among others

Visit the `skrl organization on the Hugging Face Hub <https://huggingface.co/skrl>`_ to access publicly available models!

API
"""

.. autofunction:: skrl.utils.huggingface.download_model_from_huggingface
2 changes: 1 addition & 1 deletion docs/source/modules/skrl.utils.utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Utilities
=========

.. contents:: Table of Contents
:depth: 2
:depth: 1
:local:
:backlinks: none

Expand Down

0 comments on commit 2197161

Please sign in to comment.