Run this model with HF Jobs

Run VisualInference/Molmo3-8B-MLX-8bit on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/VisualInference/Molmo3-8B-MLX-8bit. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/VisualInference/Molmo3-8B-MLX-8bit on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/VisualInference/Molmo3-8B-MLX-8bit. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
File size: 14,169 Bytes
6782e08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
"""Molmo3 configuration.

Field names follow the transformers-native Molmo3 config; configs written by older versions of
this repo (`vit_config`, `vit_layers`, ...) still load. Only the architecture of the Molmo3 4B
and 8B stage-2 checkpoints is supported: settings it fixes are checked here and hard-coded in the model.
"""
from typing import Optional

from transformers import PretrainedConfig


def _rename(kwargs: dict, old: str, new: str):
    """Move a legacy key to its current name."""
    if old in kwargs:
        value = kwargs.pop(old)
        kwargs.setdefault(new, value)


def _require(name: str, value, expected):
    if value != expected:
        raise ValueError(f"{name}={value!r} is not supported (only {expected!r})")


class Molmo3VisionConfig(PretrainedConfig):
    """SigLIP2 vision encoder, truncated after the deepest layer the adapter reads."""
    model_type = "molmo3_vision"
    base_config_key = "vision_config"

    def __init__(
        self,
        hidden_size: int = 1152,
        intermediate_size: int = 4304,
        num_hidden_layers: int = 25,
        num_attention_heads: int = 16,
        num_key_value_heads: Optional[int] = None,
        head_dim: int = 72,
        hidden_act: str = "gelu_pytorch_tanh",
        layer_norm_eps: float = 1e-6,
        image_size=(378, 378),
        patch_size: int = 14,
        num_channels: int = 3,
        num_position_embeddings: Optional[int] = None,
        attention_bias: bool = True,
        attention_dropout: float = 0.0,
        initializer_range: float = 0.02,
        **kwargs,
    ):
        kwargs.pop("model_type", None)
        super().__init__(**kwargs)
        self.hidden_size = hidden_size
        self.intermediate_size = intermediate_size
        self.num_hidden_layers = num_hidden_layers
        self.num_attention_heads = num_attention_heads
        self.num_key_value_heads = num_key_value_heads or num_attention_heads
        self.head_dim = head_dim
        self.hidden_act = hidden_act
        self.layer_norm_eps = layer_norm_eps
        self.image_size = [image_size, image_size] if isinstance(image_size, int) else list(image_size)
        self.patch_size = patch_size
        self.num_channels = num_channels
        self.num_position_embeddings = num_position_embeddings or self.grid_size ** 2
        self.attention_bias = attention_bias
        self.attention_dropout = attention_dropout
        self.initializer_range = initializer_range
        _require("vision_config.image_size", self.image_size[0], self.image_size[1])
        _require("vision_config.num_position_embeddings", self.num_position_embeddings, self.grid_size ** 2)
        _require("vision_config.num_key_value_heads", self.num_key_value_heads, num_attention_heads)
        _require("vision_config.num_channels", num_channels, 3)
        _require("vision_config.attention_bias", attention_bias, True)

    @property
    def grid_size(self) -> int:
        return self.image_size[0] // self.patch_size


class Molmo3AdapterConfig(PretrainedConfig):
    """Attention pooling + MLP projector that maps ViT features to LLM tokens."""
    model_type = "molmo3_adapter"
    base_config_key = "adapter_config"

    def __init__(
        self,
        vision_feature_layer: tuple = (24, 18),
        hidden_size: Optional[int] = None,
        num_attention_heads: int = 16,
        num_key_value_heads: Optional[int] = None,
        head_dim: int = 72,
        intermediate_size: int = 9728,
        hidden_act: str = "silu",
        num_pooling_positions: int = 9,
        text_hidden_size: int = 2560,
        attention_bias: bool = True,
        mlp_bias: bool = False,
        attention_dropout: float = 0.0,
        initializer_range: float = 0.02,
        **kwargs,
    ):
        kwargs.pop("model_type", None)
        _rename(kwargs, "max_pooling_size", "num_pooling_positions")
        num_pooling_positions = kwargs.pop("num_pooling_positions", num_pooling_positions)
        # Legacy `vit_layers` may be negative; Molmo3Config makes them absolute
        vision_feature_layer = kwargs.pop("vit_layers", vision_feature_layer)
        super().__init__(**kwargs)
        self.vision_feature_layer = list(vision_feature_layer)
        self.hidden_size = hidden_size or num_attention_heads * head_dim
        self.num_attention_heads = num_attention_heads
        self.num_key_value_heads = num_key_value_heads or num_attention_heads
        self.head_dim = head_dim
        self.intermediate_size = intermediate_size
        self.hidden_act = hidden_act
        # Rows of the learned per-slot bias over the pooling window (3x3 video pooling)
        self.num_pooling_positions = num_pooling_positions
        self.text_hidden_size = text_hidden_size
        self.attention_bias = attention_bias
        self.mlp_bias = mlp_bias
        self.attention_dropout = attention_dropout
        self.initializer_range = initializer_range
        _require("adapter_config.hidden_size", self.hidden_size, num_attention_heads * head_dim)
        _require("adapter_config.num_key_value_heads", self.num_key_value_heads, num_attention_heads)
        _require("adapter_config.attention_bias", attention_bias, True)
        _require("adapter_config.mlp_bias", mlp_bias, False)


