def find_layers(
    module, layers=(nn.Conv2d, nn.Conv1d, nn.Linear, transformers.Conv1D), name=""
):
    """Get all layers with target types."""
    for layer in layers:
        if isinstance(module, layer):
            return {name: module}
    res = {}
    for name1, child in module.named_children():
        res.update(
            find_layers(
                child, layers=layers, name=name + "." + name1 if name != "" else name1
            )
        )
    return res
Get all layers with target types.
intel_extension_for_pytorch/quantization/_GPTQ/gptq/model_utils.py