ray.rllib.models.torch.torch_modelv2.TorchModelV2#

class ray.rllib.models.torch.torch_modelv2.TorchModelV2(obs_space: gymnasium.spaces.Space, action_space: gymnasium.spaces.Space, num_outputs: int, model_config: dict, name: str)[source]#

Bases: ModelV2

Torch version of ModelV2.

Note that this class by itself is not a valid model unless you inherit from nn.Module and implement forward() in a subclass.

Methods

__init__

Initialize a TorchModelV2.

context

Returns a contextmanager for the current forward pass.

custom_loss

Override to customize the loss function used to optimize this model.

forward

Call the model with the given input tensors and state.

get_initial_state

Get the initial recurrent state values for the model.

import_from_h5

Imports weights from an h5 file.

is_time_major

If True, data for calling this ModelV2 must be in time-major format.

last_output

Returns the last output returned from calling the model.

metrics

Override to return custom metrics from your model.

value_function

Returns the value function output for the most recent forward pass.