File size: 1,000 Bytes
fe78f25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Minimal shims for the MagViT-v2 modules.

The upstream MagViT code (from MMaDA) subclasses diffusers' `ModelMixin` /
`ConfigMixin` and uses `@register_to_config`. For inference we only need
`nn.Module` behaviour plus a no-op config recorder, so we provide lightweight
replacements and avoid depending on diffusers' fast-moving internal loading
APIs. Weights are loaded directly from safetensors in `load_magvit.py`.
"""
import functools

import torch.nn as nn


class ConfigMixin:
    config_name = "config.json"


class ModelMixin(nn.Module):
    """Standin for diffusers.ModelMixin — just an nn.Module for inference."""

    def __init__(self, *args, **kwargs):
        super().__init__()


def register_to_config(init):
    """No-op replacement for diffusers' register_to_config decorator."""

    @functools.wraps(init)
    def inner(self, *args, **kwargs):
        if not hasattr(self, "config"):
            self.config = dict(kwargs)
        init(self, *args, **kwargs)

    return inner