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

Feature/benchmarking #802

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open

Feature/benchmarking #802

wants to merge 33 commits into from

Conversation

qh681248
Copy link
Contributor

@qh681248 qh681248 commented Oct 9, 2024

PR Type

  • Feature

Description

Added two files mnist_benchmark.py and blobs_benchmark.py

How Has This Been Tested?

Test A: (Write your answer here.)
Test B: (Write your answer here.)
Test C: (Write your answer here.)

Does this PR introduce a breaking change?

(Write your answer here.)

Screenshots

(Write your answer here.)

Checklist before requesting a review

  • I have made sure that my PR is not a duplicate.
  • My code follows the style guidelines of this project.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have performed a self-review of my code.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

Copy link
Contributor

github-actions bot commented Oct 9, 2024

Performance review

Commit 8a9d459 - Merge 1dffbc6 into 7aa60a7

No significant changes to performance.

@qh681248 qh681248 linked an issue Oct 10, 2024 that may be closed by this pull request
Copy link
Contributor

Performance review

Commit c281065 - Merge 055206b into 1832579

No significant changes to performance.

Copy link
Contributor

Performance review

Commit 91933db - Merge 78cd2e0 into 1832579

No significant changes to performance.

Copy link
Contributor

Performance review

Commit 4be645f - Merge 9f799bf into 1832579

No significant changes to performance.

Copy link
Contributor

@tp832944 tp832944 left a comment

Choose a reason for hiding this comment

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

I haven't got my head around everything yet, but this is good progress and you're clear to continue the job on benchmarking. I may have chucked on quite a few comments, although nothing is major.

CHANGELOG.md Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Add benchmarking to change log.

benchmark/blobs_benchmark.py Outdated Show resolved Hide resolved
benchmark/blobs_benchmark.py Outdated Show resolved Hide resolved
benchmark/blobs_benchmark.py Outdated Show resolved Hide resolved
benchmark/blobs_benchmark.py Outdated Show resolved Hide resolved
benchmark/mnist_benchmark_visualiser.py Outdated Show resolved Hide resolved
benchmark/mnist_benchmark_visualiser.py Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there are any sensible unit tests to write for this module.


