From 86332022b489f9253cbaf8f71f8d49b47d765036 Mon Sep 17 00:00:00 2001 From: Andrew Zhang <31525996+andrewzhang505@users.noreply.github.com> Date: Mon, 16 Jan 2023 16:35:24 -0800 Subject: [PATCH] Set device in notebook (#262) --- sf_examples/notebooks/samplefactory_hub_example.ipynb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sf_examples/notebooks/samplefactory_hub_example.ipynb b/sf_examples/notebooks/samplefactory_hub_example.ipynb index 9500df1dc..60f16fec8 100644 --- a/sf_examples/notebooks/samplefactory_hub_example.ipynb +++ b/sf_examples/notebooks/samplefactory_hub_example.ipynb @@ -1,6 +1,7 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -8,12 +9,12 @@ "\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/" ] }, { @@ -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'" ] }, {