luisrui commited on
Commit
56bf2c2
·
1 Parent(s): 50f569c

Add task-modality sanity filter: drop LLMs from image-gen / ASR / VQA results

Browse files
Files changed (2) hide show
  1. data/family2id.json +333 -0
  2. recommend.py +294 -0
data/family2id.json ADDED
@@ -0,0 +1,333 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "3ddfa": 0,
3
+ "aceinstruct": 1,
4
+ "acemath": 2,
5
+ "adaface": 3,
6
+ "aerialformer": 4,
7
+ "aimv2": 5,
8
+ "albef": 6,
9
+ "alphanet": 7,
10
+ "aot": 8,
11
+ "apollo": 9,
12
+ "aspire": 10,
13
+ "ast": 11,
14
+ "asymmnet": 12,
15
+ "atlas": 13,
16
+ "audioldm": 14,
17
+ "aura": 15,
18
+ "aurora": 16,
19
+ "autoformer": 17,
20
+ "aya": 18,
21
+ "baezel": 19,
22
+ "baichuan": 20,
23
+ "bart": 21,
24
+ "basic": 22,
25
+ "beats": 23,
26
+ "beit": 24,
27
+ "bellatrix": 25,
28
+ "bert": 26,
29
+ "bielik": 27,
30
+ "bit": 28,
31
+ "blip": 29,
32
+ "bloom": 30,
33
+ "blossom": 31,
34
+ "branch": 32,
35
+ "caformer": 33,
36
+ "cait": 34,
37
+ "calcium": 35,
38
+ "calme": 36,
39
+ "camelidae": 37,
40
+ "captain": 38,
41
+ "chatwaifu": 39,
42
+ "chinchilla": 40,
43
+ "chocolatine": 41,
44
+ "clarus": 42,
45
+ "claude": 43,
46
+ "cleverboi": 44,
47
+ "clip": 45,
48
+ "cloformer": 46,
49
+ "cmx": 47,
50
+ "cnn": 48,
51
+ "code": 49,
52
+ "codellama": 50,
53
+ "cohere": 51,
54
+ "command": 52,
55
+ "conformer": 53,
56
+ "conv": 54,
57
+ "convnext": 55,
58
+ "crisscross": 56,
59
+ "cswin": 57,
60
+ "cursa": 58,
61
+ "cvt": 59,
62
+ "cybernet": 60,
63
+ "dall": 61,
64
+ "damomath": 62,
65
+ "dans": 63,
66
+ "dat": 64,
67
+ "dbrx": 65,
68
+ "deaot": 66,
69
+ "debiformer": 67,
70
+ "deeplabv3": 68,
71
+ "deepmind": 69,
72
+ "deepseek": 70,
73
+ "deit": 71,
74
+ "densenet": 72,
75
+ "derivative": 73,
76
+ "diffusion": 74,
77
+ "dinat": 75,
78
+ "dit": 76,
79
+ "dolly": 77,
80
+ "dolphin": 78,
81
+ "e5": 79,
82
+ "eat": 80,
83
+ "ece": 81,
84
+ "edm2": 82,
85
+ "efficientnet": 83,
86
+ "efficientvit": 84,
87
+ "ensemble": 85,
88
+ "erann": 86,
89
+ "ernie": 87,
90
+ "exaone": 88,
91
+ "falcon": 89,
92
+ "fastervit": 90,
93
+ "flamingo": 91,
94
+ "flan": 92,
95
+ "flava": 93,
96
+ "fmixia": 94,
97
+ "gal": 95,
98
+ "gan": 96,
99
+ "gdi": 97,
100
+ "gemini": 98,
101
+ "gemma": 99,
102
+ "gin": 100,
103
+ "git": 101,
104
+ "gladiator": 102,
105
+ "glam": 103,
106
+ "glm": 104,
107
+ "googlenet": 105,
108
+ "gopher": 106,
109
+ "gpt": 107,
110
+ "granite": 108,
111
+ "graphormer": 109,
112
+ "grok": 110,
113
+ "gte": 111,
114
+ "h2o": 112,
115
+ "handreader": 113,
116
+ "hermes": 114,
117
+ "hitnet": 115,
118
+ "hrformer": 116,
119
+ "hrnet": 117,
120
+ "hubert": 118,
121
+ "hybrid": 119,
122
+ "idefics": 120,
123
+ "imagen": 121,
124
+ "imp": 122,
125
+ "inception": 123,
126
+ "incoder": 124,
127
+ "inexpertus": 125,
128
+ "instructblip": 126,
129
+ "internimage": 127,
130
+ "internlm": 128,
131
+ "ipt": 129,
132
+ "janus": 130,
133
+ "josie": 131,
134
+ "kosmos": 132,
135
+ "kronos": 133,
136
+ "kstc": 134,
137
+ "lamarck": 135,
138
+ "laneaf": 136,
139
+ "layernas": 137,
140
+ "layoutlmv3": 138,
141
+ "layoutmask": 139,
142
+ "lexora": 140,
143
+ "light": 141,
144
+ "linkbricks": 142,
145
+ "lit": 143,
146
+ "litv2": 144,
147
+ "llama": 145,
148
+ "llava": 146,
149
+ "llemma": 147,
150
+ "llm": 148,
151
+ "longformer": 149,
152
+ "lucie": 150,
153
+ "lxmert": 151,
154
+ "lyra": 152,
155
+ "m2d": 153,
156
+ "magnolia": 154,
157
+ "magnum": 155,
158
+ "mamba": 156,
159
+ "marian": 157,
160
+ "mask": 158,
161
+ "mavil": 159,
162
+ "megatron": 160,
163
+ "metamath": 161,
164
+ "mfann3bv0": 162,
165
+ "mfann3bv1": 163,
166
+ "mgm": 164,
167
+ "microsoft": 165,
168
+ "mimicore": 166,
169
+ "mindact": 167,
170
+ "minerva": 168,
171
+ "ministral": 169,
172
+ "miniuslight": 170,
173
+ "minthy": 171,
174
+ "mischievous": 172,
175
+ "miscii": 173,
176
+ "mistral": 174,
177
+ "mita": 175,
178
+ "mixnet": 176,
179
+ "mm1": 177,
180
+ "mnasnet": 178,
181
+ "moat": 179,
182
+ "mobilenet": 180,
183
+ "moe": 181,
184
+ "moganet": 182,
185
+ "mossformer2": 183,
186
+ "motip": 184,
187
+ "mplug": 185,
188
+ "mpt": 186,
189
+ "mugglemath": 187,
190
+ "musicgen": 188,
191
+ "muxnet": 189,
192
+ "mvit": 190,
193
+ "nanolm": 191,
194
+ "nat": 192,
195
+ "nemotron": 193,
196
+ "neo": 194,
197
+ "neural": 195,
198
+ "nfnet": 196,
199
+ "nova": 197,
200
+ "nuwa": 198,
201
+ "odise": 199,
202
+ "ofa": 200,
203
+ "olmner": 201,
204
+ "olmo": 202,
205
+ "openbuddy": 203,
206
+ "openchat": 204,
207
+ "openflamingo": 205,
208
+ "opt": 206,
209
+ "orca": 207,
210
+ "osvos": 208,
211
+ "pali": 209,
212
+ "palm": 210,
213
+ "panoptic": 211,
214
+ "pantheon": 212,
215
+ "pdo": 213,
216
+ "pegasus": 214,
217
+ "phi": 215,
218
+ "pit": 216,
219
+ "pixart": 217,
220
+ "pllava": 218,
221
+ "pllum": 219,
222
+ "plm": 220,
223
+ "point": 221,
224
+ "ppllava": 222,
225
+ "proto": 223,
226
+ "prymmal": 224,
227
+ "pvtv2": 225,
228
+ "pythia": 226,
229
+ "q2l": 227,
230
+ "qandoraexp": 228,
231
+ "qanet": 229,
232
+ "qwen": 230,
233
+ "r50": 231,
234
+ "r[2+1]d": 232,
235
+ "rdnet": 233,
236
+ "reasoningcore": 234,
237
+ "recurrentgemma": 235,
238
+ "redimnet": 236,
239
+ "rednet": 237,
240
+ "redpajama": 238,
241
+ "reflexis": 239,
242
+ "regnety": 240,
243
+ "regvit": 241,
244
+ "resmlp": 242,
245
+ "resnest": 243,
246
+ "resnet": 244,
247
+ "resnext": 245,
248
+ "retrieval": 246,
249
+ "revbifpn": 247,
250
+ "rewiz": 248,
251
+ "rexnet": 249,
252
+ "rft": 250,
253
+ "rnn": 251,
254
+ "rstt": 252,
255
+ "rusted": 253,
256
+ "rwkv": 254,
257
+ "saba1": 255,
258
+ "saka": 256,
259
+ "sam": 257,
260
+ "san": 258,
261
+ "sauerkrautlm": 259,
262
+ "scalenet": 260,
263
+ "scrfd": 261,
264
+ "seamlessm4t": 262,
265
+ "seer": 263,
266
+ "segformer": 264,
267
+ "segnext": 265,
268
+ "sequencer2d": 266,
269
+ "shift": 267,
270
+ "sid": 268,
271
+ "sida": 269,
272
+ "singularity": 270,
273
+ "sjt": 271,
274
+ "slowfast": 272,
275
+ "smollm": 273,
276
+ "smoltulu": 274,
277
+ "solar": 275,
278
+ "sombrero": 276,
279
+ "speechstew": 277,
280
+ "stablelm": 278,
281
+ "starcoder": 279,
282
+ "stm": 280,
283
+ "summer": 281,
284
+ "svtr": 282,
285
+ "swin": 283,
286
+ "t5": 284,
287
+ "tarsier": 285,
288
+ "thea": 286,
289
+ "tinymistral": 287,
290
+ "tinyvit": 288,
291
+ "titannet": 289,
292
+ "tora": 290,
293
+ "transformer": 291,
294
+ "transnext": 292,
295
+ "triangulum": 293,
296
+ "trocr": 294,
297
+ "tsunami": 295,
298
+ "twist": 296,
299
+ "two": 297,
300
+ "ul2": 298,
301
+ "ultiima": 299,
302
+ "una": 300,
303
+ "unet": 301,
304
+ "unifiedqa": 302,
305
+ "uniformer": 303,
306
+ "uninet": 304,
307
+ "unireplknet": 305,
308
+ "uniter": 306,
309
+ "unknown": 307,
310
+ "van": 308,
311
+ "vgg": 309,
312
+ "vicious": 310,
313
+ "video": 311,
314
+ "vila": 312,
315
+ "vilt": 313,
316
+ "vinvl": 314,
317
+ "vit": 315,
318
+ "vlm": 316,
319
+ "wav2vec": 317,
320
+ "wav2vec2": 318,
321
+ "wavlm": 319,
322
+ "whisper": 320,
323
+ "wide": 321,
324
+ "winter": 322,
325
+ "wizard": 323,
326
+ "xcit": 324,
327
+ "xlm": 325,
328
+ "xlnet": 326,
329
+ "xmem": 327,
330
+ "yi": 328,
331
+ "zephyr": 329,
332
+ "zeus": 330
333
+ }
recommend.py CHANGED
@@ -136,6 +136,270 @@ def _is_official_name(name: str) -> bool:
136
  return _OFFICIAL_BARE_PREFIX_RE.match(nl) is not None
