Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
11426641
Unverified
Commit
11426641
authored
Mar 30, 2023
by
Roy Hvaara
Committed by
GitHub
Mar 30, 2023
Browse files
Guard imports of PreTrainedTokenizerFast on is_tokenizers_available (#22285)
Guard imports that use the tokenizers library
parent
4d7a5b5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
3 deletions
+11
-3
src/transformers/models/auto/tokenization_auto.py
src/transformers/models/auto/tokenization_auto.py
+6
-1
src/transformers/pipelines/__init__.py
src/transformers/pipelines/__init__.py
+5
-2
No files found.
src/transformers/models/auto/tokenization_auto.py
View file @
11426641
...
@@ -24,7 +24,6 @@ from ...configuration_utils import PretrainedConfig
...
@@ -24,7 +24,6 @@ from ...configuration_utils import PretrainedConfig
from
...dynamic_module_utils
import
get_class_from_dynamic_module
from
...dynamic_module_utils
import
get_class_from_dynamic_module
from
...tokenization_utils
import
PreTrainedTokenizer
from
...tokenization_utils
import
PreTrainedTokenizer
from
...tokenization_utils_base
import
TOKENIZER_CONFIG_FILE
from
...tokenization_utils_base
import
TOKENIZER_CONFIG_FILE
from
...tokenization_utils_fast
import
PreTrainedTokenizerFast
from
...utils
import
cached_file
,
extract_commit_hash
,
is_sentencepiece_available
,
is_tokenizers_available
,
logging
from
...utils
import
cached_file
,
extract_commit_hash
,
is_sentencepiece_available
,
is_tokenizers_available
,
logging
from
..encoder_decoder
import
EncoderDecoderConfig
from
..encoder_decoder
import
EncoderDecoderConfig
from
.auto_factory
import
_LazyAutoMapping
from
.auto_factory
import
_LazyAutoMapping
...
@@ -37,6 +36,12 @@ from .configuration_auto import (
...
@@ -37,6 +36,12 @@ from .configuration_auto import (
)
)
if
is_tokenizers_available
():
from
...tokenization_utils_fast
import
PreTrainedTokenizerFast
else
:
PreTrainedTokenizerFast
=
None
logger
=
logging
.
get_logger
(
__name__
)
logger
=
logging
.
get_logger
(
__name__
)
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
...
...
src/transformers/pipelines/__init__.py
View file @
11426641
...
@@ -32,7 +32,6 @@ from ..models.auto.image_processing_auto import IMAGE_PROCESSOR_MAPPING, AutoIma
...
@@ -32,7 +32,6 @@ from ..models.auto.image_processing_auto import IMAGE_PROCESSOR_MAPPING, AutoIma
from
..models.auto.modeling_auto
import
AutoModelForDepthEstimation
from
..models.auto.modeling_auto
import
AutoModelForDepthEstimation
from
..models.auto.tokenization_auto
import
TOKENIZER_MAPPING
,
AutoTokenizer
from
..models.auto.tokenization_auto
import
TOKENIZER_MAPPING
,
AutoTokenizer
from
..tokenization_utils
import
PreTrainedTokenizer
from
..tokenization_utils
import
PreTrainedTokenizer
from
..tokenization_utils_fast
import
PreTrainedTokenizerFast
from
..utils
import
(
from
..utils
import
(
HUGGINGFACE_CO_RESOLVE_ENDPOINT
,
HUGGINGFACE_CO_RESOLVE_ENDPOINT
,
is_kenlm_available
,
is_kenlm_available
,
...
@@ -139,9 +138,13 @@ if is_torch_available():
...
@@ -139,9 +138,13 @@ if is_torch_available():
AutoModelForZeroShotImageClassification
,
AutoModelForZeroShotImageClassification
,
AutoModelForZeroShotObjectDetection
,
AutoModelForZeroShotObjectDetection
,
)
)
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
..modeling_tf_utils
import
TFPreTrainedModel
from
..modeling_tf_utils
import
TFPreTrainedModel
from
..modeling_utils
import
PreTrainedModel
from
..modeling_utils
import
PreTrainedModel
from
..tokenization_utils_fast
import
PreTrainedTokenizerFast
logger
=
logging
.
get_logger
(
__name__
)
logger
=
logging
.
get_logger
(
__name__
)
...
@@ -495,7 +498,7 @@ def pipeline(
...
@@ -495,7 +498,7 @@ def pipeline(
task
:
str
=
None
,
task
:
str
=
None
,
model
:
Optional
=
None
,
model
:
Optional
=
None
,
config
:
Optional
[
Union
[
str
,
PretrainedConfig
]]
=
None
,
config
:
Optional
[
Union
[
str
,
PretrainedConfig
]]
=
None
,
tokenizer
:
Optional
[
Union
[
str
,
PreTrainedTokenizer
,
PreTrainedTokenizerFast
]]
=
None
,
tokenizer
:
Optional
[
Union
[
str
,
PreTrainedTokenizer
,
"
PreTrainedTokenizerFast
"
]]
=
None
,
feature_extractor
:
Optional
[
Union
[
str
,
PreTrainedFeatureExtractor
]]
=
None
,
feature_extractor
:
Optional
[
Union
[
str
,
PreTrainedFeatureExtractor
]]
=
None
,
image_processor
:
Optional
[
Union
[
str
,
BaseImageProcessor
]]
=
None
,
image_processor
:
Optional
[
Union
[
str
,
BaseImageProcessor
]]
=
None
,
framework
:
Optional
[
str
]
=
None
,
framework
:
Optional
[
str
]
=
None
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment