Repository: pykeen/pykeen
Issue: Automatic Memory Optimization Unexpected keyword 
Root cause: Configuration Error

### Describe the bug

Hi, I am fairly new to pyKEEN. I am trying to run the hpo_pipeline from pykeen.hpo.hpo module with a TransE model. I am encountering the following issue: TypeError: __init__() got an unexpected keyword argument 'automatic_memory_optimization' in the models/base.py 

```python-traceback
[I 2022-07-29 13:14:10,576] A new study created in memory with name: no-name-2e8751b5-abdf-4b4a-be75-941d577823a6
INFO:pykeen.hpo.hpo:Using model: <class 'pykeen.models.unimodal.trans_e.TransE'>
INFO:pykeen.hpo.hpo:Using loss: <class 'pykeen.losses.NSSALoss'>
INFO:pykeen.hpo.hpo:Using regularizer: <class 'pykeen.regularizers.NoRegularizer'>
INFO:pykeen.hpo.hpo:Using optimizer: <class 'torch.optim.adam.Adam'>
INFO:pykeen.hpo.hpo:Using training loop: <class 'pykeen.training.slcwa.SLCWATrainingLoop'>
INFO:pykeen.hpo.hpo:Using negative sampler: <class 'pykeen.sampling.basic_negative_sampler.BasicNegativeSampler'>
INFO:pykeen.hpo.hpo:Using evaluator: <class 'pykeen.evaluation.rank_based_evaluator.RankBasedEvaluator'>
INFO:pykeen.hpo.hpo:Attempting to maximize both.realistic.hits_at_10
INFO:pykeen.hpo.hpo:Filter validation triples when testing: True
/projects/aa/cpga/pkg/lib/python3.9/site-packages/optuna/distributions.py:545: UserWarning: The distribution is specified by [1, 30] and q=2.0, but the range is not divisible by `q`. It will be replaced by [1, 29.0].
  warnings.warn(
WARNING:pykeen.pipeline.api:No random seed is specified. Setting to 3870135140.
INFO:pykeen.pipeline.api:Using device: None
[W 2022-07-29 13:14:10,862] Trial 0 failed because of the following error: TypeError("__init__() got an unexpected keyword argument 'automatic_memory_optimization'")
Traceback (most recent call last):
  File "/projects/aa/cpga/pkg/lib/python3.9/site-packages/optuna/study/_optimize.py", line 213, in _run_trial
    value_or_values = func(trial)
  File "/projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/hpo/hpo.py", line 259, in __call__
    result = pipeline(
  File "/projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/pipeline/api.py", line 1133, in pipeline
    model_instance, model_kwargs = _build_model_helper(
  File "/projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/pipeline/api.py", line 845, in _build_model_helper
    model_resolver.make(
  File "/projects/aa/cpga/pkg/lib/python3.9/site-packages/class_resolver/api.py", line 210, in make
    raise e
  File "/projects/aa/cpga/pkg/lib/python3.9/site-packages/class_resolver/api.py", line 204, in make
    return cls(**(pos_kwargs or {}), **kwargs)  # type: ignore
  File "/projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/models/base.py", line 819, in _new_init
    _original_init(self, *args, **kwargs)
  File "/projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/models/unimodal/trans_e.py", line 81, in __init__
    super().__init__(
  File "/projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/models/base.py", line 766, in __init__
    super().__init__(triples_factory=triples_factory, **kwargs)
  File "/projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/models/base.py", line 608, in __init__
    super().__init__(triples_factory=triples_factory, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'automatic_memory_optimization'
```

