class_docstr: Multi-stage pipeline model architectures to inherit from.
  
  This model template is intended for models that train in distinct stages, with a different
  optimizer optimizing each step. This allows model components to be optimized with a set
  order in mind, rather than all at once, such as with the ``BasePipeline``.
  
  Generally, multi-stage models will have a training protocol like:
  
  .. code-block:: python
  
      from collie.model import CollieTrainer, SomeMultiStageModel
  
  
      model = SomeMultiStageModel(train=train)
      trainer = CollieTrainer(model)
  
      # fit stage 1
      trainer.fit(model)
  
      # fit stage 2
      trainer.max_epochs += 10
      model.advance_stage()
      trainer.fit(model)
  
      # fit stage 3
      trainer.max_epochs += 10
      model.advance_stage()
      trainer.fit(model)
  
      # ... and so on, until...
  
      model.eval()
  
  Just like with ``BasePipeline``, all subclasses MUST at least override the following methods:
  
  * ``_setup_model`` - Set up the model architecture
  
  * ``forward`` - Forward pass through a model
  
  For ``item_item_similarity`` to work properly, all subclasses are should also implement:
  
  * ``_get_item_embeddings`` - Returns item embeddings from the model
  
  Notes
  -----
  * With each call of ``trainer.fit``, the optimizer and learning rate scheduler state will reset.
  * When loading a multi-stage model in, the state will be set to the last possible state. This
    state may have a different ``forward`` calculation than other states.
  
  Parameters
  ----------
  optimizer_config_list: list of dict
      List of dictionaries containing the optimizer configurations for each stage's
      optimizer(s). Each dictionary must contain the following keys:
  
      * ``lr``: str
          Learning rate for the optimizer
  
      * ``optimizer``: ``torch.optim`` or ``str``
  
      * ``parameter_prefix_list``: List[str]
          List of string prefixes corressponding to the model components that should be
          optimized with this optimizer
  
      * ``stage``: str
          Name of stage
  
      This must be ordered with the intended progression of stages.
class_docstr_tok: ["Multi-stage","pipeline","model","architectures","to","inherit","from",".","This","model","template","is","intended","for","models","that","train","in","distinct","stages",",","with","a","different","optimizer","optimizing","each","step",".","This","allows","model","components","to","be","optimized","with","a","set","order","in","mind",",","rather","than","all","at","once",",","such","as","with","the","``","BasePipeline","``",".","Generally",",","multi-stage","models","will","have","a","training","protocol","like",":","..","code-block",":",":","python","from","collie.model","import","CollieTrainer",",","SomeMultiStageModel","model","=","SomeMultiStageModel","(","train=train",")","trainer","=","CollieTrainer","(","model",")","#","fit","stage","1","trainer.fit","(","model",")","#","fit","stage","2","trainer.max_epochs","+=","10","model.advance_stage","(",")","trainer.fit","(","model",")","#","fit","stage","3","trainer.max_epochs","+=","10","model.advance_stage","(",")","trainer.fit","(","model",")","#","...","and","so","on",",","until","...","model.eval","(",")","Just","like","with","``","BasePipeline","``",",","all","subclasses","MUST","at","least","override","the","following","methods",":","*","``","_setup_model","``","-","Set","up","the","model","architecture","*","``","forward","``","-","Forward","pass","through","a","model","For","``","item_item_similarity","``","to","work","properly",",","all","subclasses","are","should","also","implement",":","*","``","_get_item_embeddings","``","-","Returns","item","embeddings","from","the","model","Notes","--","--","-","*","With","each","call","of","``","trainer.fit","``",",","the","optimizer","and","learning","rate","scheduler","state","will","reset",".","*","When","loading","a","multi-stage","model","in",",","the","state","will","be","set","to","the","last","possible","state",".","This","state","may","have","a","different","``","forward","``","calculation","than","other","states",".","Parameters","--","--","--","--","--","optimizer_config_list",":","list","of","dict","List","of","dictionaries","containing","the","optimizer","configurations","for","each","stage's","optimizer","(","s",")",".","Each","dictionary","must","contain","the","following","keys",":","*","``","lr","``",":","str","Learning","rate","for","the","optimizer","*","``","optimizer","``",":","``","torch.optim","``","or","``","str","``","*","``","parameter_prefix_list","``",":","List","[","str","]","List","of","string","prefixes","corressponding","to","the","model","components","that","should","be","optimized","with","this","optimizer","*","``","stage","``",":","str","Name","of","stage","This","must","be","ordered","with","the","intended","progression","of","stages","."]
code: def __init__(
      self,
      train: INTERACTIONS_LIKE_INPUT = None,
      val: INTERACTIONS_LIKE_INPUT = None,
      lr_scheduler_func: Optional[
          torch.optim.lr_scheduler._LRScheduler
      ] = None,
      weight_decay: float = 0.0,
      optimizer_config_list: List[
          Dict[str, Union[float, List[str], str]]
      ] = None,
      loss: Union[str, Callable[..., torch.tensor]] = "hinge",
      metadata_for_loss: Optional[Dict[str, torch.tensor]] = None,
      metadata_for_loss_weights: Optional[Dict[str, float]] = None,
      load_model_path: Optional[str] = None,
      map_location: Optional[str] = None,
      **kwargs,
  ):
      stage_list = None
  
      if load_model_path is None:
          if optimizer_config_list is None:
              raise ValueError(
                  "Must provide ``optimizer_config_list`` when initializing a new multi-stage "
                  "model!"
              )
          else:
              stage_list = list(
                  OrderedDict.fromkeys(
                      [
                          optimizer_config["stage"]
                          for optimizer_config in optimizer_config_list
                      ]
                  )
              )
  
      super().__init__(stage_list=stage_list, **get_init_arguments())
  
      if load_model_path is None:
          # set stage if we have not already loaded it in and set it there
          self.hparams.stage = self.hparams.stage_list[0]
          self.set_stage(self.hparams.stage)
  
file_path: collie/collie/model/base/multi_stage_pipeline.py
imports: from abc import ABCMeta
  from collections import OrderedDict
  from functools import reduce
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
  from collie.interactions import ApproximateNegativeSamplingInteractionsDataLoader, Interactions, InteractionsDataLoader
  from collie.model.base import BasePipeline
  from collie.utils import get_init_arguments, merge_docstrings
label_desc: Use image node_id 1 to create a new MultiStagePipeline object from inherited base classes: BasePipeline with example: obj = MultiStagePipeline(train, val, lr_scheduler_func, weight_decay, optimizer_config_list, loss, metadata_for_loss, metadata_for_loss_weights, load_model_path, map_location)