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

Added lru caches to speed up validphys multi-replica initalization #1945

Merged
merged 6 commits into from
Feb 20, 2024

Conversation

goord
Copy link
Collaborator

@goord goord commented Feb 16, 2024

Added lru caches in validphys to accelerate multi-replica initialization

Copy link
Member

@scarlehoff scarlehoff left a comment

Choose a reason for hiding this comment

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

Thanks for this.

I think we might be able to remove freeze_args depending on produce_rules.

validphys2/src/validphys/config.py Outdated Show resolved Hide resolved
@@ -1247,6 +1249,8 @@ def parse_default_filter_rules_recorded_spec_(self, spec):
def parse_added_filter_rules(self, rules: (list, type(None)) = None):
return rules

@freeze_args
@functools.lru_cache
Copy link
Member

Choose a reason for hiding this comment

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

a note to myself to check what enters here and whether maybe the problems are related to what I see in #1678 (since if so, that won't be a problem)

Are you absolutely certain this one is needed for the multi-replica? Since in principle this function should only happen once.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will check in master

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For NNPDF4.0 with 3 replicas it is called 1001 times. For 2 replicas 693 times.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Then indeed, let's keep the freeze args for now, but please add a comment with that info on top. That should definitely not happen since the rules should be the same per replica, so I believe this is a signal of a problem somewhere else which hopefully can eventually be solved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added comment in 19771a0

@@ -561,6 +563,8 @@ def _make_point_namespace(self, dataset, idat) -> dict:
return ns


@freeze_args
@functools.lru_cache
Copy link
Member

Choose a reason for hiding this comment

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

Same note to myself.
But this one I think might be solved by some of the stuff I'm doing in the reader.

Copy link
Collaborator Author

@goord goord Feb 16, 2024

Choose a reason for hiding this comment

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

For NNPDF4.0 with 3 replicas it is called 1001 times. For 2 replicas 693 times.

--> I'm sorry, this comment was intended for the other function produce_rules in config.py!!!

Copy link
Member

Choose a reason for hiding this comment

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

This one yes, but I think it might be fixed now (in other PR). The other one I'm more worried about.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For NNPDF4.0 with 3 replicas it is called 1040 times. For 2 replicas 732 times.

@goord
Copy link
Collaborator Author

goord commented Feb 16, 2024

Testing with NNPDF4.0 runcard (theorid 200) with 200 epochs and 3 replicas on my laptop yields no numerical differences with the master branch (16 digits)

Copy link
Member

@RoyStegeman RoyStegeman left a comment

Choose a reason for hiding this comment

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

Thanks

return False


def immute(obj: Any):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def immute(obj: Any):
def make_hashable(obj: Any):

For symmetry reasongs, since you have is_hashable

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 in 19771a0

Comment on lines 19 to 20
# Since typing.Hashable doesn't check recursively you actually
# have to try hashing it.
Copy link
Member

Choose a reason for hiding this comment

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

This I don't really understand, what cases would we miss by doing isinstance(obj,Hashable)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, and I prefer the type check you propose. Will implement 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.

It works just as well, see 19771a0

validphys2/src/validphys/n3fit_data_utils.py Outdated Show resolved Hide resolved
@APJansen APJansen force-pushed the lru-cache-validphys branch from 264efaa to 61e5953 Compare February 19, 2024 10:55
@APJansen
Copy link
Collaborator

What is the status of this? Anything still needed? (Just rebased to master)

@scarlehoff
Copy link
Member

For me it is ok. As I said, I hope to be able to remove the freeze_args and frozendict dependency soonish (so please, don't depend on them more than strictly necessary) after I'm done with the new reader. The filters should not be reread for every replica.

@APJansen APJansen force-pushed the lru-cache-validphys branch from a35879d to dd4b98a Compare February 20, 2024 12:16
@scarlehoff scarlehoff marked this pull request as ready for review February 20, 2024 13:29
@scarlehoff scarlehoff merged commit 463943d into master Feb 20, 2024
8 checks passed
@scarlehoff scarlehoff deleted the lru-cache-validphys branch February 20, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants