Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
cbaaa2f6
Unverified
Commit
cbaaa2f6
authored
Jan 19, 2023
by
Joao Gante
Committed by
GitHub
Jan 19, 2023
Browse files
Flax dtype-dependent numerical masking (#21197)
parent
0b86e330
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
2 deletions
+2
-2
templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/modeling_flax_{{cookiecutter.lowercase_modelname}}.py
...e}}/modeling_flax_{{cookiecutter.lowercase_modelname}}.py
+2
-2
No files found.
templates/adding_a_new_model/cookiecutter-template-{{cookiecutter.modelname}}/modeling_flax_{{cookiecutter.lowercase_modelname}}.py
View file @
cbaaa2f6
...
@@ -312,7 +312,7 @@ class Flax{{cookiecutter.camelcase_modelname}}SelfAttention(nn.Module):
...
@@ -312,7 +312,7 @@ class Flax{{cookiecutter.camelcase_modelname}}SelfAttention(nn.Module):
attention_bias
=
lax
.
select
(
attention_bias
=
lax
.
select
(
attention_mask
>
0
,
attention_mask
>
0
,
jnp
.
full
(
attention_mask
.
shape
,
0.0
).
astype
(
self
.
dtype
),
jnp
.
full
(
attention_mask
.
shape
,
0.0
).
astype
(
self
.
dtype
),
jnp
.
full
(
attention_mask
.
shape
,
-
1e10
).
astype
(
self
.
dtype
),
jnp
.
full
(
attention_mask
.
shape
,
jnp
.
finfo
(
self
.
dtype
).
min
).
astype
(
self
.
dtype
),
)
)
else
:
else
:
attention_bias
=
None
attention_bias
=
None
...
@@ -1859,7 +1859,7 @@ class Flax{{cookiecutter.camelcase_modelname}}Attention(nn.Module):
...
@@ -1859,7 +1859,7 @@ class Flax{{cookiecutter.camelcase_modelname}}Attention(nn.Module):
attention_bias
=
lax
.
select
(
attention_bias
=
lax
.
select
(
attention_mask
>
0
,
attention_mask
>
0
,
jnp
.
full
(
attention_mask
.
shape
,
0.0
).
astype
(
self
.
dtype
),
jnp
.
full
(
attention_mask
.
shape
,
0.0
).
astype
(
self
.
dtype
),
jnp
.
full
(
attention_mask
.
shape
,
float
(
"-inf"
)
).
astype
(
self
.
dtype
),
jnp
.
full
(
attention_mask
.
shape
,
jnp
.
finfo
(
self
.
dtype
).
min
).
astype
(
self
.
dtype
),
)
)
else
:
else
:
attention_bias
=
None
attention_bias
=
None
...
...
Prev
1
2
Next
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