From dbf0532f13e8e77f02b92b02ede64fc812c2ad87 Mon Sep 17 00:00:00 2001 From: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Date: Thu, 18 May 2023 12:17:17 -0400 Subject: [PATCH] Properly guard PyTorch stuff (#23452) * Properly guard PyTorch stuff * [all-test] * [all-test] Fix model imports as well * Making sure StoppingCriteria is always defined * [all-test] --- src/transformers/tools/agents.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/transformers/tools/agents.py b/src/transformers/tools/agents.py index a41e93398dd..5d46ff49bc2 100644 --- a/src/transformers/tools/agents.py +++ b/src/transformers/tools/agents.py @@ -24,9 +24,8 @@ import requests from huggingface_hub import HfFolder, hf_hub_download, list_spaces -from ..generation import StoppingCriteria, StoppingCriteriaList -from ..models.auto import AutoModelForCausalLM, AutoTokenizer -from ..utils import is_openai_available, logging +from ..models.auto import AutoTokenizer +from ..utils import is_openai_available, is_torch_available, logging from .base import TASK_MAPPING, TOOL_CONFIG_FILE, Tool, load_tool, supports_remote from .prompts import CHAT_MESSAGE_PROMPT, CHAT_PROMPT_TEMPLATE, RUN_PROMPT_TEMPLATE from .python_interpreter import evaluate @@ -38,6 +37,12 @@ if is_openai_available(): import openai +if is_torch_available(): + from ..generation import StoppingCriteria, StoppingCriteriaList + from ..models.auto import AutoModelForCausalLM +else: + StoppingCriteria = object + _tools_are_initialized = False