I want to take the output of the forward pass and detach it to generate a matrix (that is similar to the input) using an external function (not a pytorch function), then create a loss function based on this generated matrix and the input matrix.

Yes, using other libraries or explicitly detaching the tensors won’t allow Autograd to track these operations and will thus detach the tensor from the computation graph (parameters used in previous operations also won’t gradients).
To use other libraries you could write a custom autograd.Function as described here.

Since you are returning None gradients the previous layers won’t get any valid gradients so this implementation could be seen as detaching the computation graph.