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
d104dd46
Unverified
Commit
d104dd46
authored
Dec 08, 2021
by
Stas Bekman
Committed by
GitHub
Dec 08, 2021
Browse files
[trainer] support UserDict inputs (torch-nightly) (#14688)
parent
12286612
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
2 deletions
+3
-2
src/transformers/trainer.py
src/transformers/trainer.py
+3
-2
No files found.
src/transformers/trainer.py
View file @
d104dd46
...
...
@@ -27,6 +27,7 @@ import shutil
import
sys
import
time
import
warnings
from
collections.abc
import
Mapping
from
pathlib
import
Path
from
typing
import
TYPE_CHECKING
,
Any
,
Callable
,
Dict
,
List
,
Optional
,
Tuple
,
Union
...
...
@@ -1813,8 +1814,8 @@ class Trainer:
"""
Prepares one :obj:`data` before feeding it to the model, be it a tensor or a nested list/dictionary of tensors.
"""
if
isinstance
(
data
,
dict
):
return
type
(
data
)(
**
{
k
:
self
.
_prepare_input
(
v
)
for
k
,
v
in
data
.
items
()})
if
isinstance
(
data
,
Mapping
):
return
type
(
data
)({
k
:
self
.
_prepare_input
(
v
)
for
k
,
v
in
data
.
items
()})
elif
isinstance
(
data
,
(
tuple
,
list
)):
return
type
(
data
)(
self
.
_prepare_input
(
v
)
for
v
in
data
)
elif
isinstance
(
data
,
torch
.
Tensor
):
...
...
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