Skip to content

Detector

detect_model_architecture(model, targets=None)

A function detecting architecture for a given model.

Parameters:

Name Type Description Default
model Model

The machine learning model to be detected

required

Returns:

Name Type Description
ModelArchitectureSummary Set[ModuleType]

A summary of model architecture

Source code in pnpxai/core/detector/detector.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def detect_model_architecture(
    model: Model,
    targets: Optional[Tuple[ModuleType]] = None,
) -> Set[ModuleType]:
    """
    A function detecting architecture for a given model.

    Args:
        model (Model): The machine learning model to be detected

    Returns:
        ModelArchitectureSummary: A summary of model architecture
    """
    targets = targets or DEFAULT_MODULE_TYPES_TO_DETECT
    detected = set()
    for nm, module in model.named_modules():
        module_type = next(
            (target for target in targets if isinstance(module, target)), None)
        if module_type is None:
            continue
        detected.add(module_type)
    return detected