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

Ignore 10% worst replicas in hyper loss #2014

Merged
merged 14 commits into from
Jun 5, 2024
Merged

Ignore 10% worst replicas in hyper loss #2014

merged 14 commits into from
Jun 5, 2024

Conversation

APJansen
Copy link
Collaborator

Basic implementation, not tested yet and the percentage is not configurable from the runcard.

@APJansen
Copy link
Collaborator Author

APJansen commented Apr 3, 2024

I have implemented what we discussed by removing the passed as it was created (unless there's no hyperopt, I left that case as is). Instead I've set passed just based on whether the hyper loss is bigger than the threshold, as if there are more than 10% replicas with infinite loss, this will automatically be violated.

I'm a bit confused now if that's what we want, as this check is already there of course. The difference is that the one I added does not include the penalties, and it sets the hyperopt status to failed, whereas the existing check just adds a penalty.

To make the tests pass I had to increase this hyper threshold, as it now fails the trial if it's violated. Can you check if that doesn't mess up other tests @Cmurilochem?

Also, it's running on the GPU again, without lhapdf and conda, see here for the setup and slurm scripts.

@APJansen APJansen marked this pull request as ready for review April 3, 2024 13:06
@Cmurilochem
Copy link
Collaborator

I have implemented what we discussed by removing the passed as it was created (unless there's no hyperopt, I left that case as is). Instead I've set passed just based on whether the hyper loss is bigger than the threshold, as if there are more than 10% replicas with infinite loss, this will automatically be violated.

I'm a bit confused now if that's what we want, as this check is already there of course. The difference is that the one I added does not include the penalties, and it sets the hyperopt status to failed, whereas the existing check just adds a penalty.

To make the tests pass I had to increase this hyper threshold, as it now fails the trial if it's violated. Can you check if that doesn't mess up other tests @Cmurilochem?

Also, it's running on the GPU again, without lhapdf and conda, see here for the setup and slurm scripts.

@APJansen. I do not expect any breaks on the other tests by increasing the hyper threshold. But they may take more time as you would be in principle fitting more folds than before. However, I am also a bit confused as to the reason behind this.

If I understood well, in the past (not sure it still now), the passed and not passed had to do with threshold_chi2 which was passed as an argument to instantiate the Stopping object; here. This is used in its monitor_chi2 method which is in turn used in callback.py. But there is also hyper_threshold which was compared with the final (statistic) hyper_loss (including penalties) of each fold and responsible to skip hyperparameter combination. I see now that your passed is directly tied to self.hyper_threshold. I am quite sure that this is your intention that but even so I am also sure that this my discussion might help you in some way. Please, also have a look in monitor_chi2. I see there the it is trying to deal with some NaNs.

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.

I don't understand why the threshold has to go from 2 to 1000 ? Surely this has to do with some 1/N that has not been considered? (where N might be replicas, data points, fold, or a combination of the above)

n3fit/src/n3fit/hyper_optimization/rewards.py Outdated Show resolved Hide resolved
n3fit/src/n3fit/model_trainer.py Outdated Show resolved Hide resolved
@Cmurilochem
Copy link
Collaborator

Hi @APJansen and @goord,
As I discussed before with you, I tried to make an hyperopt experiment and realized that most of the trials finish with {"status": "fail"} and {"loss": NaN}. For instance, out of 85 trials calculated just one seems to have a loss lower than 10. Just in case, I attach below my partial trial.json file:
tries.json

After looking at the renew_hyperopt.yml runcard, I noticed that I should have added average_best as my replica_statistic. I overlooked it before as I am copying this runcard directly from the repo to my local directory before running the experiment in snellius.

  1. @APJansen: to avoid confusion in the future, could we add average_best in renew_hyperopt.yml?:

    replica_statistic: average

    I could do that if you say so.

  2. Turning back to the results of the experiments I have done using (without knowing) average as replica_statistic. I still cannot quite understand why so many trials are discarded. Our passed criterium seems to be much more restrictive than before. While looking at the code, I see

    passed = fold_loss < self.hyper_threshold

    and right after,
    if hyper_loss > self.hyper_threshold:

    Both fold_loss and hyper_loss appear to represent reduced-over-replicas hyper_losses for a specific fold.

@scarlehoff
Copy link
Member

I'll rebase this on top of master to facilitate the review (it shouldn't make a big difference since the last rebase was not long ago)

@scarlehoff
Copy link
Member

@Cmurilochem I've added a runcard option penalties_in_loss.

I'll add this to the docs. I've decided not to add the proportion to the runcard because it adds a bit of complexity (I need to add a custom parser in validphys) and thought that at this stage of the project it was better to skip it.

(However, since I've written already the code, if you would like to have access to the proportion or other arguments for the statistics let me know and I'll push it)

@Cmurilochem
Copy link
Collaborator

@Cmurilochem I've added a runcard option penalties_in_loss.

I'll add this to the docs. I've decided not to add the proportion to the runcard because it adds a bit of complexity (I need to add a custom parser in validphys) and thought that at this stage of the project it was better to skip it.

(However, since I've written already the code, if you would like to have access to the proportion or other arguments for the statistics let me know and I'll push it)

Thanks @scarlehoff. It looks clear. Thanks for your help.

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.

If @Cmurilochem confirms this PR works for him as it is I think it can be merged .

@Cmurilochem
Copy link
Collaborator

Cmurilochem commented Jun 4, 2024

If @Cmurilochem confirms this PR works for him as it is I think it can be merged .

Hi @scarlehoff. Thanks for all your hard work. It looks great to me and it is working as expected. I just added a last commit in which I update our experiment's runcards adding a non-default penalties_in_loss for reproducibility. Please, let me know if you agree with that. For the moment I will take the lead and approve your changes.

edit: oh..did not see you have done so already; please, merge it when you are ready.

@scarlehoff scarlehoff merged commit 7caa1ef into master Jun 5, 2024
6 checks passed
@scarlehoff scarlehoff deleted the hyper-selection branch June 5, 2024 06:03
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