|
20 | 20 | tie_word_embeddings, |
21 | 21 | vlm_decoder_weights, |
22 | 22 | vlm_embedding_weights, |
| 23 | + vlm_vision_weights, |
23 | 24 | ) |
24 | 25 |
|
25 | 26 |
|
@@ -330,6 +331,44 @@ def test_custom_keyword(self): |
330 | 331 | assert list(result.keys()) == ["word_embedding.weight"] |
331 | 332 |
|
332 | 333 |
|
| 334 | +class TestVlmVisionWeights: |
| 335 | + """Tests for vlm_vision_weights.""" |
| 336 | + |
| 337 | + def test_filters_and_renames(self): |
| 338 | + """Keeps prefixed keys and renames fc1/fc2.""" |
| 339 | + fc1 = torch.randn(4, 8) |
| 340 | + fc2 = torch.randn(8, 4) |
| 341 | + sd = { |
| 342 | + "vision_tower.encoder.layers.0.mlp.fc1.weight": fc1, |
| 343 | + "vision_tower.encoder.layers.0.mlp.fc2.weight": fc2, |
| 344 | + "multi_modal_projector.linear.weight": torch.randn(4), |
| 345 | + "language_model.model.layers.0.weight": torch.randn(4), |
| 346 | + } |
| 347 | + result = vlm_vision_weights(sd, ("vision_tower.", "multi_modal_projector.")) |
| 348 | + assert set(result.keys()) == { |
| 349 | + "vision_tower.encoder.layers.0.mlp.up_proj.weight", |
| 350 | + "vision_tower.encoder.layers.0.mlp.down_proj.weight", |
| 351 | + "multi_modal_projector.linear.weight", |
| 352 | + } |
| 353 | + assert result["vision_tower.encoder.layers.0.mlp.up_proj.weight"].data_ptr() == ( |
| 354 | + fc1.data_ptr() |
| 355 | + ) |
| 356 | + |
| 357 | + def test_single_prefix(self): |
| 358 | + """Works with a single-element prefix tuple.""" |
| 359 | + sd = { |
| 360 | + "vision_model.layers.0.mlp.fc1.weight": torch.randn(2), |
| 361 | + "other.weight": torch.randn(2), |
| 362 | + } |
| 363 | + result = vlm_vision_weights(sd, ("vision_model.",)) |
| 364 | + assert list(result.keys()) == ["vision_model.layers.0.mlp.up_proj.weight"] |
| 365 | + |
| 366 | + def test_empty_when_no_match(self): |
| 367 | + """Returns empty dict when no key matches the prefixes.""" |
| 368 | + sd = {"language_model.layers.0.weight": torch.randn(2)} |
| 369 | + assert vlm_vision_weights(sd, ("vision_tower.",)) == {} |
| 370 | + |
| 371 | + |
333 | 372 | class TestPreprocessGptqWeights: |
334 | 373 | """Tests for GPTQ weight preprocessing. |
335 | 374 |
|
|
0 commit comments