refiners/tests/adapters/test_range_adapter.py

26 lines
809 B
Python
Raw Permalink Normal View History

2023-08-04 13:28:41 +00:00
import torch
2023-09-01 14:50:41 +00:00
from refiners.fluxion.adapters.adapter import Adapter
2023-08-04 13:28:41 +00:00
from refiners.fluxion.layers import Chain, Linear
from refiners.foundationals.latent_diffusion.range_adapter import RangeEncoder
2023-08-04 13:28:41 +00:00
class DummyLinearAdapter(Chain, Adapter[Linear]):
def __init__(self, target: Linear):
with self.setup_adapter(target):
super().__init__(target)
def test_range_encoder_dtype_after_adaptation(test_device: torch.device): # FG-433
dtype = torch.float64
chain = Chain(RangeEncoder(320, 1280, device=test_device, dtype=dtype))
adaptee = chain.RangeEncoder.Linear_1
adapter = DummyLinearAdapter(adaptee).inject(chain.RangeEncoder)
2023-08-04 13:28:41 +00:00
assert adapter.parent == chain.RangeEncoder
x = torch.tensor([42], device=test_device)
y = chain(x)
assert y.dtype == dtype