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
renzhc
diffusers_dcu
Commits
3ec828d6
Unverified
Commit
3ec828d6
authored
Oct 30, 2023
by
Patrick von Platen
Committed by
GitHub
Oct 30, 2023
Browse files
Fix moved _expand_mask function (#5581)
* finish * finish
parent
9135e54e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
src/diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py
src/diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py
+15
-4
No files found.
src/diffusers/pipelines/blip_diffusion/modeling_ctx_clip.py
View file @
3ec828d6
...
@@ -19,10 +19,21 @@ from torch import nn
...
@@ -19,10 +19,21 @@ from torch import nn
from
transformers
import
CLIPPreTrainedModel
from
transformers
import
CLIPPreTrainedModel
from
transformers.modeling_outputs
import
BaseModelOutputWithPooling
from
transformers.modeling_outputs
import
BaseModelOutputWithPooling
from
transformers.models.clip.configuration_clip
import
CLIPTextConfig
from
transformers.models.clip.configuration_clip
import
CLIPTextConfig
from
transformers.models.clip.modeling_clip
import
(
from
transformers.models.clip.modeling_clip
import
CLIPEncoder
CLIPEncoder
,
_expand_mask
,
)
def
_expand_mask
(
mask
:
torch
.
Tensor
,
dtype
:
torch
.
dtype
,
tgt_len
:
Optional
[
int
]
=
None
):
"""
Expands attention_mask from `[bsz, seq_len]` to `[bsz, 1, tgt_seq_len, src_seq_len]`.
"""
bsz
,
src_len
=
mask
.
size
()
tgt_len
=
tgt_len
if
tgt_len
is
not
None
else
src_len
expanded_mask
=
mask
[:,
None
,
None
,
:].
expand
(
bsz
,
1
,
tgt_len
,
src_len
).
to
(
dtype
)
inverted_mask
=
1.0
-
expanded_mask
return
inverted_mask
.
masked_fill
(
inverted_mask
.
to
(
torch
.
bool
),
torch
.
finfo
(
dtype
).
min
)
# This is a modified version of the CLIPTextModel from transformers.models.clip.modeling_clip
# This is a modified version of the CLIPTextModel from transformers.models.clip.modeling_clip
...
...
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