This is the traceback:
```python-traceback
TypeError                                 Traceback (most recent call last)
Input In [44], in <cell line: 1>()
----> 1 run_optimization(
      2         dataset=(training, val, test),
      3         model_config=config,
      4         out_dir="out"
      5     )

Input In [42], in run_optimization(dataset, model_config, out_dir)
      4 training_factory, testing_factory, validation_factory = dataset
      6 # Define HPO pipeline
----> 7 hpo_results = hpo_pipeline(
      8     dataset=None,
      9     training=training_factory,
     10     testing=testing_factory,
     11     validation=validation_factory,
     12     model=model_config["model"],
     13     model_kwargs=model_config["model_kwargs"],
     14     model_kwargs_ranges=model_config["model_kwargs_ranges"],
     15     loss=model_config["loss_function"],
     16     loss_kwargs=model_config["loss_kwargs"],
     17     loss_kwargs_ranges=model_config["loss_kwargs_ranges"],
     18     regularizer=model_config["regularizer"],
     19     optimizer=model_config["optimizer"],
     20     optimizer_kwargs=model_config["optimizer_kwargs"],
     21     optimizer_kwargs_ranges=model_config["optimizer_kwargs_ranges"],
     22     training_loop=model_config["training_loop"],
     23     training_kwargs=model_config["training_kwargs"],
     24     training_kwargs_ranges=model_config["training_kwargs_ranges"],
     25     negative_sampler=model_config["negative_sampler"],
     26     negative_sampler_kwargs=model_config["negative_sampler_kwargs"],
     27     negative_sampler_kwargs_ranges=model_config["negative_sampler_kwargs_ranges"],
     28     stopper=model_config["stopper"],
     29     stopper_kwargs=model_config["stopper_kwargs"],
     30     evaluator=model_config["evaluator"],
     31     evaluator_kwargs=model_config["evaluator_kwargs"],
     32     evaluation_kwargs=model_config["evaluation_kwargs"],
     33     metric=model_config["metric"],
     34     direction=model_config["direction"],
     35     sampler=model_config["sampler"],
     36 )
     38 optimization_dir = os.path.join(out_dir, 'pykeen_results_optim')
     39 if not os.path.isdir(optimization_dir):

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/hpo/hpo.py:857, in hpo_pipeline(dataset, dataset_kwargs, training, testing, validation, evaluation_entity_whitelist, evaluation_relation_whitelist, model, model_kwargs, model_kwargs_ranges, loss, loss_kwargs, loss_kwargs_ranges, regularizer, regularizer_kwargs, regularizer_kwargs_ranges, optimizer, optimizer_kwargs, optimizer_kwargs_ranges, lr_scheduler, lr_scheduler_kwargs, lr_scheduler_kwargs_ranges, training_loop, training_loop_kwargs, negative_sampler, negative_sampler_kwargs, negative_sampler_kwargs_ranges, epochs, training_kwargs, training_kwargs_ranges, stopper, stopper_kwargs, evaluator, evaluator_kwargs, evaluation_kwargs, metric, filter_validation_when_testing, result_tracker, result_tracker_kwargs, device, storage, sampler, sampler_kwargs, pruner, pruner_kwargs, study_name, direction, load_if_exists, n_trials, timeout, n_jobs, save_model_directory)
    801 objective = Objective(
    802     # 1. Dataset
    803     dataset=dataset,
   (...)
    853     device=device,
    854 )
    856 # Invoke optimization of the objective function.
--> 857 study.optimize(
    858     cast(Callable[[Trial], float], objective),
    859     n_trials=n_trials,
    860     timeout=timeout,
    861     n_jobs=n_jobs or 1,
    862     catch=(MemoryError, RuntimeError),
    863 )
    865 return HpoPipelineResult(
    866     study=study,
    867     objective=objective,
    868 )

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/optuna/study/study.py:400, in Study.optimize(self, func, n_trials, timeout, n_jobs, catch, callbacks, gc_after_trial, show_progress_bar)
    392 if n_jobs != 1:
    393     warnings.warn(
    394         "`n_jobs` argument has been deprecated in v2.7.0. "
    395         "This feature will be removed in v4.0.0. "
    396         "See [https://github.com/optuna/optuna/releases/tag/v2.7.0.](https://github.com/optuna/optuna/releases/tag/v2.7.0.%3C/span%3E%3Cspan) style="color:rgb(175,0,0)">",
    397         FutureWarning,
    398     )
--> 400 _optimize(
    401     study=self,
    402     func=func,
    403     n_trials=n_trials,
    404     timeout=timeout,
    405     n_jobs=n_jobs,
    406     catch=catch,
    407     callbacks=callbacks,
    408     gc_after_trial=gc_after_trial,
    409     show_progress_bar=show_progress_bar,
    410 )

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/optuna/study/_optimize.py:66, in _optimize(study, func, n_trials, timeout, n_jobs, catch, callbacks, gc_after_trial, show_progress_bar)
     64 try:
     65     if n_jobs == 1:
---> 66         _optimize_sequential(
     67             study,
     68             func,
     69             n_trials,
     70             timeout,
     71             catch,
     72             callbacks,
     73             gc_after_trial,
     74             reseed_sampler_rng=False,
     75             time_start=None,
     76             progress_bar=progress_bar,
     77         )
     78     else:
     79         if show_progress_bar:

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/optuna/study/_optimize.py:163, in _optimize_sequential(study, func, n_trials, timeout, catch, callbacks, gc_after_trial, reseed_sampler_rng, time_start, progress_bar)
    160         break
    162 try:
--> 163     trial = _run_trial(study, func, catch)
    164 except Exception:
    165     raise

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/optuna/study/_optimize.py:264, in _run_trial(study, func, catch)
    261         assert False, "Should not reach."
    263 if state == TrialState.FAIL and func_err is not None and not isinstance(func_err, catch):
--> 264     raise func_err
    265 return trial

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/optuna/study/_optimize.py:213, in _run_trial(study, func, catch)
    210     thread.start()
    212 try:
--> 213     value_or_values = func(trial)
    214 except exceptions.TrialPruned as e:
    215     # TODO(mamu): Handle multi-objective cases.
    216     state = TrialState.PRUNED

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/hpo/hpo.py:259, in Objective.__call__(self, trial)
    256     self._update_stopper_callbacks(_stopper_kwargs, trial, metric=self.metric, result_tracker=result_tracker)
    258 try:
--> 259     result = pipeline(
    260         # 1. Dataset
    261         dataset=self.dataset,
    262         dataset_kwargs=self.dataset_kwargs,
    263         training=self.training,
    264         testing=self.testing,
    265         validation=self.validation,
    266         evaluation_entity_whitelist=self.evaluation_entity_whitelist,
    267         evaluation_relation_whitelist=self.evaluation_relation_whitelist,
    268         # 2. Model
    269         model=self.model,
    270         model_kwargs=_model_kwargs,
    271         # 3. Loss
    272         loss=self.loss,
    273         loss_kwargs=_loss_kwargs,
    274         # 4. Regularizer
    275         regularizer=self.regularizer,
    276         regularizer_kwargs=_regularizer_kwargs,
    277         # 5. Optimizer
    278         optimizer=self.optimizer,
    279         optimizer_kwargs=_optimizer_kwargs,
    280         clear_optimizer=True,
    281         # 5.1 Learning Rate Scheduler
    282         lr_scheduler=self.lr_scheduler,
    283         lr_scheduler_kwargs=_lr_scheduler_kwargs,
    284         # 6. Training Loop
    285         training_loop=self.training_loop,
    286         negative_sampler=self.negative_sampler,
    287         negative_sampler_kwargs=_negative_sampler_kwargs,
    288         # 7. Training
    289         training_loop_kwargs=self.training_loop_kwargs,
    290         training_kwargs=_training_kwargs,
    291         stopper=self.stopper,
    292         stopper_kwargs=_stopper_kwargs,
    293         # 8. Evaluation
    294         evaluator=self.evaluator,
    295         evaluator_kwargs=self.evaluator_kwargs,
    296         evaluation_kwargs=self.evaluation_kwargs,
    297         filter_validation_when_testing=self.filter_validation_when_testing,
    298         # 9. Tracker
    299         result_tracker=result_tracker,
    300         result_tracker_kwargs=None,
    301         # Misc.
    302         use_testing_data=False,  # use validation set during HPO!
    303         device=self.device,
    304     )
    305 except (MemoryError, RuntimeError) as e:
    306     # close run in result tracker
    307     result_tracker.end_run(success=False)

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/pipeline/api.py:1133, in pipeline(dataset, dataset_kwargs, training, testing, validation, evaluation_entity_whitelist, evaluation_relation_whitelist, model, model_kwargs, interaction, interaction_kwargs, dimensions, loss, loss_kwargs, regularizer, regularizer_kwargs, optimizer, optimizer_kwargs, clear_optimizer, lr_scheduler, lr_scheduler_kwargs, training_loop, training_loop_kwargs, negative_sampler, negative_sampler_kwargs, epochs, training_kwargs, stopper, stopper_kwargs, evaluator, evaluator_kwargs, evaluation_kwargs, result_tracker, result_tracker_kwargs, metadata, device, random_seed, use_testing_data, evaluation_fallback, filter_validation_when_testing, use_tqdm)
   1129     model_instance = cast(Model, model)
   1130     # TODO should training be reset?
   1131     # TODO should kwargs for loss and regularizer be checked and raised for?
   1132 else:
-> 1133     model_instance, model_kwargs = _build_model_helper(
   1134         model=model,
   1135         model_kwargs=model_kwargs,
   1136         loss=loss,
   1137         loss_kwargs=loss_kwargs,
   1138         regularizer=regularizer,
   1139         regularizer_kwargs=regularizer_kwargs,
   1140         _device=_device,
   1141         _random_seed=_random_seed,
   1142         training_triples_factory=training,
   1143     )
   1145 model_instance = model_instance.to(_device)
   1147 # Log model parameters

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/pipeline/api.py:845, in _build_model_helper(model, model_kwargs, loss, loss_kwargs, _device, _random_seed, regularizer, regularizer_kwargs, training_triples_factory)
    841     for param_name, param_default in _get_model_defaults(model).items():
    842         model_kwargs.setdefault(param_name, param_default)
    844 return (
--> 845     model_resolver.make(
    846         model,
    847         triples_factory=training_triples_factory,
    848         **model_kwargs,
    849     ),
    850     model_kwargs,
    851 )

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/class_resolver/api.py:210, in ClassResolver.make(self, query, pos_kwargs, **kwargs)
    208         if any(text in e.args[0] for text in MISSING_ARGS):
    209             raise UnexpectedKeywordError(cls) from None
--> 210         raise e
    212 # An instance was passed, and it will go through without modification.
    213 return query

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/class_resolver/api.py:204, in ClassResolver.make(self, query, pos_kwargs, **kwargs)
    202 cls: Type[X] = self.lookup(query)
    203 try:
--> 204     return cls(**(pos_kwargs or {}), **kwargs)  # type: ignore
    205 except TypeError as e:
    206     if "required keyword-only argument" in e.args[0]:

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/models/base.py:819, in _add_post_reset_parameters.<locals>._new_init(self, *args, **kwargs)
    817 @functools.wraps(_original_init)
    818 def _new_init(self, *args, **kwargs):
--> 819     _original_init(self, *args, **kwargs)
    820     self.reset_parameters_()

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/models/unimodal/trans_e.py:81, in TransE.__init__(self, embedding_dim, scoring_fct_norm, entity_initializer, entity_constrainer, relation_initializer, relation_constrainer, **kwargs)
     54 def __init__(
     55     self,
     56     *,
   (...)
     63     **kwargs,
     64 ) -> None:
     65     r"""Initialize TransE.
     66 
     67     :param embedding_dim: The entity embedding dimension $d$. Is usually $d \in [50, 300]$.
   (...)
     79        - OpenKE `implementation of TransE <[https://github.com/thunlp/OpenKE/blob/OpenKE-PyTorch/models/TransE.py>`_](https://github.com/thunlp/OpenKE/blob/OpenKE-PyTorch/models/TransE.py%3E%60_%3C/span%3E)
     80     """
---> 81     super().__init__(
     82         entity_representations_kwargs=dict(
     83             shape=embedding_dim,
     84             initializer=entity_initializer,
     85             constrainer=entity_constrainer,
     86         ),
     87         relation_representations_kwargs=dict(
     88             shape=embedding_dim,
     89             initializer=relation_initializer,
     90             constrainer=relation_constrainer,
     91         ),
     92         **kwargs,
     93     )
     94     self.scoring_fct_norm = scoring_fct_norm

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/models/base.py:766, in EntityRelationEmbeddingModel.__init__(self, triples_factory, entity_representations, entity_representations_kwargs, relation_representations, relation_representations_kwargs, **kwargs)
    752 def __init__(
    753     self,
    754     *,
   (...)
    760     **kwargs,
    761 ) -> None:
    762     """Initialize the entity embedding model.
    763 
    764     .. seealso:: Constructor of the base class :class:`pykeen.models.Model`
    765     """
--> 766     super().__init__(triples_factory=triples_factory, **kwargs)
    767     self.entity_embeddings = build_representation(
    768         max_id=triples_factory.num_entities,
    769         representation=entity_representations,
    770         representation_kwargs=entity_representations_kwargs,
    771     )
    772     self.relation_embeddings = build_representation(
    773         max_id=triples_factory.num_relations,
    774         representation=relation_representations,
    775         representation_kwargs=relation_representations_kwargs,
    776     )

File /projects/aa/cpga/pkg/lib/python3.9/site-packages/pykeen/models/base.py:608, in _OldAbstractModel.__init__(self, triples_factory, regularizer, **kwargs)
    592 def __init__(
    593     self,
    594     *,
   (...)
    597     **kwargs,
    598 ) -> None:
    599     """Initialize the module.
    600 
    601     :param triples_factory:
   (...)
    606         additional keyword-based arguments passed to Model.__init__
    607     """
--> 608     super().__init__(triples_factory=triples_factory, **kwargs)
    609     # Regularizer
    610     if regularizer is not None:

TypeError: __init__() got an unexpected keyword argument 'automatic_memory_optimization'
```

### How to reproduce

This is the function I am trying to run
```python
from pykeen.hpo.hpo import hpo_pipeline
def run_optimization(dataset: Tuple[TriplesFactory, TriplesFactory, TriplesFactory], model_config: Dict, out_dir: str):
    """Run HPO."""
    training_factory, testing_factory, validation_factory = dataset

    # Define HPO pipeline
    hpo_results = hpo_pipeline(
        dataset=None,
        training=training_factory,
        testing=testing_factory,
        validation=validation_factory,
        model=model_config["model"],
        model_kwargs=model_config["model_kwargs"],
        model_kwargs_ranges=model_config["model_kwargs_ranges"],
        loss=model_config["loss_function"],
        loss_kwargs=model_config["loss_kwargs"],
        loss_kwargs_ranges=model_config["loss_kwargs_ranges"],
        regularizer=model_config["regularizer"],
        optimizer=model_config["optimizer"],
        optimizer_kwargs=model_config["optimizer_kwargs"],
        optimizer_kwargs_ranges=model_config["optimizer_kwargs_ranges"],
        training_loop=model_config["training_loop"],
        training_kwargs=model_config["training_kwargs"],
        training_kwargs_ranges=model_config["training_kwargs_ranges"],
        negative_sampler=model_config["negative_sampler"],
        negative_sampler_kwargs=model_config["negative_sampler_kwargs"],
        negative_sampler_kwargs_ranges=model_config["negative_sampler_kwargs_ranges"],
        stopper=model_config["stopper"],
        stopper_kwargs=model_config["stopper_kwargs"],
        evaluator=model_config["evaluator"],
        evaluator_kwargs=model_config["evaluator_kwargs"],
        evaluation_kwargs=model_config["evaluation_kwargs"],
        metric=model_config["metric"],
        direction=model_config["direction"],
        sampler=model_config["sampler"],
    )

    optimization_dir = os.path.join(out_dir, 'pykeen_results_optim')
    if not os.path.isdir(optimization_dir):
        os.makedirs(optimization_dir)

    hpo_results.save_to_directory(optimization_dir)

    return None
```
This is the model config:
```json
{
  "model": "TransE",
  "model_kwargs": {
    "automatic_memory_optimization": true
  },
  "model_kwargs_ranges": {
    "embedding_dim": {
      "type": "int",
      "low": 6,
      "high": 9,
      "scale": "power_two"
    }
  },
  "training_loop": "slcwa",
  "optimizer": "adam",
  "optimizer_kwargs": {
    "weight_decay": 0.0
  },
  "optimizer_kwargs_ranges": {
    "lr": {
      "type": "float",
      "low": 0.0001,
      "high": 1.0,
      "scale": "log"
    }
  },
  "loss_function": "NSSALoss",
  "loss_kwargs": {},
  "loss_kwargs_ranges": {
    "margin": {
      "type": "float",
      "low": 1,
      "high": 30,
      "q": 2.0
    },
    "adversarial_temperature": {
      "type": "float",
      "low": 0.1,
      "high": 1.0,
      "q": 0.1
    }
  },
  "regularizer": "NoRegularizer",
  "regularizer_kwargs": {},
  "regularizer_kwargs_ranges": {},
  "negative_sampler": "BasicNegativeSampler",
  "negative_sampler_kwargs": {},
  "negative_sampler_kwargs_ranges": {
    "num_negs_per_pos": {
      "type": "int",
      "low": 1,
      "high": 50,
      "q": 1
    }
  },
  "create_inverse_triples": false,
  "evaluator": "RankBasedEvaluator",
  "evaluator_kwargs": {
    "filtered": true
  },
  "evaluation_kwargs": {
    "batch_size": null
  },
  "training_kwargs": {
    "num_epochs": 1000,
    "label_smoothing": 0.0
  },
  "training_kwargs_ranges": {
    "batch_size": {
      "type": "int",
      "low": 8,
      "high": 11,
      "scale": "power_two"
    }
  },
  "stopper": "early",
  "stopper_kwargs": {
    "frequency": 25,
    "patience": 4,
    "delta": 0.002
  },
  "n_trials": 100,
  "timeout": 129600,
  "metric": "hits@10",
  "direction": "maximize",
  "sampler": "random",
  "pruner": "nop"
}
```

training, val and test are triple factory objects

### Environment

| Key             | Value                       |
|-----------------|-----------------------------|
| OS              | posix                       |
| Platform        | Linux                       |
| Release         | 3.10.0-1160.11.1.el7.x86_64 |
| Time            | Fri Jul 29 13:36:23 2022    |
| Python          | 3.9.12                      |
| PyKEEN          | 1.8.2                       |
| PyKEEN Hash     | UNHASHED                    |
| PyKEEN Branch   |                             |
| PyTorch         | 1.12.0+cu102                |
| CUDA Available? | true                        |
| CUDA Version    | 10.2                        |
| cuDNN Version   | 7605                        |

### Additional information

I am trying to train a TransE model and doing an optimization for the hyperparatmeters. 

### Issue Template Checks

- [X] This is not a feature request (use a different issue template if it is)
- [X] This is not a question (use the [discussions](https://github.com/pykeen/pykeen/discussions/new) forum instead)
- [X] I've read the text explaining why including environment information is important and understand if I omit this information that my issue will be dismissed

Hi @AmartyaCSB ,

since https://github.com/pykeen/pykeen/pull/176, the parameter `automatic_memory_optimization` is no longer a parameter for the model but rather for the training loop / evaluator.

Is this an issue that the documentation lead @AmartyaCSB to put this in the wrong place? Can we find where that was and fix it?

I searched for `"automatic_memory_optimization"` in the repo's file and could not find any wrong documentation thereof.