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
0fdea860
Unverified
Commit
0fdea860
authored
Jul 19, 2024
by
Lucain
Committed by
GitHub
Jul 19, 2024
Browse files
Fix tests after `huggingface_hub` 0.24 (#32054)
* adapt tests * style * comment
parent
fe008d6e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
23 deletions
+36
-23
tests/trainer/test_trainer.py
tests/trainer/test_trainer.py
+36
-23
No files found.
tests/trainer/test_trainer.py
View file @
0fdea860
...
...
@@ -3739,6 +3739,7 @@ class TrainerIntegrationWithHubTester(unittest.TestCase):
def
test_push_to_hub_with_saves_each_epoch
(
self
):
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
with
self
.
assertLogs
(
level
=
"WARNING"
)
as
logs
:
trainer
=
get_regression_trainer
(
output_dir
=
os
.
path
.
join
(
tmp_dir
,
"test-trainer-epoch"
),
push_to_hub
=
True
,
...
...
@@ -3752,8 +3753,10 @@ class TrainerIntegrationWithHubTester(unittest.TestCase):
commits
=
list_repo_commits
(
f
"
{
USER
}
/test-trainer-epoch"
,
token
=
self
.
_token
)
commits
=
[
c
.
title
for
c
in
commits
]
self
.
assertIn
(
"initial commit"
,
commits
)
for
i
in
range
(
1
,
4
):
self
.
assertIn
(
f
"Training in progress, epoch
{
i
}
"
,
commits
)
self
.
assertIn
(
"Training in progress, epoch 1"
,
commits
)
self
.
assertIn
(
"Training in progress, epoch 2"
,
commits
)
# Epochs 3 and 4 are not guaranteed to be present (empty commits)
self
.
assertTrue
(
any
(
"Skipping to prevent empty commit."
in
record
.
message
for
record
in
logs
.
records
))
def
test_push_to_hub_with_saves_each_n_steps
(
self
):
num_gpus
=
max
(
1
,
backend_device_count
(
torch_device
))
...
...
@@ -3761,6 +3764,7 @@ class TrainerIntegrationWithHubTester(unittest.TestCase):
self
.
skipTest
(
reason
=
"More than 2 GPUs available"
)
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
with
self
.
assertLogs
(
level
=
"WARNING"
)
as
logs
:
trainer
=
get_regression_trainer
(
output_dir
=
os
.
path
.
join
(
tmp_dir
,
"test-trainer-step"
),
push_to_hub
=
True
,
...
...
@@ -3776,10 +3780,19 @@ class TrainerIntegrationWithHubTester(unittest.TestCase):
commits
=
[
c
.
title
for
c
in
commits
]
self
.
assertIn
(
"initial commit"
,
commits
)
# Some commits are skipped if nothing has changed
# We expect 1 commit per 5 epochs + 1 commit at the end
nb_empty_commits
=
len
(
[
record
for
record
in
logs
.
records
if
"Skipping to prevent empty commit."
in
record
.
message
]
)
nb_epoch_commits
=
len
([
commit
for
commit
in
commits
if
"Training in progress, step"
in
commit
])
# max_steps depend on the number of available GPUs
max_steps
=
math
.
ceil
(
trainer
.
args
.
num_train_epochs
*
len
(
trainer
.
get_train_dataloader
()))
for
i
in
range
(
5
,
max_steps
,
5
):
self
.
assertIn
(
f
"Training in progress, step
{
i
}
"
,
commits
)
nb_expected_commits
=
len
(
range
(
5
,
max_steps
,
5
))
# '>=' since final commit might be an empty commit as well (not deterministic)
self
.
assertGreaterEqual
(
nb_empty_commits
+
nb_epoch_commits
,
nb_expected_commits
)
@
require_tensorboard
def
test_push_to_hub_with_tensorboard_logs
(
self
):
...
...
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