Thank you! I tried removing them and made the operations store their result in a different variable. Now, when I pass the new variable to the loss and backpropagate, there is no gradient being passed through the network. The code looks something like this:
        output = model(input)

        results = torch.zeros((batch_size, 16384))


        # Applying the custom transformation (each sample in the batch
        # undergoes the same operation but with different parameters)

        for i in range (0, batch_size):
            results[i] = measurement(output[i], i)


        results = Variable(results, requires_grad = True)

        loss = criterion(results, target)
        

        # ===================backward====================
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

Is there a reason why the flow of gradients might be getting interrupted?