Hello,
I want to initialise a tranformer class, using arguments for a parent class BaseModelWithCovariates. I would like to initialise the variable “static_variables” using hparams
class Transformer(BaseModelWithCovariates):
def __init__(
self,
hidden_size: int = 16,
lstm_layers: int = 1,
dropout: float = 0.1,
output_size: Union[int, List[int]] = 7,
loss: MultiHorizonMetric = None,
attention_head_size: int = 4,
max_encoder_length: int = 10,
static_categoricals: List[str] = [],
static_reals: List[str] = [],
time_varying_categoricals_encoder: List[str] = [],
time_varying_categoricals_decoder: List[str] = [],
categorical_groups: Dict[str, List[str]] = {},
time_varying_reals_encoder: List[str] = [],
time_varying_reals_decoder: List[str] = [],
x_reals: List[str] = [],
x_categoricals: List[str] = [],
hidden_continuous_size: int = 8,
hidden_continuous_sizes: Dict[str, int] = {},
embedding_sizes: Dict[str, Tuple[int, int]] = {},
embedding_paddings: List[str] = [],
embedding_labels: Dict[str, np.ndarray] = {},
learning_rate: float = 1e-3,
log_interval: Union[int, float] = -1,
log_val_interval: Union[int, float] = None,
log_gradient_flow: bool = False,
reduce_on_plateau_patience: int = 1000,
monotone_constaints: Dict[str, int] = {},
share_single_variable_networks: bool = False,
logging_metrics: nn.ModuleList = None,
**kwargs,
):
if logging_metrics is None:
logging_metrics = nn.ModuleList([SMAPE(), MAE(), RMSE(), MAPE()])
if loss is None:
loss = MAE()
self.save_hyperparameters()
# store loss function separately as it is a module
assert isinstance(loss, LightningMetric), "Loss has to be a PyTorch Lightning `Metric`"
super().__init__(loss=loss, logging_metrics=logging_metrics, **kwargs)
self.static_variables = self.hparams.static_categoricals + self.hparams.static_reals
However I get the following attribute error:
AttributeError: can't set attribute
The getter for hparams hasn’t been deprecated, so this should work.
I would like to know what prevents me from attributing hparams to the new variable. Is there something that I misunderstand about how to use hparams?