    def generate_lrp(self, input_tensor: nn.Module, index: int = None, method: str = 'transformer_attribution',
                     start_layer: int = 0, device=None):
        """
        Generate LRP for a specific layer.
        Args:
            input_tensor (`nn.Module`):
                The input tensor to the model.
            index (`int`):
                The index of the layer to be visualized.
            method (`str`):
                The method to be used for LRP.
            start_layer (`int`):
                The index of the layer to start from.
            device (`str`):
                Model device.

        Returns:
            (`torch.Tensor`):
                The LRP tensor.
        """
        if device is None:
            device = 'cuda' if torch.cuda.is_available() else 'cpu'
        output = self.model(input_tensor)
        kwargs = {'alpha': 1}
        if index is None:
            index = np.argmax(output.cpu().data.numpy(), axis=-1)

        one_hot = np.zeros((1, output.size()[-1]), dtype=np.float32)
        one_hot[0, index] = 1
        one_hot_vector = one_hot
        one_hot = torch.from_numpy(one_hot).requires_grad_(True).to(device)
        one_hot = torch.sum(one_hot * output).to(device)

        self.model.zero_grad()
        one_hot.backward(retain_graph=True)

        return self.model.relprop(torch.tensor(one_hot_vector).to(input_tensor.device), method=method,
                                  start_layer=start_layer, **kwargs)
Generate LRP for a specific layer.
Args:
input_tensor (`nn.Module`):
The input tensor to the model.
index (`int`):
The index of the layer to be visualized.
method (`str`):
The method to be used for LRP.
start_layer (`int`):
The index of the layer to start from.
device (`str`):
Model device.

Returns:
(`torch.Tensor`):
The LRP tensor.
towhee/models/visualization/transformer_visualization.py