Safetensors
thales_quant
finance
fintech
sparse-autoencoders
xai
imbue2025 commited on
Commit
2955221
·
verified ·
1 Parent(s): f453e7f

Upload 3 files

Browse files
Files changed (3) hide show
  1. config.json +11 -0
  2. model.py +83 -0
  3. model.safetensors +3 -0
config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ThalesModel"
4
+ ],
5
+ "grid_size": 11,
6
+ "in_dim": 128,
7
+ "sae_dim": 1024,
8
+ "pricing_hidden": 256,
9
+ "model_type": "thales_quant",
10
+ "torch_dtype": "float32"
11
+ }
model.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import torch.nn.functional as F
4
+ from huggingface_hub import PyTorchModelHubMixin
5
+
6
+ class ResNetBlock(nn.Module):
7
+ def __init__(self, channels):
8
+ super().__init__()
9
+ self.conv1 = nn.Conv2d(channels, channels, 3, padding=1)
10
+ self.bn1 = nn.BatchNorm2d(channels)
11
+ self.conv2 = nn.Conv2d(channels, channels, 3, padding=1)
12
+ self.bn2 = nn.BatchNorm2d(channels)
13
+
14
+ def forward(self, x):
15
+ residual = x
16
+ x = F.relu(self.bn1(self.conv1(x)))
17
+ x = self.bn2(self.conv2(x))
18
+ x += residual
19
+ return F.relu(x)
20
+
21
+ class SAE(nn.Module):
22
+ def __init__(self, in_dim=128, sae_dim=1024):
23
+ super().__init__()
24
+ self.encoder = nn.Linear(in_dim, sae_dim)
25
+ self.decoder = nn.Linear(sae_dim, in_dim)
26
+
27
+ def forward(self, x):
28
+ f = F.relu(self.encoder(x))
29
+ recon = self.decoder(f)
30
+ return f, recon
31
+
32
+ class ThalesModel(nn.Module, PyTorchModelHubMixin):
33
+ def __init__(self, grid_size=11, in_dim=128, sae_dim=1024, pricing_hidden=256):
34
+ super().__init__()
35
+ self.config = {
36
+ "grid_size": grid_size,
37
+ "in_dim": in_dim,
38
+ "sae_dim": sae_dim,
39
+ "pricing_hidden": pricing_hidden
40
+ }
41
+
42
+ self.cnn = nn.Sequential(
43
+ nn.Conv2d(2, 32, kernel_size=3, padding=1),
44
+ nn.BatchNorm2d(32),
45
+ nn.ReLU(),
46
+ ResNetBlock(32),
47
+ nn.MaxPool2d(2),
48
+ ResNetBlock(32),
49
+ nn.Flatten(),
50
+ nn.Linear(32 * (grid_size // 2)**2, in_dim)
51
+ )
52
+ self.sae = SAE(in_dim=in_dim, sae_dim=sae_dim)
53
+
54
+ self.pricing_head = nn.Sequential(
55
+ nn.Linear(in_dim + 4, pricing_hidden),
56
+ nn.SiLU(),
57
+ nn.Linear(pricing_hidden, pricing_hidden // 2),
58
+ nn.SiLU(),
59
+ nn.Linear(pricing_hidden // 2, 1),
60
+ nn.Softplus()
61
+ )
62
+
63
+ def forward(self, surface, scalars, return_acts=False):
64
+ # Sobolev
65
+ if self.training:
66
+ scalars.requires_grad_(True)
67
+
68
+ cnn_out = self.cnn(surface)
69
+ sae_f, recon = self.sae(cnn_out)
70
+
71
+ scalars_norm = torch.stack([
72
+ scalars[:, 0] / 100.0, # S
73
+ scalars[:, 1] / 100.0, # K
74
+ scalars[:, 2], # T
75
+ scalars[:, 3] # r
76
+ ], dim=1)
77
+
78
+ concat_feat = torch.cat([recon, scalars_norm], dim=1)
79
+ price = self.pricing_head(concat_feat)
80
+
81
+ if return_acts:
82
+ return price, scalars, cnn_out, recon, sae_f
83
+ return price, scalars, cnn_out, recon
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:abf10c1a7fc37768d287296d047f5708a3737da21aa2a634962f847d24377498
3
+ size 1888348