jansel / opentuner

An extensible framework for program autotuning
http://opentuner.org/
MIT License
382 stars 112 forks source link

LogIntegerParameter may fail with domain error #114

Open athas opened 6 years ago

athas commented 6 years ago

I have a program where at some point this line is reached with (for example) v=71 and self.min_value=8192. This produces a negative argument to math.log, and then boom.

This occurs fairly quickly for a tuner that uses the following LogIntegerParameters (lower and upper bounds):

(8192, 2097152)
(8, 32)
(8, 32)
(8192, 2097152)
(8, 32)
(8, 32)

And this technique:

technique.register(bandittechniques.AUCBanditMetaTechnique([
    simplextechniques.RegularNelderMead(),
    simplextechniques.RightNelderMead(),
    simplextechniques.MultiNelderMead(),
    simplextechniques.RandomTorczon(),
    simplextechniques.RegularTorczon(),
    simplextechniques.RightTorczon(),
    simplextechniques.MultiTorczon()
], name='FutharkMetaTechnique')

I don't quite understand how this can happen, but I may be holding it wrong.

athas commented 6 years ago

Here is a stack trace:

Traceback (most recent call last):
  File "futhark/tools/futhark-autotune", line 400, in <module>
    FutharkTuner.main(args)
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/measurement/interface.py", line 299, in main
    return TuningRunMain(cls(args, *pargs, **kwargs), args).main()
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/tuningrunmain.py", line 199, in main
    self.search_driver.main()
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/driver.py", line 269, in main
    if self.run_generation_techniques() > 0:
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/driver.py", line 169, in run_generation_techniques
    dr = self.root_technique.desired_result()
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/metatechniques.py", line 39, in desired_result
    dr = technique.desired_result()
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/metatechniques.py", line 39, in desired_result
    dr = technique.desired_result()
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/technique.py", line 87, in desired_result
    cfg = self.desired_configuration()
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/technique.py", line 195, in desired_configuration
    return self.gen.next()
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/technique.py", line 249, in call_main_generator
    p = subgen.next()
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/simplextechniques.py", line 361, in main_generator
    reflected = self.reflected_simplex()
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/simplextechniques.py", line 399, in reflected_simplex
    return self.scaled_simplex(self.alpha)
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/simplextechniques.py", line 394, in scaled_simplex
    self.linear_point(simplex[0].data, simplex[i].data, scale))
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/simplextechniques.py", line 67, in linear_point
    return self.manipulator.linear_config(1.0, p1, scale, p1, -scale, p2)
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/manipulator.py", line 70, in linear_config
    dst_params[k].op4_set_linear(cfg_a, cfg_b, cfg_c, a, b, c)
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/manipulator.py", line 1760, in param_method_proxy
    return member(self.cfg, *args, **kwargs)
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/manipulator.py", line 533, in op4_set_linear
    vc = self.get_unit_value(cfg_c)
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/manipulator.py", line 475, in get_unit_value
    val = self.get_value(config)
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/manipulator.py", line 770, in get_value
    return self._scale(NumericParameter.get_value(self, config))
  File "/home/mzd885/.local/lib/python2.7/site-packages/opentuner/search/manipulator.py", line 782, in _scale
    return math.log(v + 1.0 - self.min_value, 2.0)
ValueError: math domain error
jbosboom commented 6 years ago

What seems to be happening is that one of the techniques is producing a configuration with an out-of-range value for that parameter. Then, later, one of the techniques (possibly a different one) is asking for a linear combination involving that configuration. Finding that combination requires scaling the parameter to [0.0, 1.0), but that can't be done because the value is out-of-range.

So I think this is a bug, not user error. A reasonable first debugging step is to find a minimal set of techniques and parameters that reproduces the problem.

You could also try opening the database, finding an illegal configuration, and then checking the requestor field in the desired_result table to see which technique generated it. Unfortunately configuration data is gzipped-pickled, so you can't simply query this in the sqlite3 command-line client; you'd have to write some Python code.