This commit is contained in:
zcr
2026-03-17 11:28:52 +08:00
commit 59570f8812
45 changed files with 5308 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
from .base import Sampler
from .flow_euler import FlowEulerSampler, FlowEulerCfgSampler, FlowEulerGuidanceIntervalSampler

View File

@@ -0,0 +1,20 @@
from typing import *
from abc import ABC, abstractmethod
class Sampler(ABC):
"""
A base class for samplers.
"""
@abstractmethod
def sample(
self,
model,
**kwargs
):
"""
Sample from a model.
"""
pass

View File

@@ -0,0 +1,12 @@
from typing import *
class ClassifierFreeGuidanceSamplerMixin:
"""
A mixin class for samplers that apply classifier-free guidance.
"""
def _inference_model(self, model, x_t, t, cond, neg_cond, cfg_strength, **kwargs):
pred = super()._inference_model(model, x_t, t, cond, **kwargs)
neg_pred = super()._inference_model(model, x_t, t, neg_cond, **kwargs)
return (1 + cfg_strength) * pred - cfg_strength * neg_pred