def register_custom_model(model_name, model_class): """Register a custom model class by name. The model can be later used by specifying {"custom_model": model_name} in the model config. Args: model_name (str): Name to register the model under. model_class (type): Python class of the model. """ _global_registry.register(RLLIB_MODEL, model_name, model_class)
def register_custom_preprocessor(preprocessor_name, preprocessor_class): """Register a custom preprocessor class by name. The preprocessor can be later used by specifying {"custom_preprocessor": preprocesor_name} in the model config. Args: preprocessor_name (str): Name to register the preprocessor under. preprocessor_class (type): Python class of the preprocessor. """ _global_registry.register(RLLIB_PREPROCESSOR, preprocessor_name, preprocessor_class)
def register_custom_action_dist(action_dist_name, action_dist_class): """Register a custom action distribution class by name. The model can be later used by specifying {"custom_action_dist": action_dist_name} in the model config. Args: model_name (str): Name to register the action distribution under. model_class (type): Python class of the action distribution. """ _global_registry.register(RLLIB_ACTION_DIST, action_dist_name, action_dist_class)
def register_custom_preprocessor(preprocessor_name, preprocessor_class): """Register a custom preprocessor class by name. The preprocessor can be later used by specifying {"custom_preprocessor": preprocesor_name} in the model config. Args: preprocessor_name (str): Name to register the preprocessor under. preprocessor_class (type): Python class of the preprocessor. """ _global_registry.register(RLLIB_PREPROCESSOR, preprocessor_name, preprocessor_class)
def register_custom_model(model_name: str, model_class: type) -> None: """Register a custom model class by name. The model can be later used by specifying {"custom_model": model_name} in the model config. Args: model_name (str): Name to register the model under. model_class (type): Python class of the model. """ if issubclass(model_class, tf.keras.Model): deprecation_warning(old="register_custom_model", error=False) _global_registry.register(RLLIB_MODEL, model_name, model_class)
def testErrorHandling(self): ray.init(num_cpus=4, num_gpus=2) runner = TrialRunner() kwargs = { "stopping_criterion": {"training_iteration": 1}, "resources": Resources(cpu=1, gpu=1), } _global_registry.register(TRAINABLE_CLASS, "asdf", None) trials = [Trial("asdf", **kwargs), Trial("__fake", **kwargs)] for t in trials: runner.add_trial(t) runner.step() self.assertEqual(trials[0].status, Trial.ERROR) self.assertEqual(trials[1].status, Trial.PENDING) runner.step() self.assertEqual(trials[0].status, Trial.ERROR) self.assertEqual(trials[1].status, Trial.RUNNING)
def testStartFailure(self): _global_registry.register(TRAINABLE_CLASS, "asdf", None) trial = Trial("asdf", resources=Resources(1, 0)) self.trial_executor.start_trial(trial) self.assertEqual(Trial.ERROR, trial.status)
def action_adapter(model_action): assert model_action in [0, 1, 2, 3] return ACTIONS[model_action] # throttle, brake, steering = model_action # return np.array([throttle, brake, steering * np.pi * 0.25]) class TrainingModel(GTrXLNet): NAME = "GTrXLNet" # ModelCatalog.register_custom_model(TrainingModel.NAME, TrainingModel) _global_registry.register(RLLIB_MODEL, TrainingModel.NAME, TrainingModel) class RLLibTFSavedModelAgent(Agent): def __init__(self, path_to_model, observation_space): path_to_model = str(path_to_model) # might be a str or a Path, normalize to str self._prep = ModelCatalog.get_preprocessor_for_space(observation_space) self._sess = tf.compat.v1.Session(graph=tf.Graph()) tf.compat.v1.saved_model.load( self._sess, export_dir=path_to_model, tags=["serve"] ) self._output_node = self._sess.graph.get_tensor_by_name("default_policy/add:0") self._input_node = self._sess.graph.get_tensor_by_name( "default_policy/observation:0" )
from grl.rl_apps.scenarios.trainer_configs.defaults import GRL_DEFAULT_OPENSPIEL_POKER_DQN_PARAMS, \ GRL_DEFAULT_POKER_PPO_PARAMS from grl.rllib_tools.action_dists import TorchGaussianSquashedGaussian from grl.rllib_tools.models.valid_actions_fcnet import get_valid_action_fcn_class_for_env from grl.rllib_tools.valid_actions_epsilon_greedy import ValidActionsEpsilonGreedy class _PokerAndOshiBetaTorchDist(TorchBeta): def __init__(self, inputs, model): super(_PokerAndOshiBetaTorchDist, self).__init__(inputs, model, low=-1.0, high=1.0) _global_registry.register(RLLIB_ACTION_DIST, "PokerAndOshiBetaTorchDist", _PokerAndOshiBetaTorchDist) _global_registry.register(RLLIB_ACTION_DIST, "TorchGaussianSquashedGaussian", TorchGaussianSquashedGaussian) def psro_kuhn_dqn_params_openspiel(env: MultiAgentEnv) -> Dict[str, Any]: return GRL_DEFAULT_OPENSPIEL_POKER_DQN_PARAMS def psro_leduc_dqn_params_openspiel(env: MultiAgentEnv) -> Dict[str, Any]: return merge_dicts( GRL_DEFAULT_OPENSPIEL_POKER_DQN_PARAMS, { # === Exploration Settings === "exploration_config": { # The Exploration class to use.
def testStartFailure(self): _global_registry.register(TRAINABLE_CLASS, "asdf", None) trial = Trial("asdf", resources=Resources(1, 0)) self.trial_executor.start_trial(trial) self.assertEqual(Trial.ERROR, trial.status)