| 9 | |
| 10 | |
| 11 | class SpaceTime(nn.Module): |
| 12 | def __init__(self, |
| 13 | embedding_config: dict, |
| 14 | encoder_config: dict, |
| 15 | decoder_config: dict, |
| 16 | output_config: dict, |
| 17 | inference_only: bool=False, |
| 18 | lag: int=1, |
| 19 | horizon: int=1): |
| 20 | super().__init__() |
| 21 | |
| 22 | self.embedding_config = embedding_config |
| 23 | self.encoder_config = encoder_config |
| 24 | self.decoder_config = decoder_config |
| 25 | self.output_config = output_config |
| 26 | |
| 27 | self.inference_only = inference_only |
| 28 | self.lag = lag |
| 29 | self.horizon = horizon |
| 30 | |
| 31 | self.init_weights(embedding_config, encoder_config, |
| 32 | decoder_config, output_config) |
| 33 | |
| 34 | # ----------------- |
| 35 | # Initialize things |
| 36 | # ----------------- |
| 37 | def init_weights(self, |
| 38 | embedding_config: dict, |
| 39 | encoder_config: dict, |
| 40 | decoder_config: dict, |
| 41 | output_config: dict): |
| 42 | self.embedding = self.init_embedding(embedding_config) |
| 43 | self.encoder = self.init_encoder(encoder_config) |
| 44 | self.decoder = self.init_decoder(decoder_config) |
| 45 | self.output = self.init_output(output_config) |
| 46 | |
| 47 | def init_embedding(self, config): |
| 48 | return init_embedding(config) |
| 49 | |
| 50 | def init_encoder(self, config): |
| 51 | self.encoder = Encoder(config) |
| 52 | # Allow access to first encoder SSM kernel_dim |
| 53 | self.kernel_dim = self.encoder.blocks[0].ssm.kernel_dim |
| 54 | return self.encoder |
| 55 | |
| 56 | def init_decoder(self, config): |
| 57 | self.decoder = Decoder(config) |
| 58 | self.decoder.blocks.ssm.lag = self.lag |
| 59 | self.decoder.blocks.ssm.horizon = self.horizon |
| 60 | return self.decoder |
| 61 | |
| 62 | def init_output(self, config): |
| 63 | return init_mlp(config) |
| 64 | |
| 65 | # ------------- |
| 66 | # Toggle things |
| 67 | # ------------- |
| 68 | def set_inference_only(self, mode=False): |