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
1a92bc57
Unverified
Commit
1a92bc57
authored
Nov 21, 2021
by
Sylvain Gugger
Committed by
GitHub
Nov 21, 2021
Browse files
Fix dummy objects for quantization (#14478)
* Fix dummy objects for quantization * Add more models
parent
c9d2cf85
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
1 deletion
+89
-1
src/transformers/utils/dummy_flax_objects.py
src/transformers/utils/dummy_flax_objects.py
+7
-0
src/transformers/utils/dummy_pt_objects.py
src/transformers/utils/dummy_pt_objects.py
+35
-0
src/transformers/utils/dummy_pytorch_quantization_and_torch_objects.py
...ers/utils/dummy_pytorch_quantization_and_torch_objects.py
+31
-0
src/transformers/utils/dummy_tf_objects.py
src/transformers/utils/dummy_tf_objects.py
+14
-0
utils/check_dummies.py
utils/check_dummies.py
+2
-1
No files found.
src/transformers/utils/dummy_flax_objects.py
View file @
1a92bc57
...
...
@@ -477,6 +477,13 @@ class FlaxBertForNextSentencePrediction:
def
__init__
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"flax"
])
@
classmethod
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"flax"
])
def
__call__
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"flax"
])
class
FlaxBertForPreTraining
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
src/transformers/utils/dummy_pt_objects.py
View file @
1a92bc57
...
...
@@ -56,6 +56,13 @@ class TextDatasetForNextSentencePrediction:
def
__init__
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"torch"
])
@
classmethod
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"torch"
])
class
BeamScorer
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -783,6 +790,13 @@ class BertForNextSentencePrediction:
def
__init__
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"torch"
])
@
classmethod
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"torch"
])
class
BertForPreTraining
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -2106,6 +2120,13 @@ class FNetForNextSentencePrediction:
def
__init__
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"torch"
])
@
classmethod
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"torch"
])
class
FNetForPreTraining
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -3254,6 +3275,13 @@ class MegatronBertForNextSentencePrediction:
def
__init__
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"torch"
])
@
classmethod
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"torch"
])
class
MegatronBertForPreTraining
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -3373,6 +3401,13 @@ class MobileBertForNextSentencePrediction:
def
__init__
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"torch"
])
@
classmethod
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"torch"
])
class
MobileBertForPreTraining
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
src/transformers/utils/dummy_pytorch_quantization_and_torch_objects.py
View file @
1a92bc57
...
...
@@ -13,6 +13,9 @@ class QDQBertForMaskedLM:
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"pytorch_quantization"
,
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"pytorch_quantization"
,
"torch"
])
class
QDQBertForMultipleChoice
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -22,11 +25,21 @@ class QDQBertForMultipleChoice:
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"pytorch_quantization"
,
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"pytorch_quantization"
,
"torch"
])
class
QDQBertForNextSentencePrediction
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"pytorch_quantization"
,
"torch"
])
@
classmethod
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"pytorch_quantization"
,
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"pytorch_quantization"
,
"torch"
])
class
QDQBertForQuestionAnswering
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -36,6 +49,9 @@ class QDQBertForQuestionAnswering:
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"pytorch_quantization"
,
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"pytorch_quantization"
,
"torch"
])
class
QDQBertForSequenceClassification
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -45,6 +61,9 @@ class QDQBertForSequenceClassification:
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"pytorch_quantization"
,
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"pytorch_quantization"
,
"torch"
])
class
QDQBertForTokenClassification
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -54,6 +73,9 @@ class QDQBertForTokenClassification:
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"pytorch_quantization"
,
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"pytorch_quantization"
,
"torch"
])
class
QDQBertLayer
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -68,6 +90,9 @@ class QDQBertLMHeadModel:
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"pytorch_quantization"
,
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"pytorch_quantization"
,
"torch"
])
class
QDQBertModel
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -77,6 +102,9 @@ class QDQBertModel:
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"pytorch_quantization"
,
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"pytorch_quantization"
,
"torch"
])
class
QDQBertPreTrainedModel
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -86,6 +114,9 @@ class QDQBertPreTrainedModel:
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"pytorch_quantization"
,
"torch"
])
def
forward
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"pytorch_quantization"
,
"torch"
])
def
load_tf_weights_in_qdqbert
(
*
args
,
**
kwargs
):
requires_backends
(
load_tf_weights_in_qdqbert
,
[
"pytorch_quantization"
,
"torch"
])
src/transformers/utils/dummy_tf_objects.py
View file @
1a92bc57
...
...
@@ -452,6 +452,13 @@ class TFBertForNextSentencePrediction:
def
__init__
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"tf"
])
@
classmethod
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"tf"
])
def
call
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"tf"
])
class
TFBertForPreTraining
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -1774,6 +1781,13 @@ class TFMobileBertForNextSentencePrediction:
def
__init__
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"tf"
])
@
classmethod
def
from_pretrained
(
cls
,
*
args
,
**
kwargs
):
requires_backends
(
cls
,
[
"tf"
])
def
call
(
self
,
*
args
,
**
kwargs
):
requires_backends
(
self
,
[
"tf"
])
class
TFMobileBertForPreTraining
:
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
utils/check_dummies.py
View file @
1a92bc57
...
...
@@ -23,7 +23,7 @@ import re
PATH_TO_TRANSFORMERS
=
"src/transformers"
# Matches is_xxx_available()
_re_backend
=
re
.
compile
(
r
"is\_([a-z]*)_available()"
)
_re_backend
=
re
.
compile
(
r
"is\_([a-z
_
]*)_available()"
)
# Matches from xxx import bla
_re_single_line_import
=
re
.
compile
(
r
"\s+from\s+\S*\s+import\s+([^\(\s].*)\n"
)
_re_test_backend
=
re
.
compile
(
r
"^\s+if\s+is\_[a-z]*\_available\(\)"
)
...
...
@@ -131,6 +131,7 @@ def create_dummy_object(name, backend_name):
"ForConditionalGeneration"
,
"ForMaskedLM"
,
"ForMultipleChoice"
,
"ForNextSentencePrediction"
,
"ForObjectDetection"
,
"ForQuestionAnswering"
,
"ForSegmentation"
,
...
...
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