Common Failure

import Error

Error I: Cannot find the extension library(_C.so)

Solution:

  • Make sure that the horizon_plugin_pytorch version corresponds to the cuda version.
  • In python3, find the execution path of horizon_plugin_pytorch and check for .so files in that directory. There may be multiple versions of horizon_plugin_pytorch at the same time, so you need to uninstall it and keep only the one you need.

Error II: RuntimeError: Cannot load custom ops. Please rebuild the horizon_plugin_pytorch

Solution: check if the local CUDA environment is OK, such as path, version, etc.

Module doesn't support deepcopy

Some frameworks (e.g., PyTorch Lightning) provide wrappers which do not support deepcopy around the native torch module.

Solution: Implement the __deepcopy__ method for the model.

class Model(Module):
    ...
    def __deepcopy__(self, memo):
        new_model = Model()
        new_model.xxx = self.xxx
        return new_model

RuntimeError: Only Tensors created explicitly by the user (graph leaves) support the deepcopy protocol at the moment

This error usually occurs when deepcopying a torch.nn.Module. It typically happens when certain intermediate results are stored in the model during the forward pass, and the presence of non-leaf tensors in the model causes the deepcopy error.

class Model(torch.nn.Module):
    ...
    def forward(self, x):
        # x is an input that requires gradient calculation. x.requires_grad = True
        y = x + 1

        # y is a non-leaf tensor. After assigning this to a specific attribute of the model, deepcopying the model will result in an error.
        self.yy = y

Solution: Check if there are any non-leaf tensors in the model or after the forward pass. Before saving these tensors, make sure to perform the detach operation.

class Model(torch.nn.Module):
    ...
    def forward(self, x):
        # x is an input that requires gradient calculation. x.requires_grad = True
        y = x + 1

        # y is a non-leaf tensor. Do detach operation before saving it in the model.
        self.yy = y.detach()

Error occurred during export: IndexError: list index out of range.

This error usually occurs because there are qtensor in the model's output.

Solution: Check the model output to ensure that all outputs have been dequantized.