RockTalk commited on
Commit
7a16a1c
·
verified ·
1 Parent(s): 464f74a

Initial MLX port of Lance 3B (image variant) + Wan 2.2 VAE

Browse files
README.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model:
4
+ - bytedance-research/Lance
5
+ - Qwen/Qwen2.5-VL-3B-Instruct
6
+ pipeline_tag: any-to-any
7
+ library_name: mlx
8
+ tags:
9
+ - multimodal
10
+ - mlx
11
+ - apple-silicon
12
+ - image-generation
13
+ - video-generation
14
+ - image-editing
15
+ - video-understanding
16
+ - any-to-any
17
+ - port
18
+ ---
19
+
20
+ # Lance-3B-MLX
21
+
22
+ A native [MLX](https://github.com/ml-explore/mlx) port of [ByteDance's Lance](https://huggingface.co/bytedance-research/Lance) — a 3B-parameter unified multimodal model for image and video generation, editing, and understanding.
23
+
24
+ Built on top of the Qwen2.5-VL-3B-Instruct backbone, with Lance's custom multi-task adapters and a Wan 2.2 VAE.
25
+
26
+ ## Status
27
+
28
+ This is a **work-in-progress port** focused on parity with the original PyTorch checkpoint:
29
+
30
+ | Component | Status |
31
+ |---|---|
32
+ | Weight conversion (PT → MLX safetensors, with conv layout + name remaps) | ✅ DONE |
33
+ | `modeling_utils` (TimestepEmbedder, PositionEmbedding3D, MLP, sincos tables) | ✅ DONE (5/5 unit tests pass) |
34
+ | `vae_wan22` — image-mode encode/decode | ✅ DONE |
35
+ | `vae_wan22` — video streaming feat-cache | ⏳ PENDING (image-only currently; short clips work via single-pass) |
36
+ | `lance.py` adapters (vae2llm, llm2vae, latent patching, time/pos embed) | ✅ DONE |
37
+ | Flow-matching sampler (`validation_gen` — T2I/T2V/edit) | ⏳ STUB — primitives wired, denoising loop + CFG porting in progress |
38
+ | X→T (understanding) autoregressive loop | ⏳ Phase 2 |
39
+ | NaViT variable-resolution image packing | ⏳ Phase 2 |
40
+
41
+ ## Files
42
+
43
+ - `model.safetensors` — Lance 3B image variant LLM + adapters (Qwen2.5-VL language model, vae2llm/llm2vae, time_embedder, latent_pos_embed), MLX-layout, **22.9 GB** (1021 tensors, ~6.19B params incl. embed table)
44
+ - `vit.safetensors` — Qwen2.5-VL ViT visual encoder, MLX-layout (NTHWC conv weights), **1.25 GB** (390 tensors, ~668M params, fp16 — bundled here for offline use; the source ships it as a separate shard)
45
+ - `vae.safetensors` — Wan 2.2 VAE, MLX-layout, **2.62 GB** (196 tensors, ~705M params). Converted from the upstream `Wan2.2_VAE.pth` pickle.
46
+ - `config.json` — distilled architecture config + embedded Qwen2.5-VL sub-config
47
+ - `vit_config.json` — Qwen2.5-VL ViT sub-config
48
+ - `tokenizer.json`, `tokenizer_config.json`, `vocab.json`, `merges.txt`, `generation_config.json` — copied verbatim from upstream
49
+
50
+ ## Hardware
51
+
52
+ Targets Apple Silicon with unified memory. Verified on M3 Ultra (512 GB). Lower-RAM Macs may need to run the LLM forward only (no joint backbone + VAE).
53
+
54
+ ## Loading
55
+
56
+ ```python
57
+ import mlx.core as mx
58
+ import mlx.nn as nn
59
+ from lance_mlx.lance import Lance, LanceConfig
60
+ from mlx_vlm.models.qwen2_5_vl.config import ModelConfig as Qwen25VLConfig
61
+ import json
62
+
63
+ cfg = json.load(open("config.json"))
64
+ qcfg = Qwen25VLConfig.from_dict(cfg["qwen2_5_vl_config"])
65
+ model = Lance(LanceConfig(qwen_config=qcfg, **{k: v for k, v in cfg.items() if k != "qwen2_5_vl_config"}))
66
+
67
+ # Bundle the three weight files (model + ViT + VAE).
68
+ weights = {}
69
+ for f in ("model.safetensors", "vit.safetensors", "vae.safetensors"):
70
+ weights.update(mx.load(f))
71
+ model.load_weights(list(weights.items()))
72
+ ```
73
+
74
+ ## Citation
75
+
76
+ ```bibtex
77
+ @article{lance2026,
78
+ title = {Lance: Unified Multimodal Modeling by Multi-Task Synergy},
79
+ author = {Fu, Fengyi and Huang, Mengqi and Wu, Shaojin and Jiang, Yunsheng and Huo, Yufei and Guo, Jianzhu and others},
80
+ journal = {arXiv preprint arXiv:2605.18678},
81
+ year = {2026},
82
+ url = {http://arxiv.org/abs/2605.18678}
83
+ }
84
+ ```
85
+
86
+ ## License
87
+
88
+ Apache-2.0, inherited from upstream `bytedance-research/Lance`.
89
+
90
+ ## Acknowledgments
91
+
92
+ - ByteDance Research for the original Lance training and PyTorch release
93
+ - The `mlx` and `mlx-vlm` teams at Apple
94
+ - Qwen team for Qwen2.5-VL-3B-Instruct
95
+
96
+ ---
97
+
98
+ **Port status reporting honestly:** this repo currently provides MLX-format weights with verified-loading scaffolding. Inference sampling (T2I/T2V) is a follow-up release; the building blocks are in place but the diffusion loop has not been parity-validated end-to-end yet. Pull requests welcome.
config.json ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "lance",
3
+ "variant": "image",
4
+ "license": "apache-2.0",
5
+ "source": "bytedance-research/Lance",
6
+ "mlx_port_version": "0.0.1",
7
+ "qwen2_5_vl_config": {
8
+ "architectures": [
9
+ "Qwen2_5_VLForConditionalGeneration"
10
+ ],
11
+ "attention_dropout": 0.0,
12
+ "bos_token_id": 151643,
13
+ "eos_token_id": 151645,
14
+ "vision_start_token_id": 151652,
15
+ "vision_end_token_id": 151653,
16
+ "vision_token_id": 151654,
17
+ "image_token_id": 151655,
18
+ "video_token_id": 151656,
19
+ "hidden_act": "silu",
20
+ "hidden_size": 2048,
21
+ "initializer_range": 0.02,
22
+ "intermediate_size": 11008,
23
+ "max_position_embeddings": 128000,
24
+ "max_window_layers": 70,
25
+ "model_type": "qwen2_5_vl",
26
+ "num_attention_heads": 16,
27
+ "num_hidden_layers": 36,
28
+ "num_key_value_heads": 2,
29
+ "rms_norm_eps": 1e-06,
30
+ "rope_theta": 1000000.0,
31
+ "sliding_window": 32768,
32
+ "tie_word_embeddings": true,
33
+ "torch_dtype": "bfloat16",
34
+ "transformers_version": "4.41.2",
35
+ "use_cache": true,
36
+ "use_sliding_window": false,
37
+ "vision_config": {
38
+ "depth": 32,
39
+ "hidden_act": "silu",
40
+ "hidden_size": 1280,
41
+ "intermediate_size": 3420,
42
+ "num_heads": 16,
43
+ "in_chans": 3,
44
+ "out_hidden_size": 2048,
45
+ "patch_size": 14,
46
+ "spatial_merge_size": 2,
47
+ "spatial_patch_size": 14,
48
+ "window_size": 112,
49
+ "fullatt_block_indexes": [
50
+ 7,
51
+ 15,
52
+ 23,
53
+ 31
54
+ ],
55
+ "tokens_per_second": 2,
56
+ "temporal_patch_size": 2
57
+ },
58
+ "rope_scaling": {
59
+ "type": "mrope",
60
+ "mrope_section": [
61
+ 16,
62
+ 24,
63
+ 24
64
+ ]
65
+ },
66
+ "vocab_size": 151936
67
+ },
68
+ "latent_patch_size": [
69
+ 1,
70
+ 2,
71
+ 2
72
+ ],
73
+ "max_latent_size": 32,
74
+ "max_num_frames": 25,
75
+ "latent_channel": 48,
76
+ "vae_downsample_spatial": 16,
77
+ "vae_downsample_temporal": 4,
78
+ "connector_act": "gelu_pytorch_tanh",
79
+ "timestep_shift": 3.5
80
+ }
generation_config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "pad_token_id": 151643,
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 151645,
7
+ 151643
8
+ ],
9
+ "repetition_penalty": 1.05,
10
+ "temperature": 0.000001,
11
+ "transformers_version": "4.49.0"
12
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ede2f0a376096d51004dad85705938abbfe3cedb64e212631527e76b9547817
3
+ size 24740958849
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "151643": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "151644": {
13
+ "content": "<|im_start|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "151645": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "151646": {
29
+ "content": "<|object_ref_start|>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "151647": {
37
+ "content": "<|object_ref_end|>",
38
+ "lstrip": false,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "151648": {
45
+ "content": "<|box_start|>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "151649": {
53
+ "content": "<|box_end|>",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ },
60
+ "151650": {
61
+ "content": "<|quad_start|>",
62
+ "lstrip": false,
63
+ "normalized": false,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": true
67
+ },
68
+ "151651": {
69
+ "content": "<|quad_end|>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": true
75
+ },
76
+ "151652": {
77
+ "content": "<|vision_start|>",
78
+ "lstrip": false,
79
+ "normalized": false,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": true
83
+ },
84
+ "151653": {
85
+ "content": "<|vision_end|>",
86
+ "lstrip": false,
87
+ "normalized": false,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": true
91
+ },
92
+ "151654": {
93
+ "content": "<|vision_pad|>",
94
+ "lstrip": false,
95
+ "normalized": false,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": true
99
+ },
100
+ "151655": {
101
+ "content": "<|image_pad|>",
102
+ "lstrip": false,
103
+ "normalized": false,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": true
107
+ },
108
+ "151656": {
109
+ "content": "<|video_pad|>",
110
+ "lstrip": false,
111
+ "normalized": false,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": true
115
+ },
116
+ "151657": {
117
+ "content": "<tool_call>",
118
+ "lstrip": false,
119
+ "normalized": false,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": false
123
+ },
124
+ "151658": {
125
+ "content": "</tool_call>",
126
+ "lstrip": false,
127
+ "normalized": false,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": false
131
+ },
132
+ "151659": {
133
+ "content": "<|fim_prefix|>",
134
+ "lstrip": false,
135
+ "normalized": false,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": false
139
+ },
140
+ "151660": {
141
+ "content": "<|fim_middle|>",
142
+ "lstrip": false,
143
+ "normalized": false,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": false
147
+ },
148
+ "151661": {
149
+ "content": "<|fim_suffix|>",
150
+ "lstrip": false,
151
+ "normalized": false,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": false
155
+ },
156
+ "151662": {
157
+ "content": "<|fim_pad|>",
158
+ "lstrip": false,
159
+ "normalized": false,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": false
163
+ },
164
+ "151663": {
165
+ "content": "<|repo_name|>",
166
+ "lstrip": false,
167
+ "normalized": false,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": false
171
+ },
172
+ "151664": {
173
+ "content": "<|file_sep|>",
174
+ "lstrip": false,
175
+ "normalized": false,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": false
179
+ }
180
+ },
181
+ "additional_special_tokens": [
182
+ "<|im_start|>",
183
+ "<|im_end|>",
184
+ "<|object_ref_start|>",
185
+ "<|object_ref_end|>",
186
+ "<|box_start|>",
187
+ "<|box_end|>",
188
+ "<|quad_start|>",
189
+ "<|quad_end|>",
190
+ "<|vision_start|>",
191
+ "<|vision_end|>",
192
+ "<|vision_pad|>",
193
+ "<|image_pad|>",
194
+ "<|video_pad|>"
195
+ ],
196
+ "bos_token": null,
197
+ "chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n{% endif %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}<|im_end|>\n{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>\n{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}",
198
+ "clean_up_tokenization_spaces": false,
199
+ "eos_token": "<|im_end|>",
200
+ "errors": "replace",
201
+ "model_max_length": 131072,
202
+ "pad_token": "<|endoftext|>",
203
+ "split_special_tokens": false,
204
+ "tokenizer_class": "Qwen2Tokenizer",
205
+ "unk_token": null,
206
+ "add_bos_token": false
207
+ }
vae.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c2674b01dce2c027fa33fd1a212f858d65d7d2a99b9559363d8e1d35629faf37
3
+ size 2818780182
vocab.json ADDED
The diff for this file is too large to render. See raw diff