137
 
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  def _slug(s: str) -> str:
140
  return re.sub(r"[^a-z0-9]+", "", str(s).strip().lower())
141
 
@@ -187,6 +451,15 @@ class Recommender:
187
  self.task2id: dict[str, int] = json.load(f)
188
  with open(os.path.join(data_dir, "metric2id.json")) as f:
189
  metric2id_raw: dict[str, int] = json.load(f)
 
 
 
 
 
 
 
 
 
190
  # The training-time metric vocab is the raw composite keys; expose both
191
  # the raw form and a lowercased / slugged alias for lookup.
192
  self.metric2id = metric2id_raw
@@ -210,6 +483,16 @@ class Recommender:
210
  [_is_official_name(n) for n in self.model_names], dtype=bool
211
  )
212
 
 
 
 
 
 
 
 
 
 
 
213
  # Build the MLPMetric model with the same hyper-parameters used for training.
214
  cfg = self._train_args
215
  model_args = SimpleNamespace(
@@ -358,11 +641,13 @@ class Recommender:
358
  """
359
  task_id = self.resolve_task(task)
360
  metric_id = self.resolve_metric(metric)
 
361
  emb = self.embed_description(dataset_description, api_key=api_key)
362
  return self._score(
363
  emb, task_id, metric_id, top_k, popularity_weight, hf_only,
364
  min_size_b=min_size_b, max_size_b=max_size_b,
365
  official_only=official_only,
 
366
  )
367
 
368
  @torch.no_grad()
@@ -377,6 +662,7 @@ class Recommender:
377
  min_size_b: Optional[float] = None,
378
  max_size_b: Optional[float] = None,
379
  official_only: bool = False,
 
380
  ) -> List[Recommendation]:
381
  device = self.device
382
  task_t = torch.tensor([task_id], dtype=torch.long, device=device)
@@ -423,6 +709,14 @@ class Recommender:
423
  if official_only:
424
  ranking_scores = np.where(self.is_official, ranking_scores, -np.inf)
425
 
 
 
 
 
 
 
 
 
426
  top_k = max(1, min(int(top_k), len(self.model_names)))
427
  top_idx = np.argpartition(-ranking_scores, top_k - 1)[:top_k]
428
  top_idx = top_idx[np.argsort(-ranking_scores[top_idx])]
 
136
  return _OFFICIAL_BARE_PREFIX_RE.match(nl) is not None
137
 
138
 
139
+ # --------------------------------------------------------------------------
140
+ # Modality / capability filter.
141
+ #
142
+ # The MLPMetric was trained on (dataset_emb, task_id, metric_id, model_emb) →
143
+ # score, and does *not* learn a hard "this LLM cannot do image generation"
144
+ # constraint. Without a post-filter, picking task=Image Generation surfaces
145
+ # Llama / Qwen / DeepSeek (high-popularity LLMs) ahead of any diffusion model.
146
+ #
147
+ # We classify each model family into one or more capability tags, classify the
148
+ # task into the set of capabilities it requires, and intersect.
149
+ # --------------------------------------------------------------------------
150
+
151
+ # Capability tags. Order matters only for the bitmask encoding.
152
+ _ALL_CAPS = (
153
+ "text", "text_embedding", "vision", "vision_generate",
154
+ "vision_language", "audio", "video", "document",
155
+ )
156
+ _CAP_BIT = {c: 1 << i for i, c in enumerate(_ALL_CAPS)}
157
+
158
+
159
+ def _bits(*caps: str) -> int:
160
+ b = 0
161
+ for c in caps:
162
+ b |= _CAP_BIT[c]
163
+ return b
164
+
165
+
166
+ # Family → capability bitmask. Anything not listed defaults to TEXT (most
167
+ # unknowns are LLM / encoder fine-tunes). Families that span multiple
168
+ # modalities (e.g. CLIP, LLaVA) get multiple bits set.
169
+ _FAMILY_CAPS: dict[str, int] = {}
170
+
171
+
172
+ def _assign(families, caps_bits):
173
+ for f in families:
174
+ _FAMILY_CAPS[f.lower()] = caps_bits
175
+
176
+
177
+ _CAP_TEXT = _bits("text")
178
+ _CAP_VIS = _bits("vision")
179
+ _CAP_VL = _bits("vision_language", "vision")
180
+ _CAP_VGEN = _bits("vision_generate")
181
+ _CAP_AUDIO = _bits("audio")
182
+ _CAP_VIDEO = _bits("video")
183
+ _CAP_EMB = _bits("text_embedding", "text")
184
+ _CAP_DOC = _bits("document", "vision")
185
+ _CAP_AUDIO_GEN = _bits("audio", "vision_generate") # musicgen / audioldm
186
+
187
+ # Vision recognition (classification, detection, segmentation, depth, pose, ...)
188
+ _assign([
189
+ "vit", "deit", "swin", "beit", "convnext", "resnet", "resnext", "cnn",
190
+ "conv", "densenet", "efficientnet", "efficientvit", "fastervit",
191
+ "mobilenet", "mnasnet", "mixnet", "muxnet", "mvit", "nat", "nfnet", "vgg",
192
+ "regnety", "regvit", "rexnet", "sequencer2d", "segformer", "segnext",
193
+ "deeplabv3", "mask", "point", "sam", "dinat", "dat", "caformer", "cmx",
194
+ "cswin", "cvt", "cloformer", "derivative", "gdi", "graphormer", "hrnet",
195
+ "hrformer", "internimage", "inception", "googlenet", "layernas", "laneaf",
196
+ "motip", "moat", "osvos", "panoptic", "pit", "proto", "pvtv2", "q2l",
197
+ "r50", "r[2+1]d", "rdnet", "rednet", "revbifpn", "scrfd", "scalenet",
198
+ "shift", "svtr", "tinyvit", "transnext", "twist", "uniformer", "uninet",
199
+ "unireplknet", "van", "xcit", "aerialformer", "asymmnet", "alphanet",
200
+ "aot", "autoformer", "bit", "cait", "crisscross", "deaot", "debiformer",
201
+ "handreader", "hitnet", "hybrid", "ipt", "kronos", "layoutmask", "lit",
202
+ "litv2", "mavil", "mim", "moganet", "odise", "redimnet", "resmlp",
203
+ "resnest", "rstt", "san", "sombrero", "unet", "xmem", "segnext",
204
+ "fmixia", "gladiator", "mfann3bv0", "mfann3bv1",
205
+ ], _CAP_VIS)
206
+
207
+ # Image / video generation
208
+ _assign([
209
+ "diffusion", "gan", "imagen", "dall", "pixart", "dit", "edm2", "nuwa",
210
+ "pdo", "sid", "sida",
211
+ ], _CAP_VGEN)
212
+
213
+ # Audio (ASR / TTS / audio classification / source separation)
214
+ _assign([
215
+ "whisper", "wav2vec", "wav2vec2", "hubert", "ast", "conformer", "wavlm",
216
+ "beats", "speechstew", "titannet", "seamlessm4t", "m2d", "eat", "erann",
217
+ "mossformer2",
218
+ ], _CAP_AUDIO)
219
+
220
+ # Audio generation
221
+ _assign(["musicgen", "audioldm"], _CAP_AUDIO_GEN)
222
+
223
+ # Video
224
+ _assign(["video", "slowfast", "tarsier"], _CAP_VIDEO | _CAP_VIS)
225
+
226
+ # Vision-language (multimodal: image + text)
227
+ _assign([
228
+ "clip", "llava", "kosmos", "blip", "idefics", "flava", "flamingo",
229
+ "openflamingo", "instructblip", "lxmert", "vilt", "vinvl", "uniter",
230
+ "vlm", "mm1", "mplug", "ofa", "pali", "imp", "vila", "aurora", "sapiens",
231
+ "pllava", "ppllava", "plm", "mgm", "janus", "aimv2", "altclip", "aya",
232
+ "albef", "apollo", "captain",
233
+ ], _CAP_VL)
234
+
235
+ # Text embeddings / retrieval
236
+ _assign([
237
+ "bge", "e5", "gte", "mpnet", "minilm", "retrieval",
238
+ ], _CAP_EMB)
239
+
240
+ # Document understanding (OCR + layout)
241
+ _assign([
242
+ "layoutlmv3", "trocr", "git", "donut",
243
+ ], _CAP_DOC)
244
+
245
+ # All other families (LLMs, encoders, code, translation, ...) → TEXT.
246
+ # Explicitly listing them keeps the map self-documenting.
247
+ _assign([
248
+ # Decoder LLMs
249
+ "llama", "qwen", "mistral", "ministral", "mixtral", "gemma",
250
+ "recurrentgemma", "deepseek", "phi", "falcon", "yi", "granite", "t5",
251
+ "bart", "bloom", "opt", "palm", "smollm", "smoltulu", "wizard", "magnum",
252
+ "ece", "transformer", "moe", "gemini", "claude", "command", "cohere",
253
+ "dolly", "mpt", "pythia", "dolphin", "hermes", "openbuddy", "openchat",
254
+ "baichuan", "internlm", "olmo", "olmner", "dbrx", "exaone", "nemotron",
255
+ "nova", "orca", "solar", "stablelm", "tinymistral", "lucie", "lyra",
256
+ "megatron", "miniuslight", "miscii", "neural", "nanolm", "pllum",
257
+ "prymmal", "qandoraexp", "redpajama", "reflexis", "rewiz", "rusted",
258
+ "rwkv", "saba1", "saka", "sauerkrautlm", "summer", "triangulum", "ul2",
259
+ "ultiima", "una", "unifiedqa", "vicious", "winter", "zephyr", "zeus",
260
+ "lamarck", "llemma", "llm", "light", "magnolia", "mita", "openbuddy",
261
+ "pegasus", "h2o", "flan", "ernie", "gopher", "chinchilla", "grok",
262
+ "blossom", "branch", "bellatrix", "chatwaifu", "chocolatine", "cleverboi",
263
+ "cursa", "cybernet", "dans", "deepmind", "gal", "glam", "incoder",
264
+ "inexpertus", "josie", "kstc", "lexora", "linkbricks", "longformer",
265
+ "mamba", "mavil", "mindact", "minerva", "mossformer2", "mugglemath",
266
+ "neo", "openflamingo", "pantheon", "qanet", "reasoningcore", "rft",
267
+ "rnn", "sjt", "stm", "thea", "tora", "tsunami", "twist", "ultiima",
268
+ "vlama", "wide", "xlm", "xlm-roberta", "xlnet",
269
+ # Encoders / classifiers
270
+ "bert", "distilbert", "roberta", "albert", "electra",
271
+ # Code-specialized LLMs (still text-modality at the task level)
272
+ "code", "codellama", "starcoder", "llemma", "metamath", "damomath",
273
+ "acemath", "aceinstruct",
274
+ # Translation
275
+ "marian", "seamlessm4t", # seamlessm4t reassigned: it's multilingual S2T+T2T, also audio
276
+ # Vision-language LLMs that often appear as text-only on benchmarks
277
+ "molmo",
278
+ ], _CAP_TEXT)
279
+
280
+ # Special: seamlessm4t is both audio (speech translation) and text
281
+ _FAMILY_CAPS["seamlessm4t"] = _CAP_AUDIO | _CAP_TEXT
282
+
283
+
284
+ def _family_caps_bits(family: str) -> int:
285
+ return _FAMILY_CAPS.get((family or "").strip().lower(), _CAP_TEXT)
286
+
287
+
288
+ # Single-bit task-side constants. A task lists the *capabilities a model must
289
+ # have* to be considered. We then accept a model if its (multi-bit) capability
290
+ # mask intersects the task's required bits. Using single bits on the task
291
+ # side (instead of compound model-side tags like _CAP_VL) avoids the bug
292
+ # where requiring "vision-language" would also accept plain vision encoders.
293
+ _REQ_TEXT = _CAP_BIT["text"]
294
+ _REQ_EMB = _CAP_BIT["text_embedding"]
295
+ _REQ_VIS = _CAP_BIT["vision"]
296
+ _REQ_VGEN = _CAP_BIT["vision_generate"]
297
+ _REQ_VL = _CAP_BIT["vision_language"]
298
+ _REQ_AUDIO = _CAP_BIT["audio"]
299
+ _REQ_VIDEO = _CAP_BIT["video"]
300
+ _REQ_DOC = _CAP_BIT["document"]
301
+
302
+
303
+ # Task name → required capability bitmask. Ordered list: first match wins.
304
+ # Patterns are lower-cased substring or regex tests against the task name.
305
+ _TASK_RULES: list[tuple[re.Pattern, int]] = [
306
+ # Image / video generation — must actually produce pixels.
307
+ (re.compile(r"\b(text[- ]to[- ]image|image[- ]to[- ]image|image generation|"
308
+ r"conditional image generation|personalized image generation|"
309
+ r"image synthesis|image editing|inpaint|outpaint|"
310
+ r"super[- ]?resolution|denoising|colorization|style transfer|"
311
+ r"text[- ]to[- ]video|video generation|video synthesis|"
312
+ r"image restoration|image-to-image)\b", re.I),
313
+ _REQ_VGEN),
314
+
315
+ # Audio generation / TTS / music generation
316
+ (re.compile(r"\b(text[- ]to[- ]speech|speech synthesis|\btts\b|"
317
+ r"voice conversion|voice cloning|audio generation|"
318
+ r"music generation|music synthesis|sound generation)\b", re.I),
319
+ _REQ_AUDIO),
320
+
321
+ # ASR / audio understanding — audio models only.
322
+ (re.compile(r"\b(speech recognition|automatic speech recognition|\basr\b|"
323
+ r"audio classification|audio captioning|audio retrieval|"
324
+ r"audio.*detection|audio source separation|audio tagging|"
325
+ r"audio super-resolution|spoken|phoneme|acoustic|"
326
+ r"voice activity|voice.*recognition|emotion recognition.*audio|"
327
+ r"music.*(?:auto-tagging|source|transcription|recognition|"
328
+ r"classification|tagging)|sound classification|"
329
+ r"bandwidth extension|speech.*(?:enhancement|separation|"
330
+ r"translation))\b", re.I),
331
+ _REQ_AUDIO),
332
+
333
+ # Video understanding — video-specific models.
334
+ (re.compile(r"\b(video classification|video captioning|"
335
+ r"video question answering|video retrieval|video understanding|"
336
+ r"action recognition.*video|video.*recognition|"
337
+ r"temporal action|video segmentation)\b", re.I),
338
+ _REQ_VIDEO),
339
+
340
+ # Vision-language: VQA, captioning, visual reasoning — must have a text
341
+ # decoder on top of a vision encoder (CLIP, LLaVA, BLIP, ...).
342
+ (re.compile(r"\b(visual question answering|\bvqa\b|image captioning|"
343
+ r"visual reasoning|image[- ]text|visual grounding|"
344
+ r"referring expression|chart.*(?:understanding|qa|vqa)|"
345
+ r"document.*understanding|docvqa|infovqa|chartqa|"
346
+ r"visual entailment|visual commonsense|image retrieval|"
347
+ r"cross-modal retrieval|scene text|multimodal)\b", re.I),
348
+ _REQ_VL),
349
+
350
+ # OCR / document — purpose-built document models, plus VL fallback.
351
+ (re.compile(r"\b(\bocr\b|optical character|handwriting recognition|"
352
+ r"document.*(?:classification|layout|parsing)|"
353
+ r"table.*(?:detection|recognition|extraction)|"
354
+ r"form understanding|receipt|invoice)\b", re.I),
355
+ _REQ_DOC | _REQ_VL),
356
+
357
+ # Vision recognition (broad) — vision encoders + VL multimodal.
358
+ (re.compile(r"\b(image classification|object detection|"
359
+ r"(semantic|instance|panoptic) segmentation|pose estimation|"
360
+ r"depth estimation|optical flow|scene.*(?:classification|"
361
+ r"recognition|parsing)|action recognition|action detection|"
362
+ r"action segmentation|object tracking|tracking|"
363
+ r"object discovery|object localization|keypoint|landmark|"
364
+ r"face.*(?:recognition|detection|verification|generation|"
365
+ r"reconstruction)|person re-identification|reid|"
366
+ r"3d.*(?:detect|classif|segment|reconstruct|pose|tracking|"
367
+ r"completion|generation)|point cloud|stereo|monocular|"
368
+ r"saliency|edge detection|anomaly detection|image matting|"
369
+ r"crowd counting|gaze estimation|hand.*estimation|"
370
+ r"animal pose|aerial|remote sensing|medical image|"
371
+ r"histology|radiology|tumor|lesion|breast|cancer image|"
372
+ r"covid.*(?:image|x-ray|ct)|x-ray|fundus|retinal|"
373
+ r"satellite|change detection|crop|bird|flower|food|"
374
+ r"plant|skin|dermoscopy|driving|lane|nuscenes|kitti|"
375
+ r"object.*(?:counting|grasping|6d))\b", re.I),
376
+ _REQ_VIS | _REQ_VL),
377
+
378
+ # Text embedding / retrieval / similarity
379
+ (re.compile(r"\b(text retrieval|document retrieval|passage retrieval|"
380
+ r"semantic search|sentence similarity|sentence[- ]?embedding|"
381
+ r"paraphrase identification|semantic textual similarity|"
382
+ r"\bsts\b|reranking|clustering|bitext mining)\b", re.I),
383
+ _REQ_EMB | _REQ_TEXT),
384
+ ]
385
+
386
+ # Capability bits we allow when no rule matches (mostly text-y tasks like
387
+ # QA, generation, classification, NER, sentiment, summarization, math,
388
+ # reasoning, code, translation). Vision-language is included so multimodal
389
+ # LLMs surface for text tasks.
390
+ _DEFAULT_TASK_CAPS = _REQ_TEXT | _REQ_VL
391
+
392
+
393
+ def _task_required_caps_bits(task: str) -> int:
394
+ if not task:
395
+ return _DEFAULT_TASK_CAPS
396
+ t = str(task).strip()
397
+ for pat, bits in _TASK_RULES:
398
+ if pat.search(t):
399
+ return bits
400
+ return _DEFAULT_TASK_CAPS
401
+
402
+
403
  def _slug(s: str) -> str:
404
  return re.sub(r"[^a-z0-9]+", "", str(s).strip().lower())
405
 
 
451
  self.task2id: dict[str, int] = json.load(f)
452
  with open(os.path.join(data_dir, "metric2id.json")) as f:
453
  metric2id_raw: dict[str, int] = json.load(f)
454
+ # family2id is needed to translate the integer family_ids stored in the
455
+ # pool back to family names, so we can look up modality capabilities.
456
+ family2id_path = os.path.join(data_dir, "family2id.json")
457
+ if os.path.isfile(family2id_path):
458
+ with open(family2id_path) as f:
459
+ family2id: dict[str, int] = json.load(f)
460
+ self._id2family: dict[int, str] = {v: k for k, v in family2id.items()}
461
+ else:
462
+ self._id2family = {}
463
  # The training-time metric vocab is the raw composite keys; expose both
464
  # the raw form and a lowercased / slugged alias for lookup.
465
  self.metric2id = metric2id_raw
 
483
  [_is_official_name(n) for n in self.model_names], dtype=bool
484
  )
485
 
486
+ # Precompute the modality capability bitmask per model. Resolve via
487
+ # the family vocab (preferred) and fall back to TEXT for any family we
488
+ # can't look up.
489
+ family_ids_np = self.family_ids.cpu().numpy()
490
+ self.model_caps_bits: np.ndarray = np.array(
491
+ [_family_caps_bits(self._id2family.get(int(fid), ""))
492
+ for fid in family_ids_np],
493
+ dtype=np.int64,
494
+ )
495
+
496
  # Build the MLPMetric model with the same hyper-parameters used for training.
497
  cfg = self._train_args
498
  model_args = SimpleNamespace(
 
641
  """
642
  task_id = self.resolve_task(task)
643
  metric_id = self.resolve_metric(metric)
644
+ task_caps_bits = _task_required_caps_bits(task)
645
  emb = self.embed_description(dataset_description, api_key=api_key)
646
  return self._score(
647
  emb, task_id, metric_id, top_k, popularity_weight, hf_only,
648
  min_size_b=min_size_b, max_size_b=max_size_b,
649
  official_only=official_only,
650
+ task_caps_bits=task_caps_bits,
651
  )
652
 
653
  @torch.no_grad()
 
662
  min_size_b: Optional[float] = None,
663
  max_size_b: Optional[float] = None,
664
  official_only: bool = False,
665
+ task_caps_bits: Optional[int] = None,
666
  ) -> List[Recommendation]:
667
  device = self.device
668
  task_t = torch.tensor([task_id], dtype=torch.long, device=device)
 
709
  if official_only:
710
  ranking_scores = np.where(self.is_official, ranking_scores, -np.inf)
711
 
712
+ # Modality / capability sanity check: drop models whose family does
713
+ # not overlap with the task's required modalities. Without this an
714
+ # LLM would surface high in e.g. "Image Generation" results because
715
+ # the MLPMetric never learned a hard modality constraint.
716
+ if task_caps_bits:
717
+ compat = (self.model_caps_bits & task_caps_bits) != 0
718
+ ranking_scores = np.where(compat, ranking_scores, -np.inf)
719
+
720
  top_k = max(1, min(int(top_k), len(self.model_names)))
721
  top_idx = np.argpartition(-ranking_scores, top_k - 1)[:top_k]
722
  top_idx = top_idx[np.argsort(-ranking_scores[top_idx])]