File size: 3,122 Bytes
834d1cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import torch
from torch import nn

from typing import Optional

class QwenImageMAE(nn.Module):
    def __init__(
        self, 
    ):
        super().__init__()
        from transformers import ViTMAEConfig, ViTMAEModel
        
        config=ViTMAEConfig(**{
            "architectures": [
                "ViTMAEForPreTraining"
            ],
            "attention_probs_dropout_prob": 0.0,
            "decoder_hidden_size": 512,
            "decoder_intermediate_size": 2048,
            "decoder_num_attention_heads": 16,
            "decoder_num_hidden_layers": 8,
            "hidden_act": "gelu",
            "hidden_dropout_prob": 0.0,
            "hidden_size": 1024,
            "image_size": 224,
            "initializer_range": 0.02,
            "intermediate_size": 4096,
            "layer_norm_eps": 1e-12,
            "mask_ratio": 0.0,    
            "model_type": "vit_mae",
            "norm_pix_loss": False,
            "num_attention_heads": 16,
            "num_channels": 3,
            "num_hidden_layers": 24,
            "patch_size": 16,
            "qkv_bias": True,
            "torch_dtype": "bfloat16",
            "attn_implementation": "sdpa"
            }
            )
        
        self.model = ViTMAEModel(config)
        self.config=config


    def forward(self, pixel_values):
        outputs=self.model(pixel_values,interpolate_pos_encoding=True)
        return outputs.last_hidden_state
    
    def new_forward(self, pixel_values,sample1_shapes):
        outputs=self.model.new_forward(pixel_values,sample1_shapes,interpolate_pos_encoding=True)
        return outputs.last_hidden_state