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

Find another way to disable grad in tests #172

Open
lkct opened this issue Dec 15, 2023 · 3 comments
Open

Find another way to disable grad in tests #172

lkct opened this issue Dec 15, 2023 · 3 comments
Labels
testing Related to (unit) testing the library

Comments

@lkct
Copy link
Member

lkct commented Dec 15, 2023

Ref:

I'm now against the solution to #87 by #126 on no_grad, as partially reverted here.

Reason: globally disabling grad is counter-intuitive and can waste time in debugging tests to look for missing grad, especially now when we have differential functionals.

Alternative: if a model does not need grad in unit tests, we can use nn.Module.requires_grad_(False) to disable grad for this module's params.

@lkct lkct added the testing Related to (unit) testing the library label Dec 15, 2023
@loreloc
Copy link
Member

loreloc commented Jun 11, 2024

I think more than 90% of tests will not require computing gradients. So, I still think a good default setting is gradients in tests turned off. Keeping this for now as we have still to write many tests, but it might be closed.

@lkct
Copy link
Member Author

lkct commented Sep 25, 2024

Just to note that I encountered this again 😢, though it quickly came to me to check if gradient is enabled (because it's not the first time).

Perhaps even if we're keeping the behaviour, we should add smth to docs/faqs/dev notes to remind people.

PS: currently we lack tests for circuit training which also needs grad

@andreasgrv
Copy link
Collaborator

Maybe can use a py.test fixture for this:

https://docs.pytest.org/en/6.2.x/fixture.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Related to (unit) testing the library
Projects
None yet
Development

No branches or pull requests

3 participants