MostLime commited on
Commit
de7d56b
·
verified ·
1 Parent(s): 029807d

Upload base_mid

Browse files
README.md CHANGED
@@ -26,7 +26,7 @@ datasets:
26
 
27
  # loopmm base
28
 
29
- > **Early checkpoint.** These weights come from step 500 of 8,869 (0.5B of the 9.3B tokens) of the training run, so they are still weak. The final weights will replace them when the run ends, around 10:30 UTC on 23 November 2026.
30
 
31
  loopmm is a small language model that takes images and text as input. It has 189M parameters. Its 12 middle layers run three times for each token. It was trained from scratch on 9.3B tokens of text and image-text data.
32
 
@@ -72,11 +72,22 @@ Image-text data:
72
 
73
  ## Results
74
 
75
- The full evals come with the final weights. At step 500, the validation loss is 3.993 on Ultra-FineWeb text (8,192 tokens). On 8 DOCCI image descriptions it is 3.161 with the image and 3.234 without it. So the model already uses the image a little.
76
 
77
  ## Loop count
78
 
79
- The model was trained with 3 passes through the core, but it can run with any number. At step 500, the text loss is 4.046 at 1 loop, 3.995 at 2 loops, 3.993 at 3 loops, 3.992 at 4 loops, 3.992 at 6 loops. So one pass costs about 0.05 in loss, and passes beyond 3 change nothing yet. This section will be updated with the final weights.
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  ![Validation loss at each loop count](assets/loops.png)
82
 
