|
21 | 21 | tie_word_embeddings, |
22 | 22 | vlm_decoder_weights, |
23 | 23 | vlm_embedding_weights, |
| 24 | + vlm_vision_weights, |
24 | 25 | ) |
25 | 26 |
|
26 | 27 |
|
@@ -396,6 +397,44 @@ def test_custom_keyword(self): |
396 | 397 | assert list(result.keys()) == ["word_embedding.weight"] |
397 | 398 |
|
398 | 399 |
|
| 400 | +class TestVlmVisionWeights: |
| 401 | + """Tests for vlm_vision_weights.""" |
| 402 | + |
| 403 | + def test_filters_and_renames(self): |
| 404 | + """Keeps prefixed keys and renames fc1/fc2.""" |
| 405 | + fc1 = torch.randn(4, 8) |
| 406 | + fc2 = torch.randn(8, 4) |
| 407 | + sd = { |
| 408 | + "vision_tower.encoder.layers.0.mlp.fc1.weight": fc1, |
| 409 | + "vision_tower.encoder.layers.0.mlp.fc2.weight": fc2, |
| 410 | + "multi_modal_projector.linear.weight": torch.randn(4), |
| 411 | + "language_model.model.layers.0.weight": torch.randn(4), |
| 412 | + } |
| 413 | + result = vlm_vision_weights(sd, ("vision_tower.", "multi_modal_projector.")) |
| 414 | + assert set(result.keys()) == { |
| 415 | + "vision_tower.encoder.layers.0.mlp.up_proj.weight", |
| 416 | + "vision_tower.encoder.layers.0.mlp.down_proj.weight", |
| 417 | + "multi_modal_projector.linear.weight", |
| 418 | + } |
| 419 | + assert result["vision_tower.encoder.layers.0.mlp.up_proj.weight"].data_ptr() == ( |
| 420 | + fc1.data_ptr() |
| 421 | + ) |
| 422 | + |
| 423 | + def test_single_prefix(self): |
| 424 | + """Works with a single-element prefix tuple.""" |
| 425 | + sd = { |
| 426 | + "vision_model.layers.0.mlp.fc1.weight": torch.randn(2), |
| 427 | + "other.weight": torch.randn(2), |
| 428 | + } |
| 429 | + result = vlm_vision_weights(sd, ("vision_model.",)) |
| 430 | + assert list(result.keys()) == ["vision_model.layers.0.mlp.up_proj.weight"] |
| 431 | + |
| 432 | + def test_empty_when_no_match(self): |
| 433 | + """Returns empty dict when no key matches the prefixes.""" |
| 434 | + sd = {"language_model.layers.0.weight": torch.randn(2)} |
| 435 | + assert vlm_vision_weights(sd, ("vision_tower.",)) == {} |
| 436 | + |
| 437 | + |
399 | 438 | class TestPreprocessGptqWeights: |
400 | 439 | """Tests for GPTQ weight preprocessing. |
401 | 440 |
|
|
0 commit comments