          logger.debug("Launched %s plugin", phase)
  
      def _set_extractor_batchsize(self):
          """
          Sets the batch size of the requested plugins based on their vram and
          vram_per_batch_requirements if the the configured batch size requires more
          vram than is available. Nvidia only.
          """
          if get_backend() != "nvidia":
              logger.debug("Backend is not Nvidia. Not updating batchsize requirements")
              return
          if sum([plugin.vram for plugin in self._all_plugins]) == 0:
 
</s> remove         if sum([plugin.vram for plugin in self._all_plugins]) == 0:
 </s> add         if sum([plugin.vram for plugin in self._active_plugins]) == 0: </s> remove         if plugin.vram_per_batch != 0:
            plugin.batchsize = int(max(1, available_vram // plugin.vram_per_batch))
            logger.verbose("Reset batchsize for %s to %s", plugin.name, plugin.batchsize)
 </s> add         plugins = [self._active_plugins[idx]
                   for idx, plugin in enumerate(self._current_phase)
                   if plugin in gpu_plugins]
        vram_per_batch = [plugin.vram_per_batch for plugin in plugins]
        ratios = [vram / sum(vram_per_batch) for vram in vram_per_batch]
        requested_batchsizes = [plugin.batchsize for plugin in plugins]
        batchsizes = [min(requested, max(1, int((available_vram * ratio) / plugin.vram_per_batch)))
                      for ratio, plugin, requested in zip(ratios, plugins, requested_batchsizes)]
        remaining = available_vram - sum(batchsize * plugin.vram_per_batch
                                         for batchsize, plugin in zip(batchsizes, plugins))
        sorted_indices = [i[0] for i in sorted(enumerate(plugins),
                                               key=lambda x: x[1].vram_per_batch, reverse=True)]

        logger.debug("requested_batchsizes: %s, batchsizes: %s, remaining vram: %s",
                     requested_batchsizes, batchsizes, remaining)

        while remaining > min(plugin.vram_per_batch
                              for plugin in plugins) and requested_batchsizes != batchsizes:
            for idx in sorted_indices:
                plugin = plugins[idx]
                if plugin.vram_per_batch > remaining:
                    logger.debug("Not enough VRAM to increase batch size of %s. Required: %sMB, "
                                 "Available: %sMB", plugin, plugin.vram_per_batch, remaining)
                    continue
                if plugin.batchsize == batchsizes[idx]:
                    logger.debug("Threshold reached for %s. Batch size: %s",
                                 plugin, plugin.batchsize)
                    continue
                logger.debug("Incrementing batch size of %s to %s", plugin, batchsizes[idx] + 1)
                batchsizes[idx] += 1
                remaining -= plugin.vram_per_batch
                logger.debug("Remaining VRAM to allocate: %sMB", remaining)

        if batchsizes != requested_batchsizes:
            text = ", ".join(["{}: {}".format(plugin.__class__.__name__, batchsize)
                              for plugin, batchsize in zip(plugins, batchsizes)])
            for plugin, batchsize in zip(plugins, batchsizes):
                plugin.batchsize = batchsize
            logger.info("Reset batch sizes due to available VRAM: %s", text) </s> remove     @staticmethod
    def _set_plugin_batchsize(plugin, available_vram):
 </s> add     def _set_plugin_batchsize(self, gpu_plugins, available_vram): </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) </s> remove         retval = self._is_parallel or self.phase == self._final_phase
 </s> add         retval = self._phase_index == len(self._phases) - 1
        Sets the batch size of the requested plugins based on their vram, their
        vram_per_batch_requirements and the number of plugins being loaded in the current phase.
        Only adjusts if the the configured batch size requires more vram than is available. Nvidia
        only.
          logger.debug("Launched %s plugin", phase)
  
      def _set_extractor_batchsize(self):
          """
        Sets the batch size of the requested plugins based on their vram, their
        vram_per_batch_requirements and the number of plugins being loaded in the current phase.
        Only adjusts if the the configured batch size requires more vram than is available. Nvidia
        only.
        Sets the batch size of the requested plugins based on their vram, their
        vram_per_batch_requirements and the number of plugins being loaded in the current phase.
        Only adjusts if the the configured batch size requires more vram than is available. Nvidia
        only.
        Sets the batch size of the requested plugins based on their vram, their
        vram_per_batch_requirements and the number of plugins being loaded in the current phase.
        Only adjusts if the the configured batch size requires more vram than is available. Nvidia
        only.
          """
          if get_backend() != "nvidia":
              logger.debug("Backend is not Nvidia. Not updating batchsize requirements")
              return
          if sum([plugin.vram for plugin in self._all_plugins]) == 0:
keep keep keep keep replace replace replace keep keep keep keep keep
 Extract - Better VRAM Allocation in Extraction Pipeline 
plugins/extract/pipeline.py