@@ -121,18 +132,18 @@ print(model.complete(tok, "The best way to learn a new language is", max_new_tok
121
 
122
  `model(input_ids)` returns logits for every position. Generation goes through `complete()` and `generate_from()`, which keep a cache, so each new token costs one step. `transformers`' own `generate()` is not supported. Put token id 1 (`<|startoftext|>`) before your text; `complete()` does this for you.
123
 
124
- The release code gives the same logits as the training code (largest difference 1e-5 in fp32, at 1, 2, 3, 4 and 6 loops).
125
 
126
  ### ONNX
127
 
128
- `onnx/` holds four graphs with int8 weights. The Space and the Mac app use them with onnxruntime-web.
129
 
130
  - `stem.onnx`: image patches to embeddings
131
  - `prelude.onnx`: layers 0 to 5
132
  - `core.onnx`: layers 6 to 17. Run it once per loop, and keep a separate cache for each loop.
133
  - `coda.onnx`: layers 18 to 23 and the output head
134
 
135
- `onnx/meta.json` lists the inputs of each graph. The `engine.js` file of the Space shows how to call them. int8 costs little quality. On validation text, the loss goes from 4.629 (fp32) to 4.637 (int8). The four files take 241 MB.
136
 
137
  ## Limitations
138
 
@@ -156,4 +167,4 @@ The release code gives the same logits as the training code (largest difference
156
  - `config.json`: model settings
157
  - `modeling_loopmm.py`: model code (plain PyTorch, plus a transformers wrapper)
158
  - `tokenizer.json`, `tokenizer_config.json`, `special_tokens_map.json`: the LFM2-VL tokenizer, unchanged, from [LiquidAI/LFM2-VL-450M](https://huggingface.co/LiquidAI/LFM2-VL-450M)
159
- - `onnx/`: int8 ONNX graphs and `meta.json`
 
26
 
27
  # loopmm base
28
 
29
+ > **Mid-training checkpoint.** These weights come from step 5,000 of 8,869 (5.2B of the 9.3B tokens) of the training run. The final weights will replace them when the run ends, around 10:30 UTC on 23 November 2026.
30
 
31
  loopmm is a small language model that takes images and text as input. It has 189M parameters. Its 12 middle layers run three times for each token. It was trained from scratch on 9.3B tokens of text and image-text data.
32
 
 
72
 
73
  ## Results
74
 
75
+ Validation loss at step 5,000 (3 loops): 2.896 on Ultra-FineWeb text. On DOCCI image descriptions it is 2.662 with the image and 2.804 without it, so the model uses the image. Benchmark results will be added here later today.
76
 
77
  ## Loop count
78
 
79
+ The model was trained with 3 passes through the core, but it can run with any number. The table shows the validation loss at step 5,000 at each loop count. Text is 8,192 tokens of Ultra-FineWeb; captions are 8 DOCCI image descriptions, scored with and without their image.
80
+
81
+ | loops | text | caption | caption, no image |
82
+ |---|---|---|---|
83
+ | 1 | 3.439 | 2.915 | 3.051 |
84
+ | 2 | 3.170 | 2.802 | 2.931 |
85
+ | 3 | 2.896 | 2.662 | 2.804 |
86
+ | 4 | 2.953 | 2.695 | 2.837 |
87
+ | 5 | 2.943 | 2.698 | 2.845 |
88
+ | 6 | 2.964 | 2.700 | 2.850 |
89
+
90
+ One pass costs 0.543 in text loss compared with 3. More passes than 3 make it worse (2.953 at 4 loops, 2.964 at 6). In the playground and the Mac app, the Loops slider sets this number.
91
 
92
  ![Validation loss at each loop count](assets/loops.png)
93
 
 
132
 
133
  `model(input_ids)` returns logits for every position. Generation goes through `complete()` and `generate_from()`, which keep a cache, so each new token costs one step. `transformers`' own `generate()` is not supported. Put token id 1 (`<|startoftext|>`) before your text; `complete()` does this for you.
134
 
135
+ The release code gives the same logits as the training code (largest difference 3e-05 in fp32, at 1, 2, 3, 4 and 6 loops).
136
 
137
  ### ONNX
138
 
139
+ `onnx/` holds four graphs with fp16 weights. The Space and the Mac app run them with onnxruntime-web.
140
 
141
  - `stem.onnx`: image patches to embeddings
142
  - `prelude.onnx`: layers 0 to 5
143
  - `core.onnx`: layers 6 to 17. Run it once per loop, and keep a separate cache for each loop.
144
  - `coda.onnx`: layers 18 to 23 and the output head
145
 
146
+ `onnx/meta.json` lists the inputs of each graph. The `engine.js` file of the Space shows how to call them. The weights are stored in fp16 and computed in fp32, so the ONNX graphs give the same results as PyTorch: on validation text the loss is 3.8118 with ONNX and 3.8118 with PyTorch. The four files take 467 MB. Dynamic int8 quantization was tried first; on some checkpoints it raised the loss by up to 0.17, so it is not used.
147
 
148
  ## Limitations
149
 
 
167
  - `config.json`: model settings
168
  - `modeling_loopmm.py`: model code (plain PyTorch, plus a transformers wrapper)
169
  - `tokenizer.json`, `tokenizer_config.json`, `special_tokens_map.json`: the LFM2-VL tokenizer, unchanged, from [LiquidAI/LFM2-VL-450M](https://huggingface.co/LiquidAI/LFM2-VL-450M)
170
+ - `onnx/`: ONNX graphs (fp16 weights) and `meta.json`
assets/loops.png CHANGED
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:adbefb9df36cb6660e43ffb69e863cfca24f4ff186700505f3a0c3504183ee69
3
  size 754789964
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e094ca6d85180d014534cff56263bfd84927009ab1cfffb95338119ee4ae56fc
3
  size 754789964
modeling_loopmm.py CHANGED
@@ -494,16 +494,35 @@ class _LoopMMBody:
494
  kw.setdefault('stop_ids', (BOS, EOS))
495
  return self._decode(tok, self.generate_from(self.build_inputs(pieces), **kw))
496
 
497
- def chat(self, tok, messages, **kw):
498
- """messages: [{'role': 'user', 'content': 'text', 'images': [PIL or path, ...]}, ...] (images optional, they
499
- go before the text of their message). Uses the ChatML-style template of the chat model."""
 
 
 
 
 
 
 
 
500
  pieces = [[BOS]]
501
- for m in messages:
502
  pieces.append(self._encode(tok, f"<|im_start|>{m['role']}\n"))
503
  pieces += list(m.get('images') or [])
504
  pieces.append(self._encode(tok, f"{m['content']}<|im_end|>\n"))
505
- pieces.append(self._encode(tok, '<|im_start|>assistant\n'))
506
- return self._decode(tok, self.generate_from(self.build_inputs(pieces), **kw))
 
 
 
 
 
 
 
 
 
 
 
507
 
508
 
509
  class LoopMM(nn.Module, _LoopMMBody):
 
494
  kw.setdefault('stop_ids', (BOS, EOS))
495
  return self._decode(tok, self.generate_from(self.build_inputs(pieces), **kw))
496
 
497
+ def chat(self, tok, messages, thinking=True, max_image_tokens=576, **kw):
498
+ """messages: [{'role': 'user', 'content': 'text', 'images': [PIL or path, ...]}, ...] (images optional; they
499
+ go right after the role line, before the text). ChatML format of the chat model. The reply starts with a
500
+ <think> block; thinking=False asks for an empty one (system prompt "Thinking: off"). Returns the reply text,
501
+ think block included (split it with split_thinking)."""
502
+ msgs = list(messages)
503
+ if not thinking:
504
+ if msgs and msgs[0]['role'] == 'system':
505
+ msgs[0] = dict(msgs[0], content=msgs[0]['content'] + '\nThinking: off')
506
+ else:
507
+ msgs = [{'role': 'system', 'content': 'Thinking: off'}] + msgs
508
  pieces = [[BOS]]
509
+ for m in msgs:
510
  pieces.append(self._encode(tok, f"<|im_start|>{m['role']}\n"))
511
  pieces += list(m.get('images') or [])
512
  pieces.append(self._encode(tok, f"{m['content']}<|im_end|>\n"))
513
+ prefill = '' if thinking else '<think>\n</think>\n\n'
514
+ pieces.append(self._encode(tok, '<|im_start|>assistant\n' + prefill))
515
+ kw.setdefault('temperature', 0.2)
516
+ out = self.generate_from(self.build_inputs(pieces, max_image_tokens), **kw)
517
+ return prefill + self._decode(tok, out)
518
+
519
+
520
+ def split_thinking(reply):
521
+ """'<think>\n...\n</think>\n\nanswer' -> (thinking, answer)."""
522
+ if '<think>' in reply and '</think>' in reply:
523
+ a, b = reply.split('</think>', 1)
524
+ return a.split('<think>', 1)[1].strip(), b.strip()
525
+ return '', reply.strip()
526
 
527
 
528
  class LoopMM(nn.Module, _LoopMMBody):
onnx/coda.onnx CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:822e4461b6aba693197707a90e206124b0259e6d68292e2d38e1bf3d1493c0f1
3
- size 79105998
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99621f2e8e7c247d2ff0aba54b8d70c4cd97d1d2e461e7fb0dba099f0cff9b47
3
+ size 156196840
onnx/core.onnx CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6d8a0191a9c3b244e65b9ad6331b5f8cd3eb2f0c58e5046b3b33ff73d0de4c14
3
- size 73614870
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a8b463c6a776dd596d42531d447967a2857b384bd19be4fe8aa5ff2b5ba2d141
3
+ size 144792550
onnx/meta.json CHANGED
@@ -69,9 +69,9 @@
69
  }
70
  },
71
  "file_bytes": {
72
- "prelude": 79203055,
73
- "core": 73614870,
74
- "coda": 79105998,
75
  "stem": 8865118
76
  }
77
  }
 
69
  }
70
  },
71
  "file_bytes": {
72
+ "prelude": 157345160,
73
+ "core": 144792550,
74
+ "coda": 156196840,
75
  "stem": 8865118
76
  }
77
  }
onnx/prelude.onnx CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9d4e6b150ee4a252185b7bafe306a2b4ae851cced42a75bf4d3c399940a4c12a
3
- size 79203055
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e54f2bec501e72f304d3f125bca70369d929c5f72ff9a61022266f8f1125c28
3
+ size 157345160
onnx/stem.onnx CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:eff1bcc7b170ba19182c5dd32b076f709541573c8547df9a71c8d7267e407162
3
  size 8865118
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:546b4a31d6b717b8da30ad049e0a9d54f13f07c050b42607b7a86b99078e821a
3
  size 8865118