Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 1 addition & 30 deletions src/llmcompressor/modifiers/utils/pytorch_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
from typing import Dict

import torch
from torch.nn import Module

__all__ = [
"apply_pad_mask_to_batch",
"is_moe_model",
]
__all__ = ["apply_pad_mask_to_batch"]


def apply_pad_mask_to_batch(batch: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
Expand All @@ -35,28 +31,3 @@ def apply_pad_mask_to_batch(batch: Dict[str, torch.Tensor]) -> Dict[str, torch.T
batch[key] = batch[key] * batch["attention_mask"]

return batch


def is_moe_model(model: Module) -> bool:
"""
Check if the model is a mixture of experts model

:param model: the model to check
:return: True if the model is a mixture of experts model
"""

# Check for MoE components
for _, module in model.named_modules():
module_name = module.__class__.__name__
if "MoE" in module_name or "Expert" in module_name:
return True

# Check config for MoE attributes
if hasattr(model, "config"):
if any(
"moe" in attr.lower() or "expert" in attr.lower()
for attr in dir(model.config)
):
return True

return False
Loading