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

bayes_opt crashes when only two values are given for tunable parameter #139

Closed
stijnh opened this issue Apr 20, 2022 · 1 comment
Closed
Assignees
Labels

Comments

@stijnh
Copy link
Member

stijnh commented Apr 20, 2022

The following code throws an exception.

import kernel_tuner

source = """
__global__ void foo() {

}
"""

problem_size = 100
args = []
tune_params = dict(
    block_size_x=[1, 64],
    block_size_y=[1, 2, 4, 8, 16, 32, 64],
    block_size_z=[1, 2, 4, 8, 16, 32, 64],
)

kernel_tuner.tune_kernel(
        source,
        "example",
        problem_size,
        args,
        tune_params,
        strategy="bayes_opt",
)

Results in the following error:

Traceback (most recent call last):
  File "test.py", line 23, in <module>
    strategy="bayes_opt",
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/interface.py", line 469, in tune_kernel
    results, env = strategy.tune(runner, kernel_options, device_options, tuning_options)
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 129, in tune
    bo = BayesianOptimization(parameter_space, removed_tune_params, kernel_options, tuning_options, normalize_dict, denormalize_dict, runner)
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 228, in __init__
    self.initial_sample()
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 439, in initial_sample
    samples = self.draw_latin_hypercube_samples(self.num_initial_samples)
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 424, in draw_latin_hypercube_samples
    param_config = self.normalize_param_config(param_configs[i])
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 338, in normalize_param_config
    normalized = tuple(self.normalized_dict[self.param_names[index]][param_value] for index, param_value in enumerate(param_config))
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 338, in <genexpr>
    normalized = tuple(self.normalized_dict[self.param_names[index]][param_value] for index, param_value in enumerate(param_config))
KeyError: 9

The number given by KeyError is a random number between 1 and 64. My suspicion is that bayes_opt interprets block_size_x=[1, 64] as range(1, 64) for some reason. Adding more possible values for block_size_x fixes the issue (for example, block_size_x=[1, 64, 128]).

@fjwillemsen
Copy link
Collaborator

fjwillemsen commented Sep 19, 2023

I've just resolved this issue in the commit linked above, which is part of a larger pull request (#214) that will be merged and published soon.

fjwillemsen added a commit that referenced this issue Oct 3, 2023
* Implemented PySMT in Kernel Tuner

* Added mapping of parameter names to integers for better perfomance

* Improved tests and compatibility for parameter mapping

* Switch from setup.py/cfg to pyproject.toml

* Added linting information, VS Code settings and recommendations

* Always return compiled functions as a list, application of formatter

* Improvements to string to restriction parsing

* Major speedup due to restriction splitting with parameter usage detection

* Refactored tests for parsing restrictions due to changes

* Minor improvements to an assert and a testcase

* Searchspace list to NumPy conversion only happens if needed

* Searchspace objects can now be initialized from ATF logfiles (caches), unified searchspace builder returns

* Added safeguard to prevent changing ATF block size names after compilation stage

* Fixed Constraint conversions

* Changed to non-forwardchecking by default, moved MaxProdConstraint to constraint

* Parsing of common operations to python-constraint built-in Constraints

* Fixed an issue with converting restrictions to Constraints

* Enabled converting to Constraint with '>' and '<' as well, added use of MinProdConstraint

* Added mapping of '>' to '>=' and '<' to '<=' for single-variable restriction

* Return None on trying to convert to numeric Constraint

* Automatic transformation of restrictions with multiple comparators to multiple restrictions with a single comparator, increasing the chance of converting to a built-in restriction

* Added support for PySMT on generated searchspaces

* Several improvements and fixes for PySMT builder, especially for preserving order

* Fixed an issue where restrictions would not be parsed to specific constraints, added tests for conversion to constraints, added requirement for Python version

* Removed redundant parameter mapping

* Minor fixes for testing

* Made scikit-opt (skopt) optional in strategy bayes_opt

* Changed to Poetry and pyproject.toml

* Added tests for pyproject.toml

* Updated changelog to reflect changes, updated VS Code settings

* Updated documentation to use pyproject file metadata, other minor updates

* Minor bugfixes based on SonarCloud

* Re-added support for Python 3.8, updated dependencies accordingly

* Updated GitHub Action workflows to use Poetry and Nox

* Removed unnecessary pull_request trigger for howfairis, added manual trigger for build & test

* Updated workflows with new Setup Nox 2 and new checkout

* Removed Windows from test OSes

* Updated publishing workflow, expanded TODOs in changelog

* Finished PyPI publication workflow with Poetry

* Fixed errors and warnings with the docs, as well as compatiblity issues

* Updated dependencies

* Updated documentation for installation, development setup etc.

* Minor updates: include notebook files in package, version bump

* Removed usage of OrderedDict as per issue #209, minor changes to tests for this, reogranized imports and made sure some appearantly unused imports are not automatically removed

* Updated test workflow to include upload to CodeCov for each OS, improved Noxfile so only the last test generates coverage report, added PyPI classifiers

* Disable automatic upload to CodeCov for now

* Solved issue #139: Reimplemented Latin Hypercube Sampling with SciPy

* Improved Nox with optional dependencies for CUDA, HIP, OpenCL and arguments to disable these

* Updated Contributing and Installation guidelines, specifically added development environment setup instructions, also added code syntax highlighting for Sphinx

* Minor changes to dependencies and environment setup

* Minor changes to dependencies and environment setup

* Added bruteforce solver to Searchspace object, improved tests for Searchspace

* Solved a bug in the constraints parsing that caused wrong searchspace outcomes, added and expanded searchspace tests, resolved warnings

* Added missing nox-poetry to test dependencies

* Added nox-poetry to GitHub test Action

* Added Poetry setup to Github Test Action

* Added extensive development environment setup instructions, updated installation documentation

* Add an exception for the nvml_ parameter check if in simulation mode

* Added optional additional (non-dependency) installation to Noxfile, with CUDA version differentiation. Added a tolerance to the energy power frequency model test.

* Fixed additional test input argument

* Improved detection of CUDA version using NVCC

* Improved automatic selection of cupy prebuilt version, from most exact to most general, and improved warnings

* Set the default environment used by Nox using a file

* Updated the documentation for the Noxenv file and other minor improvements

* Updated VS code settings for testing from VS code, updated documentation

* Fixed HIP import error, made backend import error messages point to documentation

* Restored accidentally removed import

* Added an option for Nox to remove the other environment caches before each session is ran, and to clean up temporary files

* Temporarily skip broken HIP tests as per issue #217, avoided error in Noxfile when no temporary files are present

* Improved Noxfile functionality for removing environments after use, and documentation on this feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants