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
b8809091
Unverified
Commit
b8809091
authored
Jun 10, 2022
by
Sylvain Gugger
Committed by
GitHub
Jun 10, 2022
Browse files
Fix dtype getters (#17656)
parent
fd1e6703
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
src/transformers/modeling_utils.py
src/transformers/modeling_utils.py
+6
-5
No files found.
src/transformers/modeling_utils.py
View file @
b8809091
...
...
@@ -152,7 +152,7 @@ def get_first_parameter_dtype(parameter: Union[nn.Module, GenerationMixin, "Modu
def
get_parameter_dtype
(
parameter
:
Union
[
nn
.
Module
,
GenerationMixin
,
"ModuleUtilsMixin"
]):
"""
Returns the first found floating dtype in parameters if there is one, otherwise returns the
la
st dtype it found.
Returns the first found floating dtype in parameters if there is one, otherwise returns the
fir
st dtype it found.
"""
try
:
for
t
in
parameter
.
parameters
():
...
...
@@ -160,7 +160,7 @@ def get_parameter_dtype(parameter: Union[nn.Module, GenerationMixin, "ModuleUtil
return
t
.
dtype
# if no floating dtype was found return whatever the first dtype is
else
:
return
t
.
dtype
return
next
(
parameter
.
parameters
())
.
dtype
except
StopIteration
:
# For nn.DataParallel compatibility in PyTorch 1.5
...
...
@@ -175,7 +175,8 @@ def get_parameter_dtype(parameter: Union[nn.Module, GenerationMixin, "ModuleUtil
return
tuple
[
1
].
dtype
# fallback to any dtype the model has even if not floating
else
:
return
tuple
[
1
].
dtype
first_tuple
=
next
(
gen
)
return
first_tuple
[
1
].
dtype
def
get_state_dict_float_dtype
(
state_dict
):
...
...
@@ -191,7 +192,7 @@ def get_state_dict_float_dtype(state_dict):
def
get_state_dict_dtype
(
state_dict
):
"""
Returns the first found floating dtype in `state_dict` if there is one, otherwise returns the
la
st dtype.
Returns the first found floating dtype in `state_dict` if there is one, otherwise returns the
fir
st dtype.
"""
for
t
in
state_dict
.
values
():
if
t
.
is_floating_point
():
...
...
@@ -199,7 +200,7 @@ def get_state_dict_dtype(state_dict):
# if no floating dtype was found return whatever the first dtype is
else
:
return
t
.
dtype
return
next
(
state_dict
.
values
())
.
dtype
def
convert_file_size_to_int
(
size
:
Union
[
int
,
str
]):
...
...
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