GOOD.ood_algorithms.algorithms.IRM

Implementation of the IRM algorithm from “Invariant Risk Minimization” paper

Classes

IRM(config)

Implementation of the IRM algorithm from "Invariant Risk Minimization" paper

class GOOD.ood_algorithms.algorithms.IRM.IRM(config: Union[CommonArgs, Munch])[source]

Bases: BaseOODAlg

Implementation of the IRM algorithm from “Invariant Risk Minimization” paper

Args:

config (Union[CommonArgs, Munch]): munchified dictionary of args (config.device, config.dataset.num_envs, config.ood.ood_param)

loss_postprocess(loss: Tensor, data: Batch, mask: Tensor, config: Union[CommonArgs, Munch], **kwargs) Tensor[source]

Process loss based on IRM algorithm

Parameters
  • loss (Tensor) – base loss between model predictions and input labels

  • data (Batch) – input data

  • mask (Tensor) – NAN masks for data formats

  • config (Union[CommonArgs, Munch]) – munchified dictionary of args (config.device, config.dataset.num_envs, config.ood.ood_param)

config = munchify({device: torch.device('cuda'),
                       dataset: {num_envs: int(10)},
                       ood: {ood_param: float(0.1)}
                       })
Returns (Tensor):

loss with IRM penalty

output_postprocess(model_output: Tensor, **kwargs) Tensor[source]

Process the raw output of model; apply the linear classifier

Parameters

model_output (Tensor) – model raw output

Returns (Tensor):

model raw predictions with the linear classifier applied