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

Feat set seed #929

Merged
merged 9 commits into from
Apr 15, 2024
Merged

Feat set seed #929

merged 9 commits into from
Apr 15, 2024

Conversation

LeonardoViotti
Copy link
Collaborator

Feature to set random state for reproducible training. Solving #576

Draft fuinction that worked on my initial testing using OpSo 0.9.1, but still needs testing on 0.10.1
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can go in opensoundscape/utils.py rather than being a separate module

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, but Let the unit test separate because I didn't want to mess-up test_utils.py.


import pytest

pytestmark = pytest.mark.parametrize("input", [1, 11, 13, 42, 59, 666, 1234])
Copy link
Collaborator

Choose a reason for hiding this comment

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

what does this do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a global version of the @pytest.mark.parametrize decorator to use the list as inputs for all functions in the script. See https://docs.pytest.org/en/7.3.x/how-to/parametrize.html for more explanation.

import random


def seed(seed, verbose=True):
Copy link
Collaborator

Choose a reason for hiding this comment

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

needs a docstring, with Args and Return fields; see other functions for examples

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

opensoundscape/seed.py Outdated Show resolved Hide resolved
@@ -329,3 +330,25 @@ def generate_opacity_colormaps(
colormaps.append(cmap)

return colormaps


import numpy as np
Copy link
Collaborator

Choose a reason for hiding this comment

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

imports should always be at the top of a file. VS Code will help detect duplicate imports

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, sorry, missed that. Just pushed the correction.

model_resnet3 = cnn_architectures.resnet18(num_classes=10, weights=None)
lw3 = model_resnet3.layer1[0].conv1.weight

assert torch.all(lw1 == lw2) & torch.any(lw1 != lw3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't understand the logic here, can you add a comment? is the any asserting that none of the weights should be the same? That doesn't seem like the correct logic, rather we want to assert that the entire array isn't equal to the other?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In summary, also assert that at least one element is different if different seeds. Added as a comment in tests/test_utils.py.

@sammlapp sammlapp merged commit 5f6ee99 into develop Apr 15, 2024
3 of 6 checks passed
@sammlapp sammlapp deleted the feat_set_seed branch April 15, 2024 17:01
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