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

fix tests float16 module losses #1809

Merged
merged 12 commits into from
Aug 19, 2022

Conversation

MrShevan
Copy link
Contributor

Changes

Fixes #1805

Type of change

  • 📚 Documentation Update
  • 🧪 Tests Cases
  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔬 New feature (non-breaking change which adds functionality)
  • 🚨 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 This change requires a documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Did you update CHANGELOG in case of a major change?

Progress

Fixed all errors when calling pytest test/losses -v --dtype=float16 --device=cuda, most caused by using float type in assert_close instead of torch.float.

I continue to think about using BaseTester and the mechanism that chooses the tolerance.

@MrShevan MrShevan changed the title fix tests fix tests float16 module losses Jul 27, 2022
@MrShevan
Copy link
Contributor Author

Progress

Fixed all errors when calling pytest test/losses -v --dtype=float16 --device=cuda, most caused by using float type in assert_close instead of torch.float.

I continue to think about using BaseTester and the mechanism that chooses the tolerance.

@MrShevan
Copy link
Contributor Author

Hi @edgarriba sorry for late, I was sick(

I researched different cases of errors for float16 tensors and there are some variations:

  1. Exceptions appear if arguments in assert_close are floats instead of tensors, so in this case selection of tolerance not possible. Most of these errors I met in test_losses.py, I fixed them by not casting to float:
    Example:
-- actual = kornia.losses.kl_div_loss_2d(input, target).item()
++ actual = kornia.losses.kl_div_loss_2d(input, target)
++ expected = torch.tensor(expected).to(device, dtype)
assert_close(actual, expected)
  1. There are fixed atol and rtol in some test cases. This also does not allow automatically to select the tolerance based on precision. So, I thought that assert_close should be method in BaseTester and don't receive as arguments rtol and atol. I implemented this mechanism of tolerance search in BaseTester and made all classes which uses assert_close as inherit from Base Tester.

I made sure all tests pass. But some tests required lower tolerance value, such as test_forth_and_back. I solved it by argument low_tolerane in assert_close method, but maybe there is a better solution.

@MrShevan MrShevan marked this pull request as ready for review August 12, 2022 10:00
Copy link
Member

@edgarriba edgarriba left a comment

Choose a reason for hiding this comment

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

This is an amazing improvement. I'm missing just a small thing here to somehow mark the tests we want to include in the ci. For example, to already include the testing of the functionality that already supports for half precision. Possibly imporove some logics here: https://github.com/kornia/kornia/blob/master/conftest.py

We can merge this PR and improve later

kornia/testing/__init__.py Outdated Show resolved Hide resolved
test/augmentation/test_augmentation.py Outdated Show resolved Hide resolved
kornia/testing/__init__.py Outdated Show resolved Hide resolved
@MrShevan
Copy link
Contributor Author

MrShevan commented Aug 12, 2022

@edgarriba I am very pleased to hear your feedback! :)
I will work a little more on this PR (I saw some errors when you run ci) and I will think how to improve conftest.py.

@MrShevan
Copy link
Contributor Author

MrShevan commented Aug 14, 2022

@edgarriba I've done in this PR all I wanted) Now it could be merged from my side.

I couldn't get an idea of how to ark all ready tests, but I added functionality to skip all tests, which not working for half-precision. I believe we can run CI tests by modules. I have convinced that all modules I have changed working with half-precision.

I think I can fix all the rest of modules in my following PRs :)

Augmentation

pytest test/augmentation/test_augmentation.py -v --device cuda --dtype float16
...
========= 198 passed, 86 skipped, 16 xfailed, 10 warnings in 16.89s =========

Color

pytest test/color/* -v --device cuda --dtype float16
...
========= 281 passed, 11 skipped in 12.98s =========

Enhance

pytest test/enhance/*  -v --device cuda --dtype float16
...
========= 266 passed, 62 skipped, 1 warning in 16.48s =========

Losses

pytest test/losses/* -v --device cuda --dtype float16
...
========= 120 passed, 1 warning in 14.77s =========

Anton Shevtsov added 2 commits August 14, 2022 12:03
@MrShevan MrShevan mentioned this pull request Aug 15, 2022
12 tasks
@edgarriba edgarriba enabled auto-merge (squash) August 17, 2022 09:00
@MrShevan
Copy link
Contributor Author

I see failings in checks :(
Looks like I have different package versions at my local ... I investigate the nature of these errors.

auto-merge was automatically disabled August 17, 2022 19:09

Head branch was pushed to by a user without write access

@MrShevan
Copy link
Contributor Author

@edgarriba Could you approve running workflows for tests?

@edgarriba edgarriba enabled auto-merge (squash) August 19, 2022 09:25
@edgarriba edgarriba merged commit c8bef0d into kornia:master Aug 19, 2022
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.

Configure rtol and atol parameters to pass tests on the losses module
2 participants