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
854a0d52
Unverified
Commit
854a0d52
authored
Feb 04, 2022
by
Sanchit Gandhi
Committed by
GitHub
Feb 04, 2022
Browse files
Handle PyTorch to Flax conversion of 1D convolutions (#15519)
parent
486260c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
0 deletions
+6
-0
src/transformers/modeling_flax_pytorch_utils.py
src/transformers/modeling_flax_pytorch_utils.py
+6
-0
No files found.
src/transformers/modeling_flax_pytorch_utils.py
View file @
854a0d52
...
@@ -88,6 +88,12 @@ def rename_key_and_reshape_tensor(
...
@@ -88,6 +88,12 @@ def rename_key_and_reshape_tensor(
pt_tensor
=
pt_tensor
.
transpose
(
2
,
3
,
1
,
0
)
pt_tensor
=
pt_tensor
.
transpose
(
2
,
3
,
1
,
0
)
return
renamed_pt_tuple_key
,
pt_tensor
return
renamed_pt_tuple_key
,
pt_tensor
# conv1d layer
renamed_pt_tuple_key
=
pt_tuple_key
[:
-
1
]
+
(
"kernel"
,)
if
pt_tuple_key
[
-
1
]
==
"weight"
and
pt_tensor
.
ndim
==
3
and
not
is_key_or_prefix_key_in_dict
(
pt_tuple_key
):
pt_tensor
=
pt_tensor
.
transpose
(
2
,
1
,
0
)
return
renamed_pt_tuple_key
,
pt_tensor
# linear layer
# linear layer
renamed_pt_tuple_key
=
pt_tuple_key
[:
-
1
]
+
(
"kernel"
,)
renamed_pt_tuple_key
=
pt_tuple_key
[:
-
1
]
+
(
"kernel"
,)
if
pt_tuple_key
[
-
1
]
==
"weight"
and
not
is_key_or_prefix_key_in_dict
(
pt_tuple_key
):
if
pt_tuple_key
[
-
1
]
==
"weight"
and
not
is_key_or_prefix_key_in_dict
(
pt_tuple_key
):
...
...
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