arthu1 commited on
Commit
bf71328
·
verified ·
1 Parent(s): e39abc8

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -101,6 +101,63 @@ response:
101
  Hi. What can I help you with?
102
  ```
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  ```text
105
  <|im_start|>user
106
  Write me a PyTorch training loop.<|im_end|>
 
101
  Hi. What can I help you with?
102
  ```
103
 
104
+ Full-script patch output:
105
+
106
+ ```text
107
+ <|im_start|>user
108
+ I need a whole pytorch training script, not just a loop<|im_end|>
109
+ <|im_start|>assistant
110
+
111
+ response:
112
+ import torch
113
+ import torch.nn as nn
114
+ from torch.utils.data import DataLoader, TensorDataset
115
+
116
+
117
+ class TinyNet(nn.Module):
118
+ def __init__(self, in_dim: int, hidden_dim: int, out_dim: int):
119
+ super().__init__()
120
+ self.net = nn.Sequential(
121
+ nn.Linear(in_dim, hidden_dim),
122
+ nn.ReLU(),
123
+ nn.Linear(hidden_dim, out_dim),
124
+ )
125
+
126
+ def forward(self, x):
127
+ return self.net(x)
128
+
129
+
130
+ def main():
131
+ device = "cuda" if torch.cuda.is_available() else "cpu"
132
+
133
+ x = torch.randn(1024, 10)
134
+ y = (x.sum(dim=1) > 0).long()
135
+ loader = DataLoader(TensorDataset(x, y), batch_size=32, shuffle=True)
136
+
137
+ model = TinyNet(10, 64, 2).to(device)
138
+ optimizer = torch.optim.AdamW(model.parameters(), lr=3e-4)
139
+ criterion = nn.CrossEntropyLoss()
140
+
141
+ model.train()
142
+ for epoch in range(5):
143
+ total_loss = 0.0
144
+ for xb, yb in loader:
145
+ xb, yb = xb.to(device), yb.to(device)
146
+ optimizer.zero_grad(set_to_none=True)
147
+ logits = model(xb)
148
+ loss = criterion(logits, yb)
149
+ loss.backward()
150
+ torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)
151
+ optimizer.step()
152
+ total_loss += loss.item()
153
+
154
+ print(f"epoch {epoch + 1}: loss={total_loss / len(loader):.4f}")
155
+
156
+
157
+ if __name__ == "__main__":
158
+ main()
159
+ ```
160
+
161
  ```text
162
  <|im_start|>user
163
  Write me a PyTorch training loop.<|im_end|>
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4b8b00ca9628b619c3a3fc7967b6c32641d2486572f3f4b684ddb77f3b4213d6
3
  size 1149472840
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6162933e3ab803c93c69c9691803f16b4ed8743aad21968156b4fbc3ba61134
3
  size 1149472840
vision_adapter/vision_adapter/README.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+ # Forge-1V Micro Vision Adapter Scaffold
6
+
7
+ This folder contains an experimental, untrained micro vision-adapter scaffold for future Forge-1V work.
8
+
9
+ It is intentionally separate from the main text checkpoint:
10
+
11
+ - The main `config.json` remains Llama-compatible.
12
+ - The GGUF export remains text-only.
13
+ - These files do not make the released model able to view images.
14
+
15
+ Suggested target design:
16
+
17
+ - Tiny patch encoder: 3-channel images to a small vision width.
18
+ - Projection: vision width to the 1024-dimensional Forge text hidden size.
19
+ - Prefix tokens: projected visual tokens can be prepended to the text sequence in a future custom multimodal training run.
20
+
21
+ Approximate extra parameters for the scaffold design are well under 1M, keeping the total system under 400M parameters.
vision_adapter/vision_adapter/config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_size": 224,
3
+ "patch_size": 16,
4
+ "vision_width": 128,
5
+ "text_hidden_size": 1024,
6
+ "num_prefix_tokens": 16,
7
+ "status": "experimental_untrained_scaffold"
8
+ }
vision_adapter/vision_adapter/forge_micro_vision.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+
3
+ import torch
4
+ import torch.nn as nn
5
+
6
+
7
+ @dataclass
8
+ class ForgeMicroVisionConfig:
9
+ image_size: int = 224
10
+ patch_size: int = 16
11
+ vision_width: int = 128
12
+ text_hidden_size: int = 1024
13
+ num_prefix_tokens: int = 16
14
+
15
+
16
+ class ForgeMicroVisionAdapter(nn.Module):
17
+ """Tiny untrained image-to-prefix adapter scaffold for Forge-1V experiments."""
18
+
19
+ def __init__(self, config: ForgeMicroVisionConfig = ForgeMicroVisionConfig()):
20
+ super().__init__()
21
+ self.config = config
22
+ self.patch_embed = nn.Conv2d(
23
+ 3,
24
+ config.vision_width,
25
+ kernel_size=config.patch_size,
26
+ stride=config.patch_size,
27
+ bias=False,
28
+ )
29
+ self.pool = nn.AdaptiveAvgPool1d(config.num_prefix_tokens)
30
+ self.norm = nn.LayerNorm(config.vision_width)
31
+ self.proj = nn.Linear(config.vision_width, config.text_hidden_size, bias=False)
32
+
33
+ def forward(self, images: torch.Tensor) -> torch.Tensor:
34
+ patches = self.patch_embed(images)
35
+ tokens = patches.flatten(2)
36
+ tokens = self.pool(tokens).transpose(1, 2)
37
+ tokens = self.norm(tokens)
38
+ return self.proj(tokens)