benchmarl.models.ModelConfig

class ModelConfig[source]

Bases: ABC

Dataclass representing a Model configuration. This should be overridden by implemented models. Implementors should:

  1. add configuration parameters for their algorithm

  2. implement all abstract methods

get_model(input_spec: Composite, output_spec: Composite, agent_group: str, input_has_agent_dim: bool, n_agents: int, centralised: bool, share_params: bool, device: device | str | int, action_spec: Composite, model_index: int = 0) Model[source]

Creates the model from the config.

Parameters:
  • input_spec (Composite) – the input spec of the model

  • output_spec (Composite) – the output spec of the model

  • agent_group (str) – the name of the agent group the model is for

  • n_agents (int) – the number of agents this module is for

  • device (str) – the mdoel’s device

  • input_has_agent_dim (bool) – This tells the model if the input will have a multi-agent dimension or not. For example, the input of policies will always have this set to true, but critics that use a global state have this set to false as the state is shared by all agents

  • centralised (bool) – This tells the model if it has full observability. This will always be true when self.input_has_agent_dim==False, but in cases where the input has the agent dimension, this parameter is used to distinguish between a decentralised model (where each agent’s data is processed separately) and a centralized model, where the model pools all data together

  • share_params (bool) – This tells the model if it should have only one set of parameters or a different set of parameters for each agent. This is independent of the other options as it is possible to have different parameters for centralized critics with global input.

  • action_spec (Composite) – The action spec of the environment

  • model_index (int) – the index of the model in a sequence. Defaults to 0.

Returns: the Model

abstract static associated_class()[source]

The associated Model class

property is_rnn: bool

Whether the model is an RNN

property is_critic

Whether the model is a critic

get_model_state_spec(model_index: int = 0) Composite[source]

Get additional specs needed by the model as input.

This method is useful for adding recurrent states.

The returned value should be key: spec with the desired ending shape.

The batch and agent dimensions will automatically be added to the spec.

Parameters:

model_index (int, optional) – the index of the model. Defaults to 0.

classmethod get_from_yaml(path: str | None = None)[source]

Load the model configuration from yaml

Parameters:

path (str, optional) – The full path of the yaml file to load from. If None, it will default to benchmarl/conf/model/layers/self.associated_class().__name__

Returns: the loaded AlgorithmConfig