class Molmo3TextConfig(PretrainedConfig):
    """Qwen3-style decoder.

    `vocab_size` counts every embedding row; the last `additional_vocab_size` rows (the special
    tokens) are stored as a separate `new_embedding` weight.
    """
    additional_vocab_size = 128
    model_type = "molmo3_text"
    base_config_key = "text_config"
    keys_to_ignore_at_inference = ["past_key_values"]

    def __init__(
        self,
        hidden_size: int = 2560,
        num_attention_heads: int = 32,
        num_key_value_heads: int = 8,
        head_dim: int = 128,
        vocab_size: int = 152064,
        num_hidden_layers: int = 36,
        intermediate_size: int = 9728,
        hidden_act: str = "silu",
        max_position_embeddings: int = 16384,
        rope_parameters: Optional[dict] = None,
        rms_norm_eps: float = 1e-6,
        qk_norm_type: str = "qwen3",
        attention_bias: bool = False,
        attention_dropout: float = 0.0,
        initializer_range: float = 0.02,
        use_cache: bool = True,
        **kwargs,
    ):
        kwargs.pop("model_type", None)
        kwargs.pop("tie_word_embeddings", None)
        _rename(kwargs, "layer_norm_eps", "rms_norm_eps")
        rms_norm_eps = kwargs.pop("rms_norm_eps", rms_norm_eps)
        _require("text_config.additional_vocab_size", kwargs.pop("additional_vocab_size", 128), 128)
        legacy_theta = kwargs.pop("rope_theta", None)
        if rope_parameters is None:
            rope_parameters = {"rope_theta": legacy_theta or 5000000.0, "rope_type": "default"}
        super().__init__(tie_word_embeddings=False, **kwargs)
        self.hidden_size = hidden_size
        self.num_attention_heads = num_attention_heads
        self.num_key_value_heads = num_key_value_heads
        self.head_dim = head_dim
        self.vocab_size = vocab_size
        self.num_hidden_layers = num_hidden_layers
        self.intermediate_size = intermediate_size
        self.hidden_act = hidden_act
        self.max_position_embeddings = max_position_embeddings
        self.rope_parameters = dict(rope_parameters)
        self.rms_norm_eps = rms_norm_eps
        self.qk_norm_type = qk_norm_type
        self.attention_bias = attention_bias
        self.attention_dropout = attention_dropout
        self.initializer_range = initializer_range
        self.use_cache = use_cache
        _require("text_config.rope_type", self.rope_parameters.get("rope_type", "default"), "default")
        _require("text_config.qk_norm_type", qk_norm_type, "qwen3")
        _require("text_config.attention_bias", attention_bias, False)

    @property
    def rope_theta(self) -> float:
        return self.rope_parameters["rope_theta"]

    @rope_theta.setter
    def rope_theta(self, value: float):
        # vLLM assigns it while normalizing rope settings
        self.rope_parameters["rope_theta"] = value

    @property
    def base_vocab_size(self) -> int:
        return self.vocab_size - self.additional_vocab_size


