Skip to content

Commit 4c4aac2

Browse files
committed
fix
Signed-off-by: Hemil Desai <hemild@nvidia.com>
1 parent 45c08ae commit 4c4aac2

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

tests/unit_tests/_peft/test_lora_moe.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
except ImportError:
2222
grouped_gemm = None
2323

24+
try:
25+
import transformer_engine # noqa: F401
26+
HAS_TE = True
27+
except ImportError:
28+
HAS_TE = False
29+
2430
from nemo_automodel.components.moe.config import MoEConfig
2531
from nemo_automodel.components.moe.layers import GroupedExperts, GroupedExpertsDeepEP, GroupedExpertsTE
2632
from nemo_automodel.components._peft.lora_experts import GroupedExpertsLoRA, GroupedExpertsDeepEPLoRA
@@ -608,22 +614,28 @@ def test_deepep_lora_zero_tokens(moe_config, device):
608614

609615

610616
@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA required")
617+
@pytest.mark.skipif(not HAS_TE, reason="Transformer Engine required")
611618
def test_patch_moe_module_rejects_te_experts(moe_config, device):
612619
"""Test that patch_moe_module raises NotImplementedError for GroupedExpertsTE."""
613-
orig_experts = GroupedExpertsTE(moe_config).to(device)
620+
orig_experts = GroupedExpertsTE(moe_config)
621+
orig_experts.init_weights(buffer_device=device)
622+
orig_experts = orig_experts.to(device)
614623
with pytest.raises(NotImplementedError, match="LoRA is not supported for Transformer Engine"):
615624
patch_moe_module(orig_experts, dim=4)
616625

617626

618627
@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA required")
628+
@pytest.mark.skipif(not HAS_TE, reason="Transformer Engine required")
619629
def test_apply_lora_rejects_te_experts(moe_config, device):
620630
"""Test that apply_lora_to_linear_modules raises NotImplementedError for GroupedExpertsTE."""
621631
class MockModel(nn.Module):
622632
def __init__(self):
623633
super().__init__()
624634
self.experts = GroupedExpertsTE(moe_config)
625635

626-
model = MockModel().to(device)
636+
model = MockModel()
637+
model.experts.init_weights(buffer_device=device)
638+
model = model.to(device)
627639
peft_config = PeftConfig(target_modules=["experts"], dim=4)
628640

629641
with pytest.raises(NotImplementedError, match="LoRA is not supported for Transformer Engine"):
@@ -841,11 +853,6 @@ def __init__(self):
841853
dim=16,
842854
moe_rank_scaling=True,
843855
)
844-
import logging as _logging
845-
846-
with pytest.warns(None) as _:
847-
# We check the logger instead of pytest.warns (logger.warning, not warnings.warn)
848-
pass
849856

850857
with patch("nemo_automodel.components._peft.lora.logger") as mock_logger:
851858
count = apply_lora_to_linear_modules(model, peft_config)

0 commit comments

Comments
 (0)