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

Refactor tests #1011

Merged
merged 50 commits into from
Dec 23, 2024
Merged

Refactor tests #1011

merged 50 commits into from
Dec 23, 2024

Conversation

qubvel
Copy link
Collaborator

@qubvel qubvel commented Dec 22, 2024

The idea is to:

  1. make tests a bit more modular and flexible
  2. speedup
  3. improve coverage

@qubvel qubvel marked this pull request as draft December 22, 2024 23:21
@adamjstewart
Copy link
Collaborator

Can you integrate codecov so we can actually measure codecov on every PR?

@qubvel
Copy link
Collaborator Author

qubvel commented Dec 22, 2024

Never used it before but can have a look :) Did you mean pytest-cov? Do you have any good examples for CI jobs?

@adamjstewart
Copy link
Collaborator

pytest-cov let's you calculate and report coverage, then you can create an account and upload it to https://about.codecov.io/ in CI. https://docs.codecov.com/docs/github-tutorial gives a good explanation of the steps you need to do. I've done it for a few projects and can help you get started if you get stuck.

Copy link

codecov bot commented Dec 23, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@qubvel
Copy link
Collaborator Author

qubvel commented Dec 23, 2024

Thanks! Looks like all set 👍

@qubvel qubvel marked this pull request as ready for review December 23, 2024 15:21
@qubvel qubvel requested a review from Copilot December 23, 2024 15:21

Choose a reason for hiding this comment

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

Copilot reviewed 27 out of 42 changed files in this pull request and generated no comments.

Files not reviewed (15)
  • Makefile: Language not supported
  • requirements/minimum.old: Language not supported
  • requirements/test.txt: Language not supported
  • segmentation_models_pytorch/decoders/unet/model.py: Evaluated as low risk
  • segmentation_models_pytorch/decoders/pspnet/model.py: Evaluated as low risk
  • segmentation_models_pytorch/decoders/linknet/model.py: Evaluated as low risk
  • segmentation_models_pytorch/encoders/inceptionv4.py: Evaluated as low risk
  • segmentation_models_pytorch/decoders/manet/model.py: Evaluated as low risk
  • segmentation_models_pytorch/decoders/fpn/model.py: Evaluated as low risk
  • segmentation_models_pytorch/decoders/pan/model.py: Evaluated as low risk
  • segmentation_models_pytorch/decoders/deeplabv3/model.py: Evaluated as low risk
  • segmentation_models_pytorch/decoders/upernet/model.py: Evaluated as low risk
  • segmentation_models_pytorch/decoders/segformer/model.py: Evaluated as low risk
  • segmentation_models_pytorch/decoders/unetplusplus/model.py: Evaluated as low risk
  • segmentation_models_pytorch/init.py: Evaluated as low risk
Comments suppressed due to low confidence (1)

segmentation_models_pytorch/base/model.py:12

  • The new attribute requires_divisible_input_shape should be covered by tests to ensure its behavior is correctly validated.
requires_divisible_input_shape = True
@qubvel
Copy link
Collaborator Author

qubvel commented Dec 23, 2024

Merging it for now, the most important I think is to have full-pretrained model tests to ensure we do not break anything with updates, it's added as a separate job "logits_match". Coverage can be improved for loss and metrics in the follow-up PR or in case of new updates in these modules.

@qubvel qubvel merged commit 900ac49 into main Dec 23, 2024
14 checks passed
Copy link
Collaborator

@adamjstewart adamjstewart left a comment

Choose a reason for hiding this comment

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

Looks like it's reporting code coverage now!

@@ -8,3 +8,4 @@ timm==0.9.0
torch==1.9.0
torchvision==0.10.0
tqdm==4.42.1
Jinja2==3.0.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is Jinja2 required? I don't see any code that uses it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

save/load pretrained raises an error on huggingface_hub 0.24 and asks to install Jinja2

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

alternatively we can bump minimum version for huggingface_hub

@@ -0,0 +1,208 @@
import unittest
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why use unittest instead of pytest? unittest is more or less obsolete

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, but I like the idea of test inheritance, don't know if we can use it with pytest. But we still use pytest to collect and run tests

import torch
import unittest

from packaging.version import Version
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like we have a new test dependency on packaging, this should be added to pyproject.toml and requirements/tests.txt

Copy link
Collaborator Author

@qubvel qubvel Dec 23, 2024

Choose a reason for hiding this comment

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

Hm... I thought it's a default python package, but it probably installed with other dependency

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is not default, it is installed using pip install packaging. It may or may not be installed, we should add an explicit dependency on it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would personally use pytest fixtures for this in conftest.py so they are available to all test code without import

@qubvel
Copy link
Collaborator Author

qubvel commented Dec 23, 2024

Thanks for the review!

@qubvel
Copy link
Collaborator Author

qubvel commented Dec 23, 2024

Feel free to refactor if you know a better/cleaner way to organize tests and have bandwidth! I'm going to be mostly off for holidays up to 3rd of Jan, but this week can review/merge. Then, I think it would be great to make a new release, what do you think?

@adamjstewart
Copy link
Collaborator

Yes, would be very excited for a new release so we can start using newer timm!

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