class Molmo3Config(PretrainedConfig):
    model_type = "molmo3"
    sub_configs = {
        "text_config": Molmo3TextConfig,
        "vision_config": Molmo3VisionConfig,
        "adapter_config": Molmo3AdapterConfig,
    }

    def __init__(
        self,
        vision_config=None,
        adapter_config=None,
        text_config=None,
        # Visual token ids
        image_patch_id: Optional[int] = None,
        image_low_res_id: Optional[int] = None,
        image_col_id: Optional[int] = None,
        image_start_token_id: Optional[int] = None,
        low_res_image_start_token_id: Optional[int] = None,
        image_end_token_id: Optional[int] = None,
        frame_start_token_id: Optional[int] = None,
        frame_end_token_id: Optional[int] = None,
        # Grounding token ids
        point_patch_id: Optional[int] = None,
        point_subpatch_id: Optional[int] = None,
        point_loc_id: Optional[int] = None,
        seg_mask_id: Optional[int] = None,
        center_patch_id: Optional[int] = None,
        corresponding_patch_id: Optional[int] = None,   # deprecated: never generated
        # Grounding head dimensions
        point_query_dims: tuple = (512, 512, 32),
        subpatch_location_size: int = 4,
        subpatch_hidden_size: int = 512,
        subpatch_conv_kernel: int = 3,
        patch_position_embedding_size: int = 512,
        mask_diffusion_steps: int = 2,
        pointer_rope_theta: float = 50000.0,
        # Ground only when the model's probability that anything is present exceeds this
        presence_threshold: float = 0.5,
        initializer_range: float = 0.02,
        **kwargs,
    ):
        kwargs.pop("tie_word_embeddings", None)
        use_cache = kwargs.pop("use_cache", True)
        _rename(kwargs, "patch_location", "subpatch_location_size")
        _rename(kwargs, "subpatch_hidden", "subpatch_hidden_size")
        subpatch_location_size = kwargs.pop("subpatch_location_size", subpatch_location_size)
        subpatch_hidden_size = kwargs.pop("subpatch_hidden_size", subpatch_hidden_size)
        legacy_vision = kwargs.pop("vit_config", None)
        if vision_config is None:
            vision_config = legacy_vision
        super().__init__(tie_word_embeddings=False, **kwargs)

        def build(cls, value):
            if value is None:
                return cls()
            return cls(**value) if isinstance(value, dict) else value

        legacy_text = isinstance(text_config, dict) and "rope_theta" in text_config
        self.vision_config = build(Molmo3VisionConfig, vision_config)
        self.adapter_config = build(Molmo3AdapterConfig, adapter_config)
        self.text_config = build(Molmo3TextConfig, text_config)

        if legacy_vision is not None:
            # Old configs list the full 27-layer ViT and index it from the end
            n = self.vision_config.num_hidden_layers
            layers = [l % n for l in self.adapter_config.vision_feature_layer]
            self.adapter_config.vision_feature_layer = layers
            self.vision_config.num_hidden_layers = max(layers) + 1
        if legacy_text:
            # Old configs counted `vocab_size` without the additional rows
            self.text_config.vocab_size += self.text_config.additional_vocab_size
        self.adapter_config.text_hidden_size = self.text_config.hidden_size

        self.image_patch_id = image_patch_id
        self.image_low_res_id = image_low_res_id
        self.image_col_id = image_col_id
        self.image_start_token_id = image_start_token_id
        self.low_res_image_start_token_id = low_res_image_start_token_id
        self.image_end_token_id = image_end_token_id
        self.frame_start_token_id = frame_start_token_id
        self.frame_end_token_id = frame_end_token_id

        self.point_patch_id = point_patch_id
        self.point_subpatch_id = point_subpatch_id
        self.point_loc_id = point_loc_id
        self.seg_mask_id = seg_mask_id
        self.center_patch_id = center_patch_id
        self.corresponding_patch_id = corresponding_patch_id

        self.point_query_dims = list(point_query_dims)
        self.subpatch_location_size = subpatch_location_size
        self.subpatch_hidden_size = subpatch_hidden_size
        self.subpatch_conv_kernel = subpatch_conv_kernel
        self.patch_position_embedding_size = patch_position_embedding_size
        self.mask_diffusion_steps = mask_diffusion_steps
        self.pointer_rope_theta = pointer_rope_theta
        self.presence_threshold = presence_threshold
        self.initializer_range = initializer_range
        self.use_cache = use_cache
        _require("patch_position_embedding_size", patch_position_embedding_size, 512)
        if max(self.adapter_config.vision_feature_layer) >= self.vision_config.num_hidden_layers:
            raise ValueError(f"vision_feature_layer {self.adapter_config.vision_feature_layer} is past "
                             f"the {self.vision_config.num_hidden_layers} ViT layers")

    @property
    def vision_token_ids(self) -> list:
        """Tokens that attend bidirectionally within a contiguous run."""
        return [self.image_patch_id, self.image_low_res_id, self.image_col_id,
                self.image_start_token_id, self.low_res_image_start_token_id,
                self.image_end_token_id, self.frame_start_token_id, self.frame_end_token_id]

    @property
    def grounding_token_ids(self) -> list:
        return [self.point_patch_id, self.point_subpatch_id, self.point_loc_id,
                self.seg_mask_id, self.center_patch_id]

    @property
    def vocab_size(self) -> int:
        return self.text_config.vocab_size

    @property
    def hidden_size(self) -> int:
        return self.text_config.hidden_size

    @property
    def num_hidden_layers(self) -> int:
        return self.text_config.num_hidden_layers


__all__ = ["Molmo3Config", "Molmo3VisionConfig", "Molmo3AdapterConfig", "Molmo3TextConfig"]