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

Fix doc example: mask_time_indices (numpy) has no attribute 'to' #15033

Merged
merged 4 commits into from
Jan 5, 2022

Conversation

ydshieh
Copy link
Collaborator

@ydshieh ydshieh commented Jan 4, 2022

What does this PR do?

In speech to text models, there are doc examples

    >>> mask_time_indices = _compute_mask_indices((batch_size, sequence_length), mask_prob=0.2, mask_length=2)
    >>> with torch.no_grad():
    ...     outputs = model(input_values, mask_time_indices=mask_time_indices)

which gives numpy.ndarray, and the following line fails

mask_time_indices = mask_time_indices.to(torch.bool)

with AttributeError: 'numpy.ndarray' object has no attribute 'to'.

This PR add

mask_time_indices = torch.tensor(mask_time_indices, device=input_values.device, dtype=torch.bool)

in the examples to make them work.

Who can review?

@patrickvonplaten

@patrickvonplaten
Copy link
Contributor

Thank you!

@patrickvonplaten patrickvonplaten merged commit e34dd05 into huggingface:master Jan 5, 2022
stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jan 6, 2022
…gingface#15033)

* fix doc example - AttributeError: 'numpy.ndarray' object has no attribute 'to'

* fix more

* Apply suggestions from code review

* Update src/transformers/models/unispeech/modeling_unispeech.py

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
@ydshieh ydshieh deleted the fix_doc_example_010 branch May 5, 2022 10:41
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

Successfully merging this pull request may close these issues.

2 participants