Defuser 0.0.32__tar.gz → 0.0.33__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {defuser-0.0.32 → defuser-0.0.33}/Defuser.egg-info/PKG-INFO +1 -1
- {defuser-0.0.32 → defuser-0.0.33}/PKG-INFO +1 -1
- {defuser-0.0.32 → defuser-0.0.33}/defuser/model_registry.py +12 -0
- {defuser-0.0.32 → defuser-0.0.33}/pyproject.toml +1 -1
- {defuser-0.0.32 → defuser-0.0.33}/tests/test_convert_model.py +77 -1
- {defuser-0.0.32 → defuser-0.0.33}/Defuser.egg-info/SOURCES.txt +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/Defuser.egg-info/dependency_links.txt +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/Defuser.egg-info/requires.txt +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/Defuser.egg-info/top_level.txt +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/LICENSE +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/README.md +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/__init__.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/checkpoint_ops.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/defuser.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/__init__.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/glm4v.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/model_patches.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/moe_experts_interface.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/replace_modules.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/runtime_defusion.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/unfused_moe/__init__.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/unfused_moe/common.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/unfused_moe/glm4_moe.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/unfused_moe/glm4_moe_lite.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/unfused_moe/mixtral.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/unfused_moe/qwen2_moe.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/unfused_moe/qwen3_moe.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/unfused_moe/qwen3_next.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/unfused_moe/qwen3_omni_moe.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/modeling/update_module.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/utils/__init__.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/utils/common.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/utils/device.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/utils/hf.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/defuser/utils/model.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/setup.cfg +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/setup.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/tests/test_candidate_coverage.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/tests/test_device_utils.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/tests/test_filter_rules.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/tests/test_meta_model_defusion.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/tests/test_moe_experts_interface.py +0 -0
- {defuser-0.0.32 → defuser-0.0.33}/tests/test_replace_modules_tracker.py +0 -0
|
@@ -52,6 +52,18 @@ MODEL_CONFIG = {
|
|
|
52
52
|
"inkling_mm_model": {
|
|
53
53
|
"min_transformers_version": MIN_SUPPORTED_TRANSFORMERS_VERSION,
|
|
54
54
|
},
|
|
55
|
+
"inkling2_loop": {
|
|
56
|
+
"min_transformers_version": MIN_SUPPORTED_TRANSFORMERS_VERSION,
|
|
57
|
+
PATCH.EXPERTS_DEFUSE: [
|
|
58
|
+
{
|
|
59
|
+
# Inkling 2 Mini keeps routed experts as 3-D gate_up_proj /
|
|
60
|
+
# down_proj parameters. Expand them into per-expert Linear
|
|
61
|
+
# modules so quantizers can discover and quantize each expert.
|
|
62
|
+
"module_class": "transformers.models.inkling2_loop.modeling_inkling2_loop.Inkling2LoopExperts",
|
|
63
|
+
"forward_impl": "linear_loop",
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
},
|
|
55
67
|
"deepseek_v3": {
|
|
56
68
|
"min_transformers_version": MIN_SUPPORTED_TRANSFORMERS_VERSION,
|
|
57
69
|
},
|
|
@@ -1292,7 +1292,9 @@ def test_defused_glm4_model_forward_accepts_router_tuple(model_type, config_fact
|
|
|
1292
1292
|
assert torch.isfinite(logits).all()
|
|
1293
1293
|
|
|
1294
1294
|
|
|
1295
|
-
@pytest.mark.parametrize(
|
|
1295
|
+
@pytest.mark.parametrize(
|
|
1296
|
+
"model_type", ["kimi_k25", "kimi_linear", "mimo_v2_flash", "unlimited_ocr", "inkling2_loop"]
|
|
1297
|
+
)
|
|
1296
1298
|
def test_native_moe_model_types_are_registered(model_type):
|
|
1297
1299
|
"""Native Transformers MoE backbones must not fall through the registry.
|
|
1298
1300
|
|
|
@@ -1335,6 +1337,80 @@ def test_native_moe_defusion_preserves_forward(model_type, config_factory, model
|
|
|
1335
1337
|
torch.testing.assert_close(actual, expected, atol=1e-6, rtol=0)
|
|
1336
1338
|
|
|
1337
1339
|
|
|
1340
|
+
def test_inkling2_loop_experts_defuse_preserves_forward():
|
|
1341
|
+
"""Inkling 2 Mini routed experts are 3-D parameters that must be expanded.
|
|
1342
|
+
|
|
1343
|
+
The implementation only exists on the open huggingface/transformers#51050
|
|
1344
|
+
branch, so this test skips with a precise reason on a released Transformers
|
|
1345
|
+
that has no ``inkling2_loop`` module.
|
|
1346
|
+
"""
|
|
1347
|
+
|
|
1348
|
+
modeling = pytest.importorskip(
|
|
1349
|
+
"transformers.models.inkling2_loop.modeling_inkling2_loop",
|
|
1350
|
+
reason="Inkling2Loop only exists on the open huggingface/transformers#51050 branch.",
|
|
1351
|
+
)
|
|
1352
|
+
configuration = pytest.importorskip(
|
|
1353
|
+
"transformers.models.inkling2_loop.configuration_inkling2_loop",
|
|
1354
|
+
reason="Inkling2Loop only exists on the open huggingface/transformers#51050 branch.",
|
|
1355
|
+
)
|
|
1356
|
+
|
|
1357
|
+
torch.manual_seed(0)
|
|
1358
|
+
config = configuration.Inkling2LoopConfig(
|
|
1359
|
+
text_config={
|
|
1360
|
+
"hidden_size": 32,
|
|
1361
|
+
"num_hidden_layers": 4,
|
|
1362
|
+
"num_attention_heads": 2,
|
|
1363
|
+
"num_key_value_heads": 1,
|
|
1364
|
+
"head_dim": 8,
|
|
1365
|
+
"intermediate_size": 16,
|
|
1366
|
+
"n_routed_experts": 3,
|
|
1367
|
+
"num_experts_per_tok": 2,
|
|
1368
|
+
"moe_intermediate_size": 8,
|
|
1369
|
+
"vocab_size": 64,
|
|
1370
|
+
"unpadded_vocab_size": 64,
|
|
1371
|
+
"n_layers_per_attn_res_block": 2,
|
|
1372
|
+
"d_rel": 2,
|
|
1373
|
+
"rel_extent": 4,
|
|
1374
|
+
"sliding_window_size": 4,
|
|
1375
|
+
"loop_config": {"core_start": 2, "core_end": 4, "num_passes": 2, "gate_rank": 4},
|
|
1376
|
+
},
|
|
1377
|
+
vision_config={
|
|
1378
|
+
"hidden_size": 16,
|
|
1379
|
+
"num_hidden_layers": 1,
|
|
1380
|
+
"num_attention_heads": 2,
|
|
1381
|
+
"projection_hidden_dim": 16,
|
|
1382
|
+
"text_hidden_size": 32,
|
|
1383
|
+
},
|
|
1384
|
+
)
|
|
1385
|
+
model = modeling.Inkling2LoopForConditionalGeneration(config).eval()
|
|
1386
|
+
input_ids = torch.tensor([[1, 2, 3, 4, 5]])
|
|
1387
|
+
|
|
1388
|
+
with torch.no_grad():
|
|
1389
|
+
expected = model(input_ids=input_ids, use_cache=False).logits
|
|
1390
|
+
|
|
1391
|
+
containers = [module for name, module in model.named_modules() if name.endswith(".mlp.experts")]
|
|
1392
|
+
assert len(containers) == config.text_config.num_hidden_layers
|
|
1393
|
+
assert all(hasattr(container, "gate_up_proj") for container in containers)
|
|
1394
|
+
|
|
1395
|
+
assert convert_model(model, cleanup_original=False) is True
|
|
1396
|
+
|
|
1397
|
+
containers = [module for name, module in model.named_modules() if name.endswith(".mlp.experts")]
|
|
1398
|
+
assert len(containers) == config.text_config.num_hidden_layers
|
|
1399
|
+
for container in containers:
|
|
1400
|
+
assert not hasattr(container, "gate_up_proj")
|
|
1401
|
+
assert not hasattr(container, "down_proj")
|
|
1402
|
+
for index in range(config.text_config.n_routed_experts):
|
|
1403
|
+
expert = container.get_submodule(str(index))
|
|
1404
|
+
assert isinstance(expert.gate_proj, nn.Linear)
|
|
1405
|
+
assert isinstance(expert.up_proj, nn.Linear)
|
|
1406
|
+
assert isinstance(expert.down_proj, nn.Linear)
|
|
1407
|
+
|
|
1408
|
+
with torch.no_grad():
|
|
1409
|
+
actual = model(input_ids=input_ids, use_cache=False).logits
|
|
1410
|
+
|
|
1411
|
+
torch.testing.assert_close(actual, expected, atol=1e-6, rtol=0)
|
|
1412
|
+
|
|
1413
|
+
|
|
1338
1414
|
def test_glm4v_checkpoint_mapping_splits_gate_up_proj():
|
|
1339
1415
|
from defuser.defuser import get_checkpoint_conversion_mapping
|
|
1340
1416
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|