Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name '_expand_mask' #571

Closed
Nyuo70 opened this issue Nov 4, 2023 · 15 comments
Closed

cannot import name '_expand_mask' #571

Nyuo70 opened this issue Nov 4, 2023 · 15 comments

Comments

@Nyuo70
Copy link

Nyuo70 commented Nov 4, 2023

When I try to execute train.py, I encounter the following error:
ImportError: cannot import name '_expand_mask' from 'transformers.models.clip.modeling_clip' (/home/tmp/onishi3n/Honki/lib/python3.10/site-packages/transformers/models/clip/modeling_clip.py)

@boop-yyt
Copy link

boop-yyt commented Nov 6, 2023

After updating the "transformers" version to either 4.28 or 4.31, the issue was resolved.

@Nyuo70
Copy link
Author

Nyuo70 commented Nov 6, 2023

Thank you!

@Nyuo70 Nyuo70 closed this as completed Nov 6, 2023
@Nyuo70
Copy link
Author

Nyuo70 commented Nov 6, 2023

resolved

@vedant001
Copy link

after updating it to transformers==4.31.0 it throws error of
RuntimeError: Failed to import diffusers.pipelines.controlnet.pipeline_controlnet_blip_diffusion because of the following error (look up to see its traceback):
cannot import name 'is_scaled_image' from 'transformers.image_utils'

@Cuppinono
Copy link

me too, I have this question

@Preciousrs
Copy link

me too, I have this question
Do you resolve this question?

@qiangtang2017
Copy link

transformers 4.31.0 is ok

@vedant001
Copy link

pip install diffusers==0.15.0
try above line
@Cuppinono @Preciousrs

@Abecid
Copy link

Abecid commented Dec 5, 2023

I am getting this error with transformers 4.35.2

@Hambaobao
Copy link

ImportError: cannot import name '_expand_mask' from 'transformers.models.bloom.modeling_bloom' (/usr/local/lib/python3.9/dist-packages/transformers/models/bloom/modeling_bloom.py)
I got this error with transformers 4.36.1.

@ghoshsubh
Copy link

ImportError: cannot import name '_expand_mask' from 'transformers.models.bloom.modeling_bloom' (/usr/local/lib/python3.9/dist-packages/transformers/models/bloom/modeling_bloom.py) I got this error with transformers 4.36.1.

I have the same error with transformers 4.36.2

@SaikoujiAsahi
Copy link

I solve the error with transformers 4.33.0

@iwannabewater
Copy link

I solve the error with transformers 4.33.0I solved the error with transformers 4.33.0

Thx, this works for me!

@maulikmadhavi
Copy link

Copy the function definition from previous transformer libraries

# Copied from transformers.models.bart.modeling_bart._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)

Then install using python setup.py install.

Btw I have already created pull request, refer to my cloned version https://github.com/maulikmadhavi/LAVIS/tree/patch-requirements. Thanks

@Deephug969
Copy link

transformers 4.31.0 is ok!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests