Fix No module named 'torch' (#553)

Do not import torch unless necessary
This commit is contained in:
Youhei Sakurai 2023-07-07 17:11:11 +09:00 committed by GitHub
parent 55967a7324
commit 5ac8a053f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,7 +31,6 @@ import sys
import tempfile
import textwrap
import torch
from elastic_transport.client_utils import DEFAULT
from elasticsearch import AuthenticationException, Elasticsearch
@ -177,6 +176,8 @@ def check_cluster_version(es_client, logger):
# PyTorch was upgraded to version 1.13.1 in 8.7.
# and is incompatible with earlier versions
if major_version == 8 and minor_version < 7:
import torch
logger.error(f"Eland uses PyTorch version {torch.__version__} which is incompatible with Elasticsearch versions prior to 8.7. Please upgrade Elasticsearch to at least version 8.7")
exit(1)