File size: 717 Bytes
2577656
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import math

from diffusers.configuration_utils import ConfigMixin, register_to_config


class YuE2SemanticGuider(ConfigMixin):
    config_name = "guider_config.json"

    @register_to_config
    def __init__(self, scale=None):
        if scale is not None and (not math.isfinite(scale) or not 0 <= scale <= 20):
            raise ValueError("Semantic guidance must be finite and in [0,20]")

    def scale_for(self, cot):
        return (1.01 if cot == "off" else 1.0) if self.config.scale is None else self.config.scale

    def combine(self, conditional, unconditional, cot):
        scale = self.scale_for(cot)
        return conditional if scale == 1.0 else unconditional + scale * (conditional - unconditional)