Extending launch.py for Sb3 and Ray

Schola supports extending the launch.py scripts for both ray and sb3 with additional callbacks and logging. This is done using Python plugins, which enable automatic discovery of new code extending schola. The plugins must extend an appropriate base class, and register an appropriately named entry point. The launch.py scripts will then automatically discover the plugin and use it to modify the training process. Below are the steps to specifically extend the schola.scripts.sb3.launch and schola.scripts.ray.launch scripts.

Extending schola.scripts.sb3.launch

You can extend schola.scripts.sb3.launch with additional callbacks, KVWriters for logging and command line arguments. Below is an example of how to implement a plugin which adds a CSV logger and a callback to log every N timesteps.

  1. Create a new class that inherits from Sb3LauncherExtension, and implement these methods if relevant: get_extra_KVWriters(), get_extra_callbacks(), and add_plugin_args_to_parser().

Copied!

from schola.scripts.common import Sb3LauncherExtension
from dataclasses import dataclass
from typing import Dict, Any
import argparse
from stable_baselines3.common.logger import KVWriters, CSVOutputFormat
from stable_baselines3.common.callbacks import LogEveryNTimesteps

@dataclass
class ExampleSb3Extension(Sb3LauncherExtension):
    csv_save_path: str = "./output.csv"
    log_frequency: int = 1000

    def get_extra_KVWriters(self):
        return [CSVOutputFormat(self.csv_save_path)]

    def get_extra_callbacks(self):
        return [LogEveryNTimesteps(n_steps=log_frequency)]

    @classmethod
    def add_plugin_args_to_parser(cls, parser: argparse.ArgumentParser):
        """
        Add example logging arguments to the parser.

        Parameters
        ----------
        parser : argparse.ArgumentParser
            The parser to which the arguments will be added.
        """
        group = parser.add_argument_group("CSV Logging")
        group.add_argument("--csv-save-path", type=str, help="The path to save the CSV file to")
        group.add_argument("--log-frequency", type=int, help="The frequency to log to the terminal")

  1. Create a new Python package, with an entrypoint in the schola.plugins.sb3.launch group pointing to your new class.

Copied!

setup(
    ...,
    entry_points={
        'schola.plugins.sb3.launch': [
            'example_extension_name = example_plugin_name.example_extension_name:ExampleSb3Extension',
        ],
    },
    ...,
)

Extending schola.scripts.ray.launch

You can extend schola.scripts.ray.launch with additional callbacks, and command line arguments. Below is an example of how to implement a plugin which adds support for logging with Wandb.

  1. Create a new class that inherits from RLLibLauncherExtension, and implement these methods if relevant: get_extra_callbacks(), and add_plugin_args_to_parser().

Copied!

from schola.scripts.common import RLLibLauncherExtension
from dataclasses import dataclass
from typing import Any, Dict, List
import argparse
from ray.tune.integration.wandb import WandbLoggerCallback

@dataclass
class ExampleRayExtension(RLLibLauncherExtension):
    experiment_id: str = None

    def get_extra_callbacks(self):
        return [WandbLoggerCallback(project=self.experiment_id)]

    @classmethod
    def add_plugin_args_to_parser(cls, parser: argparse.ArgumentParser):
        """
        Add example logging arguments to the parser.

        Parameters
        ----------
        parser : argparse.ArgumentParser
            The parser to which the arguments will be added.
        """
        group = parser.add_argument_group("Wandb Logging")
        group.add_argument("--experiment-id", type=str, help="The experiment ID to log to")

  1. Create a new Python package, with an entrypoint in the schola.plugins.ray.launch group pointing to your new class.

Copied!

setup(
    ...,
    entry_points={
        'schola.plugins.ray.launch': [
            'example_extension_name = example_plugin_name.example_extension_name:ExampleRayExtension',
        ],
    },
    ...,
)

Related pages

  • Visit the Schola product page for download links and more information.

Looking for more documentation on GPUOpen?

AMD GPUOpen software blogs

Our handy software release blogs will help you make good use of our tools, SDKs, and effects, as well as sharing the latest features with new releases.

GPUOpen Manuals

Don’t miss our manual documentation! And if slide decks are what you’re after, you’ll find 100+ of our finest presentations here.

AMD GPUOpen Performance Guides

The home of great performance and optimization advice for AMD RDNAâ„¢ 2 GPUs, AMD Ryzenâ„¢ CPUs, and so much more.

Getting started: AMD GPUOpen software

New or fairly new to AMD’s tools, libraries, and effects? This is the best place to get started on GPUOpen!

AMD GPUOpen Getting Started Development and Performance

Looking for tips on getting started with developing and/or optimizing your game, whether on AMD hardware or generally? We’ve got you covered!

AMD GPUOpen Technical blogs

Browse our technical blogs, and find valuable advice on developing with AMD hardware, ray tracing, Vulkan®, DirectX®, Unreal Engine, and lots more.

Find out more about our software!

AMD GPUOpen Effects - AMD FidelityFX technologies

Create wonder. No black boxes. Meet the AMD FidelityFX SDK!

AMD GPUOpen Samples

Browse all our useful samples. Perfect for when you’re needing to get started, want to integrate one of our libraries, and much more.

AMD GPUOpen developer SDKs

Discover what our SDK technologies can offer you. Query hardware or software, manage memory, create rendering applications or machine learning, and much more!

AMD GPUOpen Developer Tools

Analyze, Optimize, Profile, Benchmark. We provide you with the developer tools you need to make sure your game is the best it can be!