"""
data_loader = DataLoader(pytorch_data, batch_size=len(pytorch_data))
_data, _targets = next(iter(data_loader)) # Load all data at once
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with DataLoader. next(iter( would normally only grab the first item of something. Does this fetch all the data?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a pretty involved file. I would look at adding some unit tests for the medium-sized functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seconding @tp832944 's comment - please add some unit tests

Copy link
Contributor

Performance review

Commit efb2040 - Merge b84ff03 into 1832579

No significant changes to performance.

Copy link
Contributor

Performance review

Commit 1d62686 - Merge 41f4f09 into 1832579

No significant changes to performance.

Copy link
Contributor

Performance review

Commit e1f9141 - Merge 5d0a8e2 into 3463539

Statistically significant changes

  • basic_rpc:
    • OLD: compilation 0.6253 units ± 0.03252 units; execution 0.142 units ± 0.001823 units
    • NEW: compilation 0.6087 units ± 0.02183 units; execution 0.1634 units ± 0.00134 units
    • Significant increase in execution time (15.05%, p=8.125e-16)

Normalisation values for new data:
Compilation: 1 unit = 375.27 ms
Execution: 1 unit = 795.81 ms

Copy link
Contributor

Performance review

Commit 63937b4 - Merge 4180f52 into 3463539

Statistically significant changes

  • basic_rpc:
    • OLD: compilation 0.6253 units ± 0.03252 units; execution 0.142 units ± 0.001823 units
    • NEW: compilation 0.6025 units ± 0.03407 units; execution 0.1573 units ± 0.0005494 units
    • Significant increase in execution time (10.72%, p=7.818e-11)

Normalisation values for new data:
Compilation: 1 unit = 372.3 ms
Execution: 1 unit = 793.52 ms

Copy link
Contributor

Performance review

Commit 65b253f - Merge db3d3ee into 3463539

No significant changes to performance.

Copy link
Contributor

Performance review

Commit 88742a6 - Merge b912461 into 3463539

Statistically significant changes

  • basic_rpc:
    • OLD: compilation 0.6253 units ± 0.03252 units; execution 0.142 units ± 0.001823 units
    • NEW: compilation 0.6208 units ± 0.02652 units; execution 0.1588 units ± 0.0007635 units
    • Significant increase in execution time (11.78%, p=4.115e-12)

Normalisation values for new data:
Compilation: 1 unit = 367.39 ms
Execution: 1 unit = 792.56 ms

@qh681248 qh681248 marked this pull request as ready for review October 18, 2024 09:00
Copy link
Contributor

Performance review

Commit 7746798 - Merge e94aed0 into ca26716

Statistically significant changes

  • basic_rpc:
    • OLD: compilation 0.6179 units ± 0.03292 units; execution 0.1748 units ± 0.0007481 units
    • NEW: compilation 0.6272 units ± 0.03453 units; execution 0.155 units ± 0.001498 units
    • Significant decrease in execution time (-11.34%, p=8.204e-15)
  • basic_stein:
    • OLD: compilation 4.631 units ± 0.3963 units; execution 0.6794 units ± 0.01023 units
    • NEW: compilation 4.589 units ± 0.3369 units; execution 0.5276 units ± 0.009367 units
    • Significant decrease in execution time (-22.35%, p=8.009e-18)

Normalisation values for new data:
Compilation: 1 unit = 367.93 ms
Execution: 1 unit = 801.31 ms

@bk958178 bk958178 self-requested a review October 21, 2024 08:40
@bk958178
Copy link
Contributor

bk958178 commented Oct 23, 2024

Note: Upon fix of RPCholesky (once #787 and related fixes are Done), we expect benchmarking metrics to change significantly.

Copy link
Contributor

@bk958178 bk958178 left a comment

Choose a reason for hiding this comment

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

@qh681248 Please find some further requested changes below.

This is an intermediate review. I'm having trouble running mnist_benchmark.py. Once I've resolved the issue, I will continue reviewing this PR


def main() -> None:
"""
Perform a benchmark comparing different coreset algorithms on a synthetic dataset.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding more information to this docstring, in response to a previous review comment.

It is still grammatically clumsy.
"Perform a benchmark..." is redundant, since 'benchmark' is a verb.
"...for each solver at different." isn't a correct ending to a sentence. Is the word 'sizes' missing?

Suggested rephrasing:

Benchmark different algorithms against a synthetic dataset.

Compare the performance of different coreset algorithms using a synthetic dataset,
generated using :func:`sklearn.datasets.make_blobs`. We set up various solvers,
generate coresets of multiple sizes, and compute performance metrics (MMD and KSD)
for each solver at each coreset size. Results are saved to a JSON file. 


The benchmarking process follows these steps:
1. Generate a synthetic dataset of 1000 two-dimensional points using
`sklearn.datasets.make_blobs`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add :func: before sklearn reference, so the documentation externally links correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`sklearn.datasets.make_blobs`.
:func:`sklearn.datasets.make_blobs`.


