malib.algorithm.common.model module

Model factory. Add more description

class malib.algorithm.common.model.MLP(observation_space: gym.spaces.space.Space, action_space: gym.spaces.space.Space, model_config: Dict[str, Any], **kwargs)[source]

Bases: malib.algorithm.common.model.Model

Create a Model instance. Common abstract methods could be added here.

Parameters
  • input_space – Input space size, int or gym.spaces.Space.

  • output_space – Output space size, int or gym.spaces.Space.

forward(obs)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class malib.algorithm.common.model.Model(input_space, output_space)[source]

Bases: torch.nn.modules.module.Module

Create a Model instance. Common abstract methods could be added here.

Parameters
  • input_space – Input space size, int or gym.spaces.Space.

  • output_space – Output space size, int or gym.spaces.Space.

get_initial_state(batch_size: Optional[int] = None) List[torch._C.TensorType][source]

Return a list of initial rnn state, if current model is rnn

training: bool
class malib.algorithm.common.model.RNN(observation_space: gym.spaces.space.Space, action_space: gym.spaces.space.Space, model_config: Dict[str, Any])[source]

Bases: malib.algorithm.common.model.Model

Create a Model instance. Common abstract methods could be added here.

Parameters
  • input_space – Input space size, int or gym.spaces.Space.

  • output_space – Output space size, int or gym.spaces.Space.

forward(obs, hidden_state)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

get_initial_state(batch_size: Optional[int] = None) List[torch._C.TensorType][source]

Return a list of initial rnn state, if current model is rnn

training: bool
malib.algorithm.common.model.get_model(model_config: Dict[str, Any])[source]
malib.algorithm.common.model.mlp(layers_config)[source]