CoolFace
Modelpublic

OzzyGT/YuE2-Modular

sourceHugging Faceapache-2.0updated 1d agoView on Hugging Face
2likes6downloads
guidance.py20 linesDownload Raw Back to root
1import math2 3from diffusers.configuration_utils import ConfigMixin, register_to_config4 5 6class YuE2SemanticGuider(ConfigMixin):7    config_name = "guider_config.json"8 9    @register_to_config10    def __init__(self, scale=None):11        if scale is not None and (not math.isfinite(scale) or not 0 <= scale <= 20):12            raise ValueError("Semantic guidance must be finite and in [0,20]")13 14    def scale_for(self, cot):15        return (1.01 if cot == "off" else 1.0) if self.config.scale is None else self.config.scale16 17    def combine(self, conditional, unconditional, cot):18        scale = self.scale_for(cot)19        return conditional if scale == 1.0 else unconditional + scale * (conditional - unconditional)20