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
ce50305e
Unverified
Commit
ce50305e
authored
Dec 22, 2019
by
Aymeric Augustin
Committed by
GitHub
Dec 22, 2019
Browse files
Merge pull request #2270 from aaugustin/remove-python-2
Remove support for Python 2
parents
b6ea0f43
1a948d70
Changes
155
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
24 additions
and
45 deletions
+24
-45
tests/test_modeling_roberta.py
tests/test_modeling_roberta.py
+1
-1
tests/test_modeling_t5.py
tests/test_modeling_t5.py
+1
-1
tests/test_modeling_tf_albert.py
tests/test_modeling_tf_albert.py
+1
-1
tests/test_modeling_tf_auto.py
tests/test_modeling_tf_auto.py
+1
-1
tests/test_modeling_tf_bert.py
tests/test_modeling_tf_bert.py
+1
-1
tests/test_modeling_tf_common.py
tests/test_modeling_tf_common.py
+4
-23
tests/test_modeling_tf_ctrl.py
tests/test_modeling_tf_ctrl.py
+1
-1
tests/test_modeling_tf_distilbert.py
tests/test_modeling_tf_distilbert.py
+1
-1
tests/test_modeling_tf_gpt2.py
tests/test_modeling_tf_gpt2.py
+1
-1
tests/test_modeling_tf_openai_gpt.py
tests/test_modeling_tf_openai_gpt.py
+1
-1
tests/test_modeling_tf_roberta.py
tests/test_modeling_tf_roberta.py
+1
-1
tests/test_modeling_tf_t5.py
tests/test_modeling_tf_t5.py
+1
-1
tests/test_modeling_tf_transfo_xl.py
tests/test_modeling_tf_transfo_xl.py
+1
-1
tests/test_modeling_tf_xlm.py
tests/test_modeling_tf_xlm.py
+1
-1
tests/test_modeling_tf_xlnet.py
tests/test_modeling_tf_xlnet.py
+1
-1
tests/test_modeling_transfo_xl.py
tests/test_modeling_transfo_xl.py
+1
-1
tests/test_modeling_xlm.py
tests/test_modeling_xlm.py
+1
-1
tests/test_modeling_xlnet.py
tests/test_modeling_xlnet.py
+1
-1
tests/test_optimization.py
tests/test_optimization.py
+3
-3
tests/test_optimization_tf.py
tests/test_optimization_tf.py
+0
-2
No files found.
tests/test_modeling_roberta.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_t5.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_tf_albert.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_tf_auto.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
logging
import
unittest
...
...
tests/test_modeling_tf_bert.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_tf_common.py
View file @
ce50305e
...
...
@@ -12,13 +12,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
copy
import
os
import
random
import
shutil
import
sys
import
tempfile
from
transformers
import
is_tf_available
,
is_torch_available
...
...
@@ -32,23 +30,6 @@ if is_tf_available():
# from transformers.modeling_bert import BertModel, BertConfig, BERT_PRETRAINED_MODEL_ARCHIVE_MAP
if
sys
.
version_info
[
0
]
==
2
:
class
TemporaryDirectory
(
object
):
"""Context manager for tempfile.mkdtemp() so it's usable with "with" statement."""
def
__enter__
(
self
):
self
.
name
=
tempfile
.
mkdtemp
()
return
self
.
name
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
shutil
.
rmtree
(
self
.
name
)
else
:
TemporaryDirectory
=
tempfile
.
TemporaryDirectory
unicode
=
str
def
_config_zero_init
(
config
):
configs_no_init
=
copy
.
deepcopy
(
config
)
...
...
@@ -87,7 +68,7 @@ class TFModelTesterMixin:
model
=
model_class
(
config
)
outputs
=
model
(
inputs_dict
)
with
TemporaryDirectory
()
as
tmpdirname
:
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
model
.
save_pretrained
(
tmpdirname
)
model
=
model_class
.
from_pretrained
(
tmpdirname
)
after_outputs
=
model
(
inputs_dict
)
...
...
@@ -137,7 +118,7 @@ class TFModelTesterMixin:
self
.
assertLessEqual
(
max_diff
,
2e-2
)
# Check we can load pt model in tf and vice-versa with checkpoint => model functions
with
TemporaryDirectory
()
as
tmpdirname
:
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
pt_checkpoint_path
=
os
.
path
.
join
(
tmpdirname
,
"pt_model.bin"
)
torch
.
save
(
pt_model
.
state_dict
(),
pt_checkpoint_path
)
tf_model
=
transformers
.
load_pytorch_checkpoint_in_tf2_model
(
tf_model
,
pt_checkpoint_path
)
...
...
@@ -180,7 +161,7 @@ class TFModelTesterMixin:
model
=
model_class
(
config
)
# Let's load it from the disk to be sure we can use pretrained weights
with
TemporaryDirectory
()
as
tmpdirname
:
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
outputs
=
model
(
inputs_dict
)
# build the model
model
.
save_pretrained
(
tmpdirname
)
model
=
model_class
.
from_pretrained
(
tmpdirname
)
...
...
tests/test_modeling_tf_ctrl.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_tf_distilbert.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_tf_gpt2.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_tf_openai_gpt.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_tf_roberta.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_tf_t5.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_tf_transfo_xl.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
random
import
unittest
...
...
tests/test_modeling_tf_xlm.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_tf_xlnet.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
random
import
unittest
...
...
tests/test_modeling_transfo_xl.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
random
import
unittest
...
...
tests/test_modeling_xlm.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
...
...
tests/test_modeling_xlnet.py
View file @
ce50305e
...
...
@@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
random
import
unittest
...
...
tests/test_optimization.py
View file @
ce50305e
...
...
@@ -12,14 +12,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
,
division
,
print_function
import
os
import
tempfile
import
unittest
from
transformers
import
is_torch_available
from
.test_tokenization_common
import
TemporaryDirectory
from
.utils
import
require_torch
...
...
@@ -50,7 +50,7 @@ def unwrap_and_save_reload_schedule(scheduler, num_steps=10):
scheduler
.
step
()
lrs
.
append
(
scheduler
.
get_lr
())
if
step
==
num_steps
//
2
:
with
TemporaryDirectory
()
as
tmpdirname
:
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
file_name
=
os
.
path
.
join
(
tmpdirname
,
"schedule.bin"
)
torch
.
save
(
scheduler
.
state_dict
(),
file_name
)
...
...
tests/test_optimization_tf.py
View file @
ce50305e
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
from
transformers
import
is_tf_available
...
...
Prev
1
…
3
4
5
6
7
8
Next
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