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

Cleanup _get_enum_from_fn implementation in _api.py #8847

Open
GdoongMathew opened this issue Jan 11, 2025 · 1 comment · May be fixed by #8852
Open

Cleanup _get_enum_from_fn implementation in _api.py #8847

GdoongMathew opened this issue Jan 11, 2025 · 1 comment · May be fixed by #8852

Comments

@GdoongMathew
Copy link
Contributor

🚀 The feature

In the current _get_enum_from_fn implementation, there are two things that can be refined.

  1. https://github.com/pytorch/vision/blob/main/torchvision/models/_api.py#L167-L171, signature function was called twice, but I think it only needs one call.
def _get_enum_from_fn(fn: Callable) -> Type[WeightsEnum]:
    sig = signature(fn)
    if "weights" not in sig.parameters:
        raise ValueError("The method is missing the 'weights' argument.")

    ann = sig.parameters["weights"].annotation    # <-- here
  1. resolve the TODO at line https://github.com/pytorch/vision/blob/main/torchvision/models/_api.py#L177, since torch already removed its support from py3.8, there should be no risk making that modification.

Motivation, pitch

Just saw this and think it'd be helpful?

Alternatives

No response

Additional context

No response

@NicolasHug
Copy link
Member

NicolasHug commented Jan 13, 2025

Thanks for the report @GdoongMathew . I agree with you that this could be cleaned up, however I don't think it would lead to a significant improvement - that part of the code-base "just works" and we don't really need to touch it as it's not a hot path.

If you'd like to submit a PR though, I'll make sure to review it.

GdoongMathew added a commit to GdoongMathew/vision that referenced this issue Jan 13, 2025
@GdoongMathew GdoongMathew linked a pull request Jan 13, 2025 that will close this issue
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 a pull request may close this issue.

2 participants