src/transformers/pipelines/base.py/Pipeline/get_inference_context
class Pipeline:    def get_inference_context(self):
        inference_context = (
            torch.inference_mode
            if version.parse(version.parse(torch.__version__).base_version) >= version.parse("1.9.0")
            else torch.no_grad
        )
        return inference_context