          for phase in self._flow:
              plugin_type, idx = self._get_plugin_type_and_index(phase)
              attr = getattr(self, "_{}".format(plugin_type))
              attr = attr[idx] if idx is not None else attr
              vrams[phase] = attr.vram
          vram_required_count = sum(1 for p in vrams.values() if p > 0)
          logger.debug("VRAM requirements: %s. Plugins requiring VRAM: %s",
                       vrams, vram_required_count)
          retval = (sum(vrams.values()) *
                    self._parallel_scaling[vram_required_count]) + self._vram_buffer
 
</s> remove                   self._parallel_scaling[vram_required_count]) + self._vram_buffer
 </s> add                   self._parallel_scaling[vram_required_count]) </s> remove     def _total_vram_required(self):
        """ Return vram required for all phases plus the buffer """
        vrams = dict()
 </s> add     def _vram_per_phase(self):
        """ dict: The amount of vram required for each phase in :attr:`_flow`. """
        retval = dict() </s> remove             attr = getattr(self, "_{}".format(plugin_type))
 </s> add  </s> remove         if self.passes == 1:
            retval = self._all_plugins
        else:
            retval = [getattr(self, "_{}".format(self.phase))]
 </s> add         retval = []
        for phase in self._current_phase:
            plugin_type, idx = self._get_plugin_type_and_index(phase)
            attr = getattr(self, "_{}".format(plugin_type))
            retval.append(attr[idx] if idx is not None else attr) </s> remove         stats = GPUStats().get_card_most_free()
        vram_free = int(stats["free"])
        if self._is_parallel:
            batch_required = sum([plugin.vram_per_batch * plugin.batchsize
                                  for plugin in self._all_plugins])
            plugin_required = self._total_vram_required + batch_required
            if plugin_required <= vram_free:
                logger.debug("Plugin requirements within threshold: (plugin_required: %sMB, "
                             "vram_free: %sMB)", plugin_required, vram_free)
                return
            # Hacky split across plugins that use vram
            gpu_plugin_count = sum([1 for plugin in self._all_plugins if plugin.vram != 0])
            available_vram = (vram_free - self._total_vram_required) // gpu_plugin_count
            for plugin in self._all_plugins:
                if plugin.vram != 0:
                    self._set_plugin_batchsize(plugin, available_vram)
        else:
            for plugin in self._all_plugins:
                if plugin.vram == 0:
                    continue
                vram_required = plugin.vram + self._vram_buffer
                batch_required = plugin.vram_per_batch * plugin.batchsize
                plugin_required = vram_required + batch_required
                if plugin_required <= vram_free:
                    logger.debug("%s requirements within threshold: (plugin_required: %sMB, "
                                 "vram_free: %sMB)", plugin.name, plugin_required, vram_free)
                    continue
                available_vram = vram_free - vram_required
                self._set_plugin_batchsize(plugin, available_vram)
 </s> add         batch_required = sum([plugin.vram_per_batch * plugin.batchsize
                              for plugin in self._active_plugins])
        gpu_plugins = [p for p in self._current_phase if self._vram_per_phase[p] > 0]
        plugins_required = sum([self._vram_per_phase[p]
                                for p in gpu_plugins]) * self._parallel_scaling[len(gpu_plugins)]
        if plugins_required + batch_required <= self._vram_stats["vram_free"]:
            logger.debug("Plugin requirements within threshold: (plugins_required: %sMB, "
                         "vram_free: %sMB)", plugins_required, self._vram_stats["vram_free"])
            return
        # Hacky split across plugins that use vram
        available_vram = (self._vram_stats["vram_free"] - plugins_required) // len(gpu_plugins)
        self._set_plugin_batchsize(gpu_plugins, available_vram)
            retval[phase] = attr.vram
        logger.trace(retval)
        return retval

    @property
    def _total_vram_required(self):
        """ Return vram required for all phases plus the buffer """
        vrams = self._vram_per_phase
          for phase in self._flow:
              plugin_type, idx = self._get_plugin_type_and_index(phase)
              attr = getattr(self, "_{}".format(plugin_type))
              attr = attr[idx] if idx is not None else attr
            retval[phase] = attr.vram
        logger.trace(retval)
        return retval

    @property
    def _total_vram_required(self):
        """ Return vram required for all phases plus the buffer """
        vrams = self._vram_per_phase
          vram_required_count = sum(1 for p in vrams.values() if p > 0)
          logger.debug("VRAM requirements: %s. Plugins requiring VRAM: %s",
                       vrams, vram_required_count)
          retval = (sum(vrams.values()) *
                    self._parallel_scaling[vram_required_count]) + self._vram_buffer
keep keep keep keep replace keep keep keep keep keep
 Extract - Better VRAM Allocation in Extraction Pipeline 
plugins/extract/pipeline.py