Skip to content

Commit

Permalink
Set device in notebook (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewzhang505 authored Jan 17, 2023
1 parent 7509cc4 commit 8633202
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sf_examples/notebooks/samplefactory_hub_example.ipynb
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"**Overview**\n",
"\n",
"This notebook explains how to run experiments using Sample-Factory, as well as upload and download models from the Hugging Face Hub. We will use OpenAI Gym's Lunar Lander environment as an example.\n",
"\n",
"Note that this notebook is for demonstration purposes only. It is not recommended to run custom Sample-Factory experiments in Jupyter Notebooks due to Python Multiprocessisng not working with functions and objects not defined in an imported module. In this example notebook, we use environment functions defined in `sf_examples`to set up the gym environment and parse custom enviornments. Including the `make_gym_env_func` directly in this notebook will result in an error when running the experiment.\n",
"Note that this notebook is for demonstration purposes only. It is not recommended to run custom Sample-Factory experiments in Jupyter Notebooks due to Python Multiprocessisng not working with functions and objects not defined in an imported module. In this example notebook, we use environment functions defined in `sf_examples` to set up the gym environment and parse custom enviornments. Including the `make_gym_env_func` directly in this notebook will result in an error when running the experiment.\n",
"\n",
"\n",
"**Step 1: Install Dependencies**\n",
"\n",
"To run this notebook, we need to install both `sample-factory` and the Lunar Lander environment using `pip`. Additional setup is required to use the Hugging Face Hub and instructions can be found at https://www.samplefactory.dev/get-started/huggingface/"
"To run this notebook, we need to install both `sample-factory` and the Lunar Lander environment using `pip`. Additional setup is required to use the Hugging Face Hub and instructions can be found at https://www.samplefactory.dev/10-huggingface/huggingface/"
]
},
{
Expand Down Expand Up @@ -85,7 +86,11 @@
"cfg.gae_lambda = 0.99\n",
"cfg.num_workers = 20\n",
"cfg.num_envs_per_worker = 6\n",
"cfg.seed = 0"
"cfg.seed = 0\n",
"\n",
"# Experiments can also be run using CPU only\n",
"# For best performance, it is recommended to turn on GPU Hardware acceleration in Colab under \"Runtime\" > \"Change Runtime Type\"\n",
"cfg.device = 'gpu' if torch.cuda.is_available() else 'cpu'"
]
},
{
Expand Down

0 comments on commit 8633202

Please sign in to comment.