Skip to content

An optimization for WeightsEnum #5225

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

Merged
merged 1 commit into from
Jan 20, 2022
Merged

Conversation

yoshitomo-matsubara
Copy link
Contributor

@yoshitomo-matsubara yoshitomo-matsubara commented Jan 19, 2022

As partly discussed in #5088 with @datumbox, the current WegithsEnum class checks if a given str is a member of the class in an iterative way as follows:

    @classmethod
    def from_str(cls, value: str) -> "WeightsEnum":
        for k, v in cls.__members__.items():
            if k == value:
                return v
        raise ValueError(f"Invalid value {value} for enum {cls.__name__}.")

Since __members__ is an instance of mappingproxy, we can check it in an efficient way like we do with a dict:

    @classmethod
    def from_str(cls, value: str) -> "WeightsEnum":
        if value in cls.__members__:
            return cls.__members__[value]
        raise ValueError(f"Invalid value {value} for enum {cls.__name__}.")

cc @datumbox @bjuncek

@facebook-github-bot
Copy link

Hi @yoshitomo-matsubara!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot
Copy link

facebook-github-bot commented Jan 19, 2022

💊 CI failures summary and remediations

As of commit 638f705 (more details on the Dr. CI page):


None of the CI failures appear to be your fault 💚



🚧 1 ongoing upstream failure:

These were probably caused by upstream breakages that are not fixed yet.


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

@yoshitomo-matsubara LGTM, thanks!

@datumbox
Copy link
Contributor

@yoshitomo-matsubara You will need to complete the CLA before I can merge this. Just follow the bot's instructions at #5225 (comment) :)

@yoshitomo-matsubara
Copy link
Contributor Author

@datumbox
My pleasure :)

I signed up the CLA with this github account, but they have not recognized it yet

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@yoshitomo-matsubara
Copy link
Contributor Author

@datumbox
It looks like the bot just recognized my CLA sign up

@datumbox
Copy link
Contributor

@yoshitomo-matsubara Sometimes it takes a bit of time for the bot to "see" the change. Thanks for the contribution!

@datumbox datumbox merged commit f670152 into pytorch:main Jan 20, 2022
facebook-github-bot pushed a commit that referenced this pull request Jan 26, 2022
Reviewed By: jdsgomes, prabhat00155

Differential Revision: D33739384

fbshipit-source-id: 705c72213fd211e3bd3c25225dde402138a23000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants