Checks if gradient calculation is disabled during evaluation.
1def disable_gradient_calculation_noncompliant():
2 import torch
3 # Noncompliant: disables gradient calculation using `torch.no_grad()`.
4 with torch.no_grad():
5 model.eval()
1def disable_gradient_calculation_compliant():
2 import torch
3 # Compliant: disables gradient calculation using `torch.inference_mode()`.
4 with torch.inference_mode():
5 model.eval()