PotionUI Docs v0.3.0

Driving native-engine generation directly

Most pipes just assemble existing pipes into a pipeline. A pipe that needs to run inference against the native (in-process) engine itself — VAE-encode a reference image, sample, decode — rather than only consuming other pipes' outputs, does that through src.plugin_api.native (src/pipelines/pipes/generator/krea2_edit/ is the in-tree example — a generator that in-context edits a source image rather than generating from scratch).

GeneratorKrea2Pipe is the concrete core Krea-2 generator pipe. Subclass it (as generator/krea2_edit does) to reuse its config schema and the shared seed-loop/model-acquisition machinery (build_context/process) instead of re-deriving Krea-2's own defaults — override generate_one for whatever your pipe does differently:

python
from src.plugin_api import (
    Conditioning, GeneratorContext, GeneratorKrea2Pipe,
    NativeGeneratorHandle, ProgressEmitter, native_step_hooks,
)

class MyEditPipe(GeneratorKrea2Pipe):
    def generate_one(self, ctx: GeneratorContext, index: int, seed: int, progress: ProgressEmitter):
        gen: NativeGeneratorHandle = ctx.extra["generator"]  # already constructed for you
        latent = gen.sample(Conditioning(cond=..., uncond=...), gen.latent_shape_for(w, h),
                             steps=..., seed=seed, cfg_scale=..., hooks=native_step_hooks(gen, progress, ...))
        pixels = gen.decode(latent)
        ...

NativeGeneratorHandle is a narrow, structural view of the real (large, fast-moving, mostly-private) NativeGenerator class — only encode_image, sample, decode and latent_shape_for, the operations a generator pipe's generate_one actually calls. A real generator instance (handed to you pre-built via ctx.extra["generator"]) satisfies it structurally; there is no wrapper object and no runtime cost. You never construct a generator yourself, and you should never call anything on gen beyond this surface — everything else (device placement, VRAM streaming, quantization, ...) is exactly the kind of internal that src.plugin_api exists to keep you out of. If your pipe genuinely needs another NativeGenerator operation, that is a gap in this surface — ask for it, the same as any other plugin_api gap.