Based on the error message it seems that this method assignment self.model.forward_flex = types.MethodType(forward_flex, self.model) is creating the issue.
Could you explain what this method is doing and if new tensors are created internally etc.?