Unverified Commit 1af766e1 authored by Matt's avatar Matt Committed by GitHub
Browse files

Add version check for Jinja (#27403)



* Add version check for Jinja

* Update src/transformers/tokenization_utils_base.py
Co-authored-by: default avataramyeroberts <22614925+amyeroberts@users.noreply.github.com>

* make fixup

---------
Co-authored-by: default avataramyeroberts <22614925+amyeroberts@users.noreply.github.com>
parent 2422c38d
...@@ -1762,11 +1762,17 @@ class PreTrainedTokenizerBase(SpecialTokensMixin, PushToHubMixin): ...@@ -1762,11 +1762,17 @@ class PreTrainedTokenizerBase(SpecialTokensMixin, PushToHubMixin):
@lru_cache @lru_cache
def _compile_jinja_template(self, chat_template): def _compile_jinja_template(self, chat_template):
try: try:
import jinja2
from jinja2.exceptions import TemplateError from jinja2.exceptions import TemplateError
from jinja2.sandbox import ImmutableSandboxedEnvironment from jinja2.sandbox import ImmutableSandboxedEnvironment
except ImportError: except ImportError:
raise ImportError("apply_chat_template requires jinja2 to be installed.") raise ImportError("apply_chat_template requires jinja2 to be installed.")
if version.parse(jinja2.__version__) <= version.parse("3.0.0"):
raise ImportError(
"apply_chat_template requires jinja2>=3.0.0 to be installed. Your version is " f"{jinja2.__version__}."
)
def raise_exception(message): def raise_exception(message):
raise TemplateError(message) raise TemplateError(message)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment