mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-25 23:38:59 +06:00
Add version check for Jinja (#27403)
* Add version check for Jinja * Update src/transformers/tokenization_utils_base.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * make fixup --------- Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
This commit is contained in:
parent
2422c38de6
commit
1af766e104
@ -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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user