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: Allow for customized extra results to be written to results.csv.zip #612

Merged
merged 3 commits into from
Apr 4, 2023

Conversation

mseeger
Copy link
Collaborator

@mseeger mseeger commented Apr 1, 2023

At the moment, we write time-stamped results to results.csv.zip (a dataframe), and the serialized tuner to tuner.dill.
This PR allows to (optionally) write extra results to results.csv.zip. These are appended as new columns.

An example use case is given.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@mseeger mseeger requested a review from wesk April 1, 2023 17:07
return tuner_kwargs


def start_benchmark_local_backend(
configuration: ConfigDict,
methods: MethodDefinitions,
benchmark_definitions: RealBenchmarkDefinitions,
post_processing: Optional[PostProcessingType] = None,
final_results: Optional[FinalResultsComposer] = None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaces post_processing. Instead of running some code at the end, we extract some extra results which are stored. This is more useful.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are there any known uses of customers using post_processing?

I agree that final_results is a great new feature -- just wondering before we remove post_processing if there are any use-cases that will break from the removal.

Especially since this is in benchmarking, I think it's very low-risk to update.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. I don't think anybody except me uses this right now.

@codecov
Copy link

codecov bot commented Apr 1, 2023

Codecov Report

Patch coverage: 59.48% and project coverage change: -0.02 ⚠️

Comparison is base (62f1b8c) 65.11% compared to head (cabf154) 65.10%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #612      +/-   ##
==========================================
- Coverage   65.11%   65.10%   -0.02%     
==========================================
  Files         362      363       +1     
  Lines       26500    26532      +32     
==========================================
+ Hits        17256    17274      +18     
- Misses       9244     9258      +14     
Impacted Files Coverage Δ
benchmarking/commons/hpo_main_common.py 47.22% <ø> (-0.96%) ⬇️
benchmarking/commons/hpo_main_local.py 0.00% <0.00%> (ø)
benchmarking/commons/hpo_main_sagemaker.py 0.00% <0.00%> (ø)
benchmarking/commons/hpo_main_simulator.py 0.00% <0.00%> (ø)
benchmarking/commons/utils.py 0.00% <0.00%> (ø)
benchmarking/nursery/benchmark_dyhpo/hpo_main.py 0.00% <0.00%> (ø)
syne_tune/experiments.py 0.00% <0.00%> (ø)
...ptimizer/schedulers/searchers/searcher_callback.py 0.00% <0.00%> (ø)
syne_tune/tuner_callback.py 100.00% <ø> (ø)
...izer/schedulers/searchers/dyhpo/hyperband_dyhpo.py 94.44% <66.66%> (+0.24%) ⬆️
... and 6 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

syne_tune/results_callback.py Outdated Show resolved Hide resolved
Comment on lines 146 to 151
def _write_final_results(self):
if self._final_results_composer is not None:
final_results = self._final_results_composer(self._tuner)
if final_results is not None:
path = self._tuner.tuner_path / ST_FINAL_RESULTS_FILENAME
dump_json_with_numpy(final_results, path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this new method relate to this existing way of getting the final hyperparameters: https://github.com/awslabs/syne-tune/blob/main/examples/launch_plot_results.py#L69

tuning_experiment = load_experiment(tuner.name)
print(tuning_experiment)
print(f"best result found: {tuning_experiment.best_config()}")

Is this _final_results_composer needed if it's already possible to call .best_config()? Could we not re-use what .best_config() is doing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Final results are not best parameters. They can be anything. In the example I have here, they are statistics recorded by the scheduler, so nothing that would even be in results.csv.zip.

In the next PR, I am using this to record performance statistics for checkpoint removal. Again, this is not stored in results.csv.

These final results are optional. If you can obtain your answer from the results.csv, you should do that. But often, this is not possible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you consider adding the ability to optionally augment the information in results.csv.zip to include the additional optional information that you want to extract? (Rather than creating a new separate output file, which might confuse users by creating two competing sources-of-truth.)

With the current implementation, I can foresee scenarios where people expect to be able to extract the best hyperparameters from final-results.json, however they don't find them there. It may become confusing to understand when to look in final-results.json versus results.csv.zip.

Or, if we choose not to combine the files, maybe renaming it to something like extra-metadata.json, so that it's clear that the primary output of tuning, the hyperparameters, will not be included in the file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You have a good point, I'll do that

@@ -66,7 +66,7 @@

# Does not contain ASHABORE, because >10 secs on CI
# TODO: Dig more, why is ASHABORE more expensive than BORE here?
@pytest.mark.timeout(10)
@pytest.mark.timeout(12)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like writing the files to disk makes the test run longer? Is this with intermediate checkpoints enabled, or is this just writing final output to disk?

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 am not sure. I just increased this because I had this test failing. I do not think this has anything to do with the change here, to be honest. The change here is not activated in this test, right? Final results are only written when you activate the feature.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can bump the limit, but if it was passing reliably before this PR, and starts timing out with this PR, then it would be useful to know why.

Not necessarily a blocker but something interesting

@mseeger
Copy link
Collaborator Author

mseeger commented Apr 3, 2023

I will rework this, so information is appended to the results.csv dataframe. Thanks Wes, this is indeed a better solution.

@mseeger mseeger changed the title feature: New result file (optional) to be written at the end of tuning feature: Allow for customized extra results to be written to resultscsv.zip Apr 3, 2023
@mseeger mseeger changed the title feature: Allow for customized extra results to be written to resultscsv.zip feature: Allow for customized extra results to be written to results.csv.zip Apr 3, 2023
@mseeger
Copy link
Collaborator Author

mseeger commented Apr 3, 2023

OK, this is totally rewritten. The extra results are now appended to the default ones, by extending the dataframe by additional columns. This has the advantage of not needing another file, and of getting time-stamped results.

The disadvantage is we cannot write out final results of complex structure (e.g., lists or dicts). But that is OK.

if __name__ == "__main__":
logging.getLogger().setLevel(logging.INFO)

random_seed = 31415927
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice seed choice 🥧

Copy link
Collaborator

@wesk wesk left a comment

Choose a reason for hiding this comment

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

Very intuitive, looks good!

@mseeger mseeger merged commit 9185aa3 into main Apr 4, 2023
@mseeger mseeger deleted the results_at_end branch April 4, 2023 15:01
@wesk wesk added the feature label Apr 11, 2023
@wesk wesk changed the title feature: Allow for customized extra results to be written to results.csv.zip feat: Allow for customized extra results to be written to results.csv.zip Apr 11, 2023
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.

2 participants