                   save_optimizer: Literal["never", "always", "exit"]) -> None:
          self._plugin = plugin
          self._is_predict = is_predict
          self._model_dir = model_dir
          self._history: List[List[float]] = [[], []]  # Loss histories per save iteration
          self._backup = Backup(self._model_dir, self._plugin.name)
  
      @property
      def _filename(self) -> str:
          """str: The filename for this model."""
 
</s> remove     def __init__(self, plugin: "ModelBase", model_dir: str, is_predict: bool) -> None:
 </s> add     def __init__(self,
                 plugin: "ModelBase",
                 model_dir: str,
                 is_predict: bool,
                 save_optimizer: Literal["never", "always", "exit"]) -> None: </s> remove     def save(self) -> None:
 </s> add     def save(self, is_exit: bool = False) -> None: </s> remove         keypress = KBHit(is_gui=self._args.redirect_gui)
        window_created = False
        err = False
        while True:
            try:
                if self._args.preview:
                    with self._lock:
                        for name, image in self._preview_buffer.items():
                            if not window_created:
                                self._create_resizable_window(name, image.shape)
                            cv2.imshow(name, image)  # pylint: disable=no-member
                        if not window_created:
                            window_created = bool(self._preview_buffer)
                    cv_key = cv2.waitKey(1000)  # pylint: disable=no-member
                else:
                    cv_key = None

                if thread.has_error:
                    logger.debug("Thread error detected")
                    err = True
                    break
                if self._stop:
                    logger.debug("Stop received")
                    break

                # Preview Monitor
                if not self._preview_monitor(cv_key):
                    break

                # Console Monitor
                if keypress.kbhit():
                    console_key = keypress.getch()
                    if console_key in ("\n", "\r"):
                        logger.debug("Exit requested")
                        break
                    if console_key in ("s", "S"):
                        logger.info("Save requested")
                        self._save_now = True

                # GUI Preview trigger update monitor
                self._process_gui_triggers()

                sleep(1)
            except KeyboardInterrupt:
                logger.debug("Keyboard Interrupt received")
                break
        keypress.set_normal_term()
        logger.debug("Closed Monitor")
        return err

 </s> add  </s> remove     def _preview_monitor(self, key_press):
 </s> add     def _do_preview(self, window_created: bool) -> bool:
        """" Display an image preview in a resizable window

        Parameters
        ----------
        window_created: bool
            ``True`` if a preview window has been created otherwise ``False``

        Returns
        -------
        bool
            ``True`` if a preview window has been created otherwise ``False``
        """
        with self._lock:
            for name, image in self._preview_buffer.items():
                if not window_created:
                    self._create_resizable_window(name, image.shape)
                cv2.imshow(name, image)  # pylint: disable=no-member
            window_created = bool(self._preview_buffer) if not window_created else window_created
        return window_created

    def _check_keypress(self, keypress: KBHit) -> bool:
        """ Check if a keypress has been detected.

        Parameters
        ----------
        keypress: :class:`lib.keypress.KBHit`
            The keypress monitor

        Returns
        -------
        bool
            ``True`` if an exit keypress has been detected otherwise ``False``
        """
        retval = False
        if keypress.kbhit():
            console_key = keypress.getch()
            if console_key in ("\n", "\r"):
                logger.debug("Exit requested")
                retval = True
            if console_key in ("s", "S"):
                logger.info("Save requested")
                self._save_now = True
        return retval

    def _preview_monitor(self, key_press: str) -> bool:
        self._save_optimizer = save_optimizer
                   save_optimizer: Literal["never", "always", "exit"]) -> None:
          self._plugin = plugin
          self._is_predict = is_predict
          self._model_dir = model_dir
        self._save_optimizer = save_optimizer
          self._history: List[List[float]] = [[], []]  # Loss histories per save iteration
          self._backup = Backup(self._model_dir, self._plugin.name)
  
      @property
      def _filename(self) -> str:
          """str: The filename for this model."""
keep keep keep add keep keep keep keep keep keep
 Training: Add setting option to save optimizer weights 
plugins/train/model/_base/io.py