patchfm 2.2.5__tar.gz → 3.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {patchfm-2.2.5/src/patchfm.egg-info → patchfm-3.0.0}/PKG-INFO +1 -1
- {patchfm-2.2.5 → patchfm-3.0.0}/pyproject.toml +1 -1
- {patchfm-2.2.5 → patchfm-3.0.0}/src/patchfm/configs/model_config.py +0 -1
- {patchfm-2.2.5 → patchfm-3.0.0}/src/patchfm/inference/forecaster.py +3 -9
- {patchfm-2.2.5 → patchfm-3.0.0}/src/patchfm/inference/modules.py +6 -16
- {patchfm-2.2.5 → patchfm-3.0.0/src/patchfm.egg-info}/PKG-INFO +1 -1
- {patchfm-2.2.5 → patchfm-3.0.0}/LICENSE +0 -0
- {patchfm-2.2.5 → patchfm-3.0.0}/README.md +0 -0
- {patchfm-2.2.5 → patchfm-3.0.0}/setup.cfg +0 -0
- {patchfm-2.2.5 → patchfm-3.0.0}/src/patchfm/__init__.py +0 -0
- {patchfm-2.2.5 → patchfm-3.0.0}/src/patchfm.egg-info/SOURCES.txt +0 -0
- {patchfm-2.2.5 → patchfm-3.0.0}/src/patchfm.egg-info/dependency_links.txt +0 -0
- {patchfm-2.2.5 → patchfm-3.0.0}/src/patchfm.egg-info/requires.txt +0 -0
- {patchfm-2.2.5 → patchfm-3.0.0}/src/patchfm.egg-info/top_level.txt +0 -0
|
@@ -18,17 +18,12 @@ class Forecaster(nn.Module):
|
|
|
18
18
|
self.d_model = config["d_model"]
|
|
19
19
|
self.n_heads = config["n_heads"]
|
|
20
20
|
self.n_layers_encoder = config["n_layers_encoder"]
|
|
21
|
-
self.use_xsa = config["use_xsa"]
|
|
22
21
|
self.quantiles = config["quantiles"]
|
|
23
22
|
self.n_quantiles = len(self.quantiles)
|
|
24
23
|
self.max_patches = self.max_seq_len // self.patch_len
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
base_model = PatchFM.from_pretrained("vilhess/PatchFM")
|
|
29
|
-
else:
|
|
30
|
-
print("Loading XSA model from HuggingFace Hub...")
|
|
31
|
-
base_model = PatchFM.from_pretrained("vilhess/PatchFM-XSA")
|
|
25
|
+
print("Loading base model from HuggingFace Hub...")
|
|
26
|
+
base_model = PatchFM.from_pretrained("vilhess/PatchFM")
|
|
32
27
|
|
|
33
28
|
self._init_from_base(base_model)
|
|
34
29
|
|
|
@@ -53,7 +48,6 @@ class Forecaster(nn.Module):
|
|
|
53
48
|
d_model=self.d_model,
|
|
54
49
|
n_heads=self.n_heads,
|
|
55
50
|
n_layers=self.n_layers_encoder,
|
|
56
|
-
use_xsa=self.use_xsa
|
|
57
51
|
)
|
|
58
52
|
self.proj_output = ResidualBlock(
|
|
59
53
|
in_dim=self.d_model,
|
|
@@ -167,7 +161,7 @@ class Forecaster(nn.Module):
|
|
|
167
161
|
bs, ws = x.size()
|
|
168
162
|
|
|
169
163
|
if flip_equivariance:
|
|
170
|
-
|
|
164
|
+
|
|
171
165
|
bs = context.size(0)
|
|
172
166
|
x_flipped = -x
|
|
173
167
|
concat_x = torch.cat([x, x_flipped], dim=0)
|
|
@@ -185,7 +185,7 @@ class ResidualBlock(nn.Module):
|
|
|
185
185
|
return out
|
|
186
186
|
|
|
187
187
|
class MultiHeadAttention(nn.Module):
|
|
188
|
-
def __init__(self, d_model, n_heads, last=False
|
|
188
|
+
def __init__(self, d_model, n_heads, last=False):
|
|
189
189
|
super().__init__()
|
|
190
190
|
assert d_model%n_heads==0, f"d_model ({d_model}) must be divisible by n_heads ({n_heads})"
|
|
191
191
|
|
|
@@ -204,7 +204,6 @@ class MultiHeadAttention(nn.Module):
|
|
|
204
204
|
self.v_cache = None
|
|
205
205
|
|
|
206
206
|
self.last = last
|
|
207
|
-
self.use_xsa = use_xsa
|
|
208
207
|
|
|
209
208
|
def forward(self, q):
|
|
210
209
|
bs, context, dim = q.size()
|
|
@@ -240,13 +239,6 @@ class MultiHeadAttention(nn.Module):
|
|
|
240
239
|
|
|
241
240
|
values = nn.functional.scaled_dot_product_attention(q, k, v, is_causal=is_causal)
|
|
242
241
|
|
|
243
|
-
if self.use_xsa:
|
|
244
|
-
if v.size(2) != values.size(2):
|
|
245
|
-
v = v[:, :, -values.size(2) :, :]
|
|
246
|
-
|
|
247
|
-
vn = torch.nn.functional.normalize(v, dim=-1)
|
|
248
|
-
values = values - (values * vn).sum(dim=-1, keepdim=True) * vn
|
|
249
|
-
|
|
250
242
|
values = values.transpose(1, 2).reshape(bs, -1, dim)
|
|
251
243
|
values = self.out_proj(values)
|
|
252
244
|
return values
|
|
@@ -275,10 +267,10 @@ class FeedForward(nn.Module):
|
|
|
275
267
|
|
|
276
268
|
|
|
277
269
|
class TransformerEncoderLayer(nn.Module):
|
|
278
|
-
def __init__(self, d_model, n_heads, last=False
|
|
270
|
+
def __init__(self, d_model, n_heads, last=False):
|
|
279
271
|
super().__init__()
|
|
280
272
|
self.ln1 = nn.LayerNorm(d_model)
|
|
281
|
-
self.attn = MultiHeadAttention(d_model=d_model, n_heads=n_heads, last=last
|
|
273
|
+
self.attn = MultiHeadAttention(d_model=d_model, n_heads=n_heads, last=last)
|
|
282
274
|
self.ln2 = nn.LayerNorm(d_model)
|
|
283
275
|
self.ff = FeedForward(d_model=d_model)
|
|
284
276
|
|
|
@@ -289,15 +281,15 @@ class TransformerEncoderLayer(nn.Module):
|
|
|
289
281
|
return out
|
|
290
282
|
|
|
291
283
|
class TransformerEncoder(nn.Module):
|
|
292
|
-
def __init__(self, d_model, n_heads, n_layers
|
|
284
|
+
def __init__(self, d_model, n_heads, n_layers):
|
|
293
285
|
super().__init__()
|
|
294
286
|
self.layers = nn.ModuleList(
|
|
295
287
|
[
|
|
296
|
-
TransformerEncoderLayer(d_model=d_model, n_heads=n_heads
|
|
288
|
+
TransformerEncoderLayer(d_model=d_model, n_heads=n_heads)
|
|
297
289
|
for _ in range(n_layers-1)
|
|
298
290
|
]
|
|
299
291
|
)
|
|
300
|
-
self.layers.append(TransformerEncoderLayer(d_model=d_model, n_heads=n_heads, last=True
|
|
292
|
+
self.layers.append(TransformerEncoderLayer(d_model=d_model, n_heads=n_heads, last=True))
|
|
301
293
|
self.norm = nn.LayerNorm(d_model)
|
|
302
294
|
|
|
303
295
|
def forward(self, x):
|
|
@@ -314,7 +306,6 @@ class PatchFM(nn.Module, PyTorchModelHubMixin):
|
|
|
314
306
|
self.d_model = config["d_model"]
|
|
315
307
|
self.n_heads = config["n_heads"]
|
|
316
308
|
self.n_layers_encoder = config["n_layers_encoder"]
|
|
317
|
-
self.use_xsa = config["use_xsa"]
|
|
318
309
|
self.quantiles = config["quantiles"]
|
|
319
310
|
self.n_quantiles = len(self.quantiles)
|
|
320
311
|
|
|
@@ -329,7 +320,6 @@ class PatchFM(nn.Module, PyTorchModelHubMixin):
|
|
|
329
320
|
d_model=self.d_model,
|
|
330
321
|
n_heads=self.n_heads,
|
|
331
322
|
n_layers=self.n_layers_encoder,
|
|
332
|
-
use_xsa=self.use_xsa
|
|
333
323
|
)
|
|
334
324
|
self.proj_output = ResidualBlock(
|
|
335
325
|
in_dim=self.d_model,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|