AlexanderHall2000 commited on
Commit
173995b
·
verified ·
1 Parent(s): 461cf9b

Add inference.py, README.md, config.json, training_args.json, model.safetensors

Browse files
Files changed (5) hide show
  1. README.md +73 -0
  2. config.json +19 -0
  3. inference.py +53 -0
  4. model.safetensors +3 -0
  5. training_args.json +9 -0
README.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mpl-2.0
3
+ tags:
4
+ - pytorch
5
+ - hybrid
6
+ - classification
7
+ ---
8
+
9
+ # Hybrid for Classification
10
+
11
+ ## Overview
12
+
13
+ A small **Hybrid** implementation for **Classification**, packaged with an explicit configuration and an initialization checkpoint. The **base** variant is a reproducible starting point, not a trained model release.
14
+
15
+ ---
16
+
17
+ ## Quick check
18
+
19
+ Run `python inference.py --help` for the built-in smoke test. Because this is a custom implementation, generic automatic loading APIs require an explicit adapter before use.
20
+
21
+ ---
22
+
23
+ ## Limitations
24
+
25
+ The checkpoint is untrained and unaudited. Treat the repository as an experimental starting point; anything learned from a future trained version must be documented separately.
26
+
27
+ ---
28
+
29
+ ## Default experiment recipe
30
+
31
+ Defaults: **novograd** optimizer, **linear warmup** schedule. Treat these as starting points; a real run should sweep learning rate and batch size before drawing conclusions.
32
+
33
+ ---
34
+
35
+ ## Training details
36
+
37
+ * Weights initialized with a xavier uniform scheme.
38
+ * Runs on a single consumer GPU.
39
+ * Full smoke test takes minutes, not hours.
40
+ * No distributed setup required.
41
+
42
+ ---
43
+
44
+ ## Repository status
45
+
46
+ * Single-file implementation; the `__main__` block runs a smoke test.
47
+ * `config.json` and `training_args.json` hold the generated settings.
48
+ * `model.safetensors` is freshly initialized — plumbing, not results.
49
+ * No benchmark numbers are reported on purpose.
50
+
51
+ ---
52
+
53
+ ## Evaluation guidance
54
+
55
+ A first evaluation could use a task-specific labeled split. Report the metric across at least three seeds and include a matched-capacity baseline; keep logs and library versions with any published number.
56
+
57
+ ---
58
+
59
+ ## Files
60
+
61
+ | File | Purpose |
62
+ |---|---|
63
+ | `inference.py` | primary artifact |
64
+ | `README.md` | this documentation |
65
+ | `config.json` | architecture configuration |
66
+ | `training_args.json` | default experiment settings |
67
+ | `model.safetensors` | initialization checkpoint |
68
+
69
+ ---
70
+
71
+ ## License
72
+
73
+ Released under **mpl-2.0**. Review the source-data terms separately when this repository is used with external datasets.
config.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "CustomResearchModel"
4
+ ],
5
+ "architecture": "hybrid",
6
+ "model_type": "hybrid",
7
+ "hidden_size": 192,
8
+ "num_hidden_layers": 6,
9
+ "num_attention_heads": 6,
10
+ "intermediate_size": 768,
11
+ "hidden_act": "relu",
12
+ "max_position_embeddings": 256,
13
+ "layer_norm_eps": 1e-12,
14
+ "checkpoint_status": "initialization-only",
15
+ "notes": "Untrained checkpoint for smoke tests; no benchmark claim.",
16
+ "use_cache": true,
17
+ "torch_dtype": "float32",
18
+ "vocab_size": 2048
19
+ }
inference.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch, torch.nn as nn, math
2
+
3
+ class M(nn.Module):
4
+ def __init__(self, d=256, L=6, H=4, nc=10):
5
+ super().__init__()
6
+ self.pe = nn.Conv2d(3, d, 16, 16)
7
+ self.cls = nn.Parameter(torch.randn(1,1,d)*.02)
8
+ self.pos = nn.Parameter(torch.randn(1,197,d)*.02)
9
+ self.blks = nn.ModuleList([nn.TransformerEncoderLayer(d, H, d*4, .1, activation='gelu', batch_first=True, norm_first=True) for _ in range(L)])
10
+ self.ln = nn.LayerNorm(d)
11
+ self.te = nn.Embedding(30522, d, padding_idx=0)
12
+ self.tpos = nn.Parameter(torch.randn(1,128,d)*.02)
13
+ self.tblks = nn.ModuleList([nn.TransformerEncoderLayer(d, H, d*4, .1, activation='gelu', batch_first=True, norm_first=True) for _ in range(L)])
14
+ self.tln = nn.LayerNorm(d)
15
+ self.fuse = nn.ModuleList([nn.TransformerEncoderLayer(d, H, d*4, .1, activation='gelu', batch_first=True, norm_first=True) for _ in range(2)])
16
+ self.fln = nn.LayerNorm(d)
17
+ self.head = nn.Sequential(nn.Linear(d,d), nn.ReLU(), nn.Dropout(.1), nn.Linear(d,nc))
18
+ self._init()
19
+
20
+ def _init(self):
21
+ for m in self.modules():
22
+ if isinstance(m, nn.Linear):
23
+ nn.init.xavier_uniform_(m.weight)
24
+ if m.bias is not None: nn.init.zeros_(m.bias)
25
+
26
+ def enc_img(self, x):
27
+ x = self.pe(x).flatten(2).transpose(1,2)
28
+ x = torch.cat([self.cls.expand(x.size(0),-1,-1), x], 1)
29
+ x = x + self.pos
30
+ for b in self.blks: x = b(x)
31
+ return self.ln(x)
32
+
33
+ def enc_txt(self, ids, mask=None):
34
+ x = self.te(ids) + self.tpos[:, :ids.size(1)]
35
+ m = (mask == 0) if mask is not None else None
36
+ for b in self.tblks: x = b(x, src_key_padding_mask=m)
37
+ return self.tln(x)
38
+
39
+ def forward(self, img, ids, mask=None, lbl=None):
40
+ fi = self.enc_img(img)
41
+ ft = self.enc_txt(ids, mask)
42
+ x = ft
43
+ for f in self.fuse: x = f(x)
44
+ x = self.fln(x[:, 0])
45
+ logits = self.head(x)
46
+ loss = nn.functional.cross_entropy(logits, lbl) if lbl is not None else None
47
+ return {'logits': logits, 'loss': loss}
48
+
49
+ if __name__ == '__main__':
50
+ m = M()
51
+ print(f'Params: {sum(p.numel() for p in m.parameters()):,}')
52
+ o = m(torch.randn(2,3,224,224), torch.randint(0,30522,(2,128)), torch.ones(2,128), torch.tensor([0,1]))
53
+ print(o['logits'].shape, o['loss'].item())
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:140b1cce023b4378ee2f258373ad1d4564c8e6a52a2f67201daaa9067d49ecae
3
+ size 99800
training_args.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "optimizer": "novograd",
3
+ "scheduler": "linear_warmup",
4
+ "learning_rate": 0.0002,
5
+ "batch_size": 24,
6
+ "epochs": 20,
7
+ "seed": 3407,
8
+ "status": "default recipe; not a completed run"
9
+ }