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

Remove efficientnet-pytorch dependency #1018

Closed
wants to merge 1 commit into from

Conversation

adamjstewart
Copy link
Collaborator

I first mentioned this in #918, but we should really remove efficientnet-pytorch for the following reasons:

  • It is no longer receiving bug fixes (last commit is from over 4 years ago)
  • It does not have wheels on PyPI (makes installation challenging due to missing setuptools dependency)
  • All of the models it provides are already available in the well-maintained timm library
  • Fewer lines of code in SMP that we need to maintain without fewer features

If we need to ensure backwards compatibility, we can add aliases to the timm implementations.

P.S. I'm also planning on doing this for as many of our other dependencies as I can. I'll wait to see if this PR gets any traction before starting on pretrainedmodels next.

Copy link

codecov bot commented Jan 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
segmentation_models_pytorch/encoders/__init__.py 85.88% <ø> (-0.33%) ⬇️

... and 1 file with indirect coverage changes

@qubvel
Copy link
Collaborator

qubvel commented Jan 7, 2025

Hey @adamjstewart! Thanks for working on it! Yeah, in order to remove it we have to ensure backward compatibility with existing timm backbones + add an aliases, otherwise we can copy-paste existing code directly to the lib or define a weight-loading hook

@adamjstewart
Copy link
Collaborator Author

Let me see if efficientnet-pytorch weights can be loaded into a timm backbone. If not, would that be a deal breaker? I.e., if the API remains the same (no code changes required) but the weights change from efficientnet-pytorch to timm (thus breaking reproducibility) would that be an issue?

@qubvel
Copy link
Collaborator

qubvel commented Jan 8, 2025

Yes, I don't want some users to have issues with weights loading while they update to a newer version. EfficientNet especially, because it is a very popular backbone. On our side, there were no issues with this library, so I don't feel like we need to cause inconvenience just to remove the dependency. The solution might be to maintain it on our side (copy-paste code) or introduce a load hook.

@adamjstewart
Copy link
Collaborator Author

Maintaining it on our side would also be fine with me, although I would still like to deprecate it in favor of timm in the long run.

@qubvel
Copy link
Collaborator

qubvel commented Jan 8, 2025

Deprecation in the long run is fine with me as well 👍

@adamjstewart
Copy link
Collaborator Author

Tried investigating this but the timm and efficientnet-pytorch implementations are sufficiently different that I don't think we can easily remap the keys. I think we should simply deprecate efficientnet-pytorch (and possibly vendor it). Thoughts?

How long would you be comfortable waiting before removing? I usually wait one minor release, so remove it in 0.5.0. Not sure what release cadence you would like, I usually do a minor release every 6 months so I can add new features more often.

@qubvel
Copy link
Collaborator

qubvel commented Jan 11, 2025

Let's move to our code-base, efficientnet seems to be a popular architecture, so I am not sure we can deprecate it quickly, I would better maintain it for a while and force users to use tu- version, at least 3 releases

@qubvel
Copy link
Collaborator

qubvel commented Jan 12, 2025

I am going to move all encoder checkpoints to the HF Hub. This will allow us to see the download statistics and potentially deprecate them more aggressively if there is no usage, or wait until usage decreases, prioritizing the timm-universal encoder. Although it does not solve the problem entirely, as there is no way to see how many pre-trained checkpoints users already have. Also it might be that the ported version can be a bit more optimized for depths less than 5. This is because the later stages are not executed for the ported versions, as opposed to timm.

@adamjstewart
Copy link
Collaborator Author

Do you want to open a PR to vendor efficientnet-pytorch (and possibly pretrainedmodels)? Or do we just deprecate them and wait until HF Hub download metrics taper off? I've never vendored a dep before so not sure what code/license changes are required. Efficientnet-pytorch is Apache-2.0 and pretrainedmodels is BSD-3-Clause.

@qubvel
Copy link
Collaborator

qubvel commented Jan 12, 2025

No pull requests are needed, I just want to replace download links in our source code. The weight loading is managed on our side.

Regarding the license: I suppose we can just add a header to the files containing the code, for example, for pretrainedmodels.pytorch:
https://github.com/Cadene/pretrained-models.pytorch?tab=BSD-3-Clause-1-of-file#readme

Additionally, add a note in our License folder.

@adamjstewart
Copy link
Collaborator Author

Where would the vendored code live? How would it be imported? Do you want a segmentation_models_pytorch/_vendor directory containing everything?

@qubvel
Copy link
Collaborator

qubvel commented Jan 12, 2025

It's better to put it in the encoders/ folder. As you can see with the mix_transformer, Nvidia's code exists in the same file as the encoder itself. I'm not sure if it's correct to mix it, but there have been no complaints regarding that.

@adamjstewart
Copy link
Collaborator Author

Will wait until #1031 is merged and then try vendor these in a separate PR. Do you want the entire source code of https://github.com/lukemelas/EfficientNet-PyTorch/tree/master/efficientnet_pytorch in segmentation_models_pytorch/encoders/efficientnet.py (the entire file would then become under the Apache license) or in a separate file like _efficientnet.py to keep the separation clear?

@adamjstewart adamjstewart deleted the deps/efficientnet branch January 15, 2025 10:58
@qubvel
Copy link
Collaborator

qubvel commented Jan 15, 2025

Ok, lets put it into _efficientnet.py, sounds good!

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