Only does cross attention
| 105 | |
| 106 | |
| 107 | class SimplePerceiver(nn.Module): |
| 108 | """ |
| 109 | Only does cross attention |
| 110 | """ |
| 111 | |
| 112 | def __init__( |
| 113 | self, |
| 114 | *, |
| 115 | device: torch.device, |
| 116 | dtype: torch.dtype, |
| 117 | n_data: int, |
| 118 | width: int, |
| 119 | layers: int, |
| 120 | heads: int, |
| 121 | init_scale: float = 0.25, |
| 122 | data_width: Optional[int] = None, |
| 123 | ): |
| 124 | super().__init__() |
| 125 | self.width = width |
| 126 | self.layers = layers |
| 127 | init_scale = init_scale * math.sqrt(1.0 / width) |
| 128 | self.resblocks = nn.ModuleList( |
| 129 | [ |
| 130 | ResidualCrossAttentionBlock( |
| 131 | device=device, |
| 132 | dtype=dtype, |
| 133 | n_data=n_data, |
| 134 | width=width, |
| 135 | heads=heads, |
| 136 | init_scale=init_scale, |
| 137 | data_width=data_width, |
| 138 | ) |
| 139 | for _ in range(layers) |
| 140 | ] |
| 141 | ) |
| 142 | |
| 143 | def forward(self, x: torch.Tensor, data: torch.Tensor): |
| 144 | for block in self.resblocks: |
| 145 | x = block(x, data) |
| 146 | return x |