Create # services/vince_server.py from common.config import load_config, create_object from pathlib import Path import gc, torch class VinceSingleton: def __init__(self, config_path: str, overrides: list[str]): self.config = load_config(config_path, overrides) self.gen = create_object(self.config) self.gen.configure_persistence() self.gen.configure_models() self.gen.configure_diffusion() def _set_steps(self, steps: int | None): if steps and hasattr(self.gen, "sampler") and hasattr(self.gen.sampler, "timesteps"): ts = self.gen.sampler.timesteps if hasattr(ts, "__len__") and len(ts) > 0: steps = min(int(steps), len(ts)) if steps < len(ts): idx = torch.linspace(0, len(ts) - 1, steps).round().long().tolist() self.gen.sampler.timesteps = [ts[i] for i in idx] def generate_multi_turn(self, image_path, turns, out_dir, *, steps=None, cfg_scale=None, aspect_ratio=None, resolution=None): g = self.gen.config.generation g.output.dir = str(out_dir) g.positive_prompt = {"image_path": [str(image_path)], "prompts": list(turns)} if cfg_scale is not None: g.cfg_scale = float(cfg_scale) if aspect_ratio is not None: g.aspect_ratio = str(aspect_ratio) if resolution is not None: g.resolution = int(resolution) self._set_steps(steps) self.gen.inference_loop() try: torch.cuda.synchronize() except Exception: pass gc.collect() try: torch.cuda.empty_cache() torch.cuda.memory.reset_peak_memory_stats() except Exception: pass return str(out_dir)
verified