Files
vnassets/vnassets/edit.py
Michele Rossi 97ac841518 Add VnAssetsSession for persistent model lifecycle
- Extract model loading from generate()/edit() into VnAssetsSession class
- Session eagerly loads SDXL + Qwen Image Edit at construction (28s, once)
- Both models held in GPU memory across calls; generate()/edit() reuse them
- generate.py and edit.py become thin wrappers (backwards compatible CLI)
- Context manager (with VnAssetsSession(...) as vna:) for library use
- Metadata backwards-compatible: all fields preserved including lora_load_s
- load_time_s now reflects total session construction, amortized across calls

- Add performance stats for edit path (Qwen Image Edit + Lightning LoRA)
- Benchmark matmul fallback (86.8s) vs flash attention (53.3s, 1.63x speedup)
- Session vs cold start comparison: 2 ops save one 28s load, 5 edits save 112s
- Flash attention via TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1 documented
2026-07-08 10:18:42 +02:00

32 lines
832 B
Python

"""Qwen Image Edit — image-to-image editing (standalone entry point).
For multi-call reuse, use VnAssetsSession directly.
"""
from .session import VnAssetsSession
def edit(
model_path: str,
input_path: str,
prompt: str,
steps: int = 20,
cfg: float = 4.0,
seed: int | None = None,
output_path: str = "output.png",
lora_path: str | None = None,
) -> None:
"""One-shot image edit. Loads model, runs inference, unloads.
For multiple edits, create a VnAssetsSession to keep the model
loaded between calls.
"""
with VnAssetsSession(edit_model=model_path, edit_lora=lora_path) as vna:
vna.edit(
input_path=input_path,
prompt=prompt,
steps=steps,
cfg=cfg,
seed=seed,
output_path=output_path,
)