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

test string casting only on first element #159

Merged
merged 7 commits into from
Jun 30, 2022

Conversation

lvwerra
Copy link
Member

@lvwerra lvwerra commented Jun 24, 2022

This addresses #153: Instead of testing on every element of a batch we only test on the first. This should reduce the latency for adding batches.

This makes the assumption that the user would pass the same type in the rest of the batch which is a fair one IMO.

@lvwerra lvwerra requested a review from lhoestq June 24, 2022 10:08
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 24, 2022

The documentation is not available anymore as the PR was closed or merged.

@lhoestq
Copy link
Member

lhoestq commented Jun 28, 2022

I think for #153 the matter is about checking the first non null element in a Sequence feature type, and not about checking the first element of a batch (though it can be complementary)

This can be done inside _enforce_nested_string_type

@lvwerra
Copy link
Member Author

lvwerra commented Jun 29, 2022

True, I guess it depends what is larger: samples ( $n$ ) in dataset or sequence length ( $s$ ). I also added that only the first element of a sequence is tested. So with this change we went from $O(n \times s)$ to $O(1)$. This decreased the time of the example in #153 from 24 to 6 seconds on my machine. You can also see in the profile that _enforce_nested_string_type is now a tiny fraction (~0.1%) of the computation (it's the narrow pink bar on the right).

Screenshot 2022-06-29 at 14 48 13

cc @NouamaneTazi

@NouamaneTazi
Copy link
Member

LGTM. I think we could clarify in the docs that using Array..D is still faster if we're working with fixed length arrays.

Copy link
Member

@lhoestq lhoestq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

(feel free to write some tests btw)

src/evaluate/module.py Outdated Show resolved Hide resolved
src/evaluate/module.py Outdated Show resolved Hide resolved
lvwerra and others added 4 commits June 30, 2022 14:52
Co-authored-by: Quentin Lhoest <42851186+lhoestq@users.noreply.github.com>
@lvwerra lvwerra merged commit bcff843 into main Jun 30, 2022
@lvwerra lvwerra deleted the improve-string-casting-checks branch June 30, 2022 15:07
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.

None yet

4 participants