Skip to content

Conversation

@theweiho
Copy link
Contributor

Revert to original implementation using std::vector and std::sort instead of templatizing std::set since profiling shows std::set taking ~5x as long as vector+sort.

@apaszke @goldsborough @colesbury @ezyang

@apaszke
Copy link
Contributor

apaszke commented Mar 20, 2018

Is std::set so much slower than std::unordered_set in this case? I wouldn't expect them to be all that different. After all both should be quite slow (as they require an allocation per element).

@theweiho
Copy link
Contributor Author

See the link in group thread for more details, but below are the relevant excerpts from line_profiler:

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
...
    67      1000      4227050   4227.1     11.3          unique_numpy = np.unique(x_numpy)
...
    71                                                   # std::set
    72      1000      9937905   9937.9     26.5          unique_cpu = torch.unique(x_cpu, use_stdset=True)
    73
    74                                                   # std::vector + sort
    75      1000      4303123   4303.1     11.5          unique_cpu = torch.unique(x_cpu, use_vector=True)
...
    87                                                   # std::unordered_set
    88      1000      1543563   1543.6      4.1          unique_cpu = torch.unique(x_cpu, sorted=False)
...
    97                                                   # std::unordered_set + vector sorting
    98      1000      2030760   2030.8      5.4          unique_cpu = torch.unique(x_cpu, sorted=True)

@apaszke apaszke merged commit a3bd7b2 into pytorch:master Mar 21, 2018
Pythongoras pushed a commit to Pythongoras/pytorch that referenced this pull request Feb 15, 2022
)

Summary:
Pull Request resolved: pytorch/glow#5913

revert D33894937 (pytorch@4f8b986) to unblock f6 build fail

Test Plan: sandcastle

Differential Revision: D34243864

fbshipit-source-id: daffc15615850e02e96d625030cd024991ad4030
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.

3 participants