import json
import time
from typing import Any, Tuple
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove Tuple, and use type-annotations below with tuple instead (also requested in #802 (comment))

all_results[size] = results

# Save results to JSON file
with open("coreset_comparison_results.json", "w", encoding="utf-8") as f:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this filename different from the one in blobs_benchmark_visualiser.py ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching that, I have changed it to the correct file name now.

def setup_stein_kernel(
sq_exp_kernel: SquaredExponentialKernel, dataset: Data
) -> SteinKernel:
"""Set up Stein Kernel."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Document parameters and return for this function

:param sq_exp_kernel: ...
:param dataset: ...
:return: ...



def save_results(results: dict) -> None:
"""Save results to JSON."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Document parameters!

import jax.numpy as jnp
import numpy as np
import optax
import torchvision
Copy link
Contributor

Choose a reason for hiding this comment

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

@qh681248 please add torch and torchvision. This file can't be run without these.

Please add them to pyproject.toml

@@ -109,6 +109,7 @@ rcond
rect
rerunfailures
rightarrow
rngs
Copy link
Contributor

Choose a reason for hiding this comment

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

this is in custom_misc.txt too. It should only be needed in one of these .cspell files



def main() -> None:
"""Load benchmark results and visualize the algorithm performance."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Use British spelling: visualize -> visualise

Copy link
Contributor

Choose a reason for hiding this comment

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

Seconding @tp832944 's comment - please add some unit tests

Copy link
Contributor

@bk958178 bk958178 left a comment

Choose a reason for hiding this comment

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

@qh681248 Some further questions/requested changes. Thanks in advance for responding

pyproject.toml Outdated
@@ -34,6 +34,8 @@ dependencies = [
"scikit-learn",
"tqdm",
"typing-extensions",
"pytorch",
Copy link
Contributor

Choose a reason for hiding this comment

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

"pytorch" isn't the package named for PyTorch. It's "torch"

You can learn this by trying to run uv sync with this erroneous pyproject.toml file

@@ -123,6 +124,7 @@ tensordot
texttt
toctree
tomli
torchvision
Copy link
Contributor

Choose a reason for hiding this comment

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

consider adding torch to this file

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a particular reason we're committing these results files? I would have assumed they didn't need to be added to the repo, as they can be recreated locally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one takes a lot of runtime and computing power to generate, so we thought that it is worth committing (especially if we run it on a powerful computer to get the results)

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a particular reason we're committing these results files? I would have assumed they didn't need to be added to the repo, as they can be recreated locally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this one needs to be added as it can be recreated locally.

Comment on lines 251 to 253

# Save results to JSON file
with open("blobs_benchmark_results.json", "w", encoding="utf-8") as f:
Copy link
Contributor

Choose a reason for hiding this comment

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

Add more control over where this results file is saved. Suggested change:

base_dir = os.path.dirname(os.path.abspath(__file__))  # Gets the directory of current script
# Save results to JSON file
with open(os.path.join(base_dir,"blobs_benchmark_results.json"), "w", encoding="utf-8") as f:


def main() -> None:
"""Load benchmark results and visualise the algorithm performance."""
with open("mnist_benchmark_results.json", "r", encoding="utf-8") as file:
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly for blobs, enforce the location of the .json file. Suggested change:

 base_dir = os.path.dirname(os.path.abspath(__file__))  # Gets the directory of current script
# Save results to JSON file
with open(os.path.join(base_dir,"mnist_benchmark_results.json"), "w", encoding="utf-8") as f:

Copy link
Contributor

Performance review

Commit 52dec04 - Merge 4b36684 into 458f15a

Statistically significant changes

  • basic_herding:
    • OLD: compilation 0.5307 units ± 0.07855 units; execution 0.1929 units ± 0.008614 units
    • NEW: compilation 0.5451 units ± 0.09524 units; execution 0.2193 units ± 0.008304 units
    • Significant increase in execution time (13.71%, p=1.605e-06)
  • basic_rpc:
    • OLD: compilation 0.6136 units ± 0.02734 units; execution 0.1565 units ± 0.0008416 units
    • NEW: compilation 0.6532 units ± 0.04273 units; execution 0.1849 units ± 0.005503 units
    • Significant increase in execution time (18.15%, p=3.514e-08)
  • basic_stein:
    • OLD: compilation 4.687 units ± 0.3033 units; execution 0.5352 units ± 0.01495 units
    • NEW: compilation 4.573 units ± 0.434 units; execution 0.7048 units ± 0.02811 units
    • Significant increase in execution time (31.71%, p=1.482e-10)

Normalisation values for new data:
Compilation: 1 unit = 383.73 ms
Execution: 1 unit = 811.5 ms

Copy link
Contributor

Performance review

Commit 960bec0 - Merge f679a57 into 458f15a

No significant changes to performance.

Copy link
Contributor

Performance review

Commit 5106664 - Merge a2f45d3 into 458f15a

No significant changes to performance.

Copy link
Contributor

Performance review

Commit 9c17c98 - Merge 058e816 into cf9f6c0

No significant changes to performance.

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.

Coreset algorithm benchmarks for different data types
3 participants