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
4cdb7ee5
"src/git@developer.sourcefind.cn:OpenDAS/nni.git" did not exist on "5f3c5ffd5343c88ecd99c9ae64fbec009275f73b"
Unverified
Commit
4cdb7ee5
authored
Jul 14, 2021
by
yujun
Committed by
GitHub
Jul 13, 2021
Browse files
fix #11724 (#11897)
parent
83f02512
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
6 deletions
+8
-6
src/transformers/models/marian/modeling_tf_marian.py
src/transformers/models/marian/modeling_tf_marian.py
+4
-3
src/transformers/models/pegasus/modeling_tf_pegasus.py
src/transformers/models/pegasus/modeling_tf_pegasus.py
+4
-3
No files found.
src/transformers/models/marian/modeling_tf_marian.py
View file @
4cdb7ee5
...
@@ -151,11 +151,12 @@ class TFMarianSinusoidalPositionalEmbedding(tf.keras.layers.Layer):
...
@@ -151,11 +151,12 @@ class TFMarianSinusoidalPositionalEmbedding(tf.keras.layers.Layer):
position_enc
=
np
.
array
(
position_enc
=
np
.
array
(
[[
pos
/
np
.
power
(
10000
,
2
*
(
j
//
2
)
/
dim
)
for
j
in
range
(
dim
)]
for
pos
in
range
(
n_pos
)]
[[
pos
/
np
.
power
(
10000
,
2
*
(
j
//
2
)
/
dim
)
for
j
in
range
(
dim
)]
for
pos
in
range
(
n_pos
)]
)
)
table
=
np
.
zeros_like
(
position_enc
)
# index 0 is all zero
# index 0 is all zero
position_enc
[:,
0
:
dim
//
2
]
=
np
.
sin
(
position_enc
[:,
0
::
2
])
table
[:,
0
:
dim
//
2
]
=
np
.
sin
(
position_enc
[:,
0
::
2
])
position_enc
[:,
dim
//
2
:]
=
np
.
cos
(
position_enc
[:,
1
::
2
])
table
[:,
dim
//
2
:]
=
np
.
cos
(
position_enc
[:,
1
::
2
])
# convert to tensor
# convert to tensor
table
=
tf
.
convert_to_tensor
(
position_enc
)
table
=
tf
.
convert_to_tensor
(
table
)
tf
.
stop_gradient
(
table
)
tf
.
stop_gradient
(
table
)
return
table
return
table
...
...
src/transformers/models/pegasus/modeling_tf_pegasus.py
View file @
4cdb7ee5
...
@@ -152,11 +152,12 @@ class TFPegasusSinusoidalPositionalEmbedding(tf.keras.layers.Layer):
...
@@ -152,11 +152,12 @@ class TFPegasusSinusoidalPositionalEmbedding(tf.keras.layers.Layer):
position_enc
=
np
.
array
(
position_enc
=
np
.
array
(
[[
pos
/
np
.
power
(
10000
,
2
*
(
j
//
2
)
/
dim
)
for
j
in
range
(
dim
)]
for
pos
in
range
(
n_pos
)]
[[
pos
/
np
.
power
(
10000
,
2
*
(
j
//
2
)
/
dim
)
for
j
in
range
(
dim
)]
for
pos
in
range
(
n_pos
)]
)
)
table
=
np
.
zeros_like
(
position_enc
)
# index 0 is all zero
# index 0 is all zero
position_enc
[:,
0
:
dim
//
2
]
=
np
.
sin
(
position_enc
[:,
0
::
2
])
table
[:,
0
:
dim
//
2
]
=
np
.
sin
(
position_enc
[:,
0
::
2
])
position_enc
[:,
dim
//
2
:]
=
np
.
cos
(
position_enc
[:,
1
::
2
])
table
[:,
dim
//
2
:]
=
np
.
cos
(
position_enc
[:,
1
::
2
])
# convert to tensor
# convert to tensor
table
=
tf
.
convert_to_tensor
(
position_enc
)
table
=
tf
.
convert_to_tensor
(
table
)
tf
.
stop_gradient
(
table
)
tf
.
stop_gradient
(
table
)
return
table
return
table
...
...
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