feat(nodes): use LATENT_SCALE_FACTOR in primitives.py, noise.py

- LatentsOutput.build
- NoiseOutput.build
- Noise.width, Noise.height multiple_of
This commit is contained in:
psychedelicious 2024-02-11 08:54:01 +11:00
parent ba7b1b2665
commit 2005411f7e
2 changed files with 8 additions and 6 deletions

View File

@ -4,6 +4,7 @@
import torch import torch
from pydantic import field_validator from pydantic import field_validator
from invokeai.app.invocations.constants import LATENT_SCALE_FACTOR
from invokeai.app.invocations.fields import FieldDescriptions, InputField, LatentsField, OutputField from invokeai.app.invocations.fields import FieldDescriptions, InputField, LatentsField, OutputField
from invokeai.app.services.shared.invocation_context import InvocationContext from invokeai.app.services.shared.invocation_context import InvocationContext
from invokeai.app.util.misc import SEED_MAX from invokeai.app.util.misc import SEED_MAX
@ -70,8 +71,8 @@ class NoiseOutput(BaseInvocationOutput):
def build(cls, latents_name: str, latents: torch.Tensor, seed: int) -> "NoiseOutput": def build(cls, latents_name: str, latents: torch.Tensor, seed: int) -> "NoiseOutput":
return cls( return cls(
noise=LatentsField(latents_name=latents_name, seed=seed), noise=LatentsField(latents_name=latents_name, seed=seed),
width=latents.size()[3] * 8, width=latents.size()[3] * LATENT_SCALE_FACTOR,
height=latents.size()[2] * 8, height=latents.size()[2] * LATENT_SCALE_FACTOR,
) )
@ -93,13 +94,13 @@ class NoiseInvocation(BaseInvocation):
) )
width: int = InputField( width: int = InputField(
default=512, default=512,
multiple_of=8, multiple_of=LATENT_SCALE_FACTOR,
gt=0, gt=0,
description=FieldDescriptions.width, description=FieldDescriptions.width,
) )
height: int = InputField( height: int = InputField(
default=512, default=512,
multiple_of=8, multiple_of=LATENT_SCALE_FACTOR,
gt=0, gt=0,
description=FieldDescriptions.height, description=FieldDescriptions.height,
) )

View File

@ -4,6 +4,7 @@ from typing import Optional
import torch import torch
from invokeai.app.invocations.constants import LATENT_SCALE_FACTOR
from invokeai.app.invocations.fields import ( from invokeai.app.invocations.fields import (
ColorField, ColorField,
ConditioningField, ConditioningField,
@ -321,8 +322,8 @@ class LatentsOutput(BaseInvocationOutput):
def build(cls, latents_name: str, latents: torch.Tensor, seed: Optional[int] = None) -> "LatentsOutput": def build(cls, latents_name: str, latents: torch.Tensor, seed: Optional[int] = None) -> "LatentsOutput":
return cls( return cls(
latents=LatentsField(latents_name=latents_name, seed=seed), latents=LatentsField(latents_name=latents_name, seed=seed),
width=latents.size()[3] * 8, width=latents.size()[3] * LATENT_SCALE_FACTOR,
height=latents.size()[2] * 8, height=latents.size()[2] * LATENT_SCALE_FACTOR,
) )