48 points · by mindcrime · 11y ago · 45 comments
When you use irreproducible floating-point, you're essentially treating your CPU as an analog computer. For a subset of very specialized numerical applications, this is probably okay. For any kind of integration with interesting, non-numerical system software (let alone scientific publishing!), it's a disaster.
I always recommend this link on FP determinism: http://gafferongames.com/networking-for-game-programmers/flo...
In fact, FP32 is commutative (go ahead, check it out). It's just not associative. If you can't figure out how to reduce sums of FP32 numbers in a deterministic manner, you suck, no that's too weak, you really suck. And your complete lack of numerical analysis has turned a digital computing problem effectively into an analog nightmare you'll never debug. HPC people love to use this excuse for why their parallel code isn't deterministic, but it turns out that making it so is effectively free in an age of fast RDMA and INT64 atomics.
To be fair, there are situations where noisy non-deterministic inputs (cameras, microphones, and other sensors) are part of the deal. However, if given simulated deterministic examples of inputs, your result isn't deterministic, you still suck. That said, I'm willing to relax the constraint to assume reproducibility given the same HW/compiler/toolchain so I think the naysayers are pretty much out of excuses here.
I speak from experience. And the efforts I've made to achieve bitwise reproducibility in HPC algorithms are dismissed as "engineering" by the people who can't do so.
I've decided to take that as a compliment.
This is worse for our codes because our mesh structure changes topology based on floating point comparisons, so error in values turns into different discrete structures.
Parallelism introduces more headaches, making some codes non-deterministic between runs on the same machine, although I've been able to fix this for the most part.
Its important to break down "determinism" into consistency across changes in something, whether it be hardware or time or partitioning.
Unless the timings themselves are non-deterministic, sigh. But then I'm far more sympathetic. I have not found this sort of thing to be the case for the most part and when I have, I've used a deterministic measure rather than timing (i.e. number of calculations as opposed to how long they take).
For even compiler revisions are sufficient to break FP32 associativity let along different transcendental approximations (we ought to fix that, no?).
Where I get angry is when people sloppily use FP32 for everything or FP64 because it's double(tm) and then insist determinism isn't possible. That isn't even science IMO.
I'm just saying, like OP, that this work shouldn't be needed. You should get this result for free and not even have to think about it.
The instruction sets certainly aren't irreproducible and I shouldn't have implied that, although there are plenty of IEEE extensions not well-standardized (eg, transcendentals). The problem is that their specifications grow weaker as you move up the programming hierarchy. Optimizers rearranging algebra, etc. And the result that's presented to the normal programmer is that floating-point is analog computing.
As for the second part, one needs a great deal more thought into the definitions of transcendentals before proceeding. The 22-bit mantissa approximations of transcendentals on GPUs are fantastic for most scientific computing and machine learning applications. Any error they introduce is more than offset by errors introduced by the assumptions that led to those algorithms in the first place.
(1)We agree that the farther you move up the programmer hierarchy, the harder it is to make a reproducible algorithm. My solution is to defy the trend and implement the bowels of the hierarchy, but I'd be happy for a computer scientist to design something from the ground up that was bitwise-reproducible (and please please strongly typed so it's L1-friendly without doing functional programming backflips to make it so). I really don't think it should be that hard given how easily and repeatedly I have done so from the guts outward.
That's not bad.
Hopefully developers don't misinterpret this to mean that it is idiotic or overly obsessive about performance to use floating point types in calculations. That's not true.
As an example, I once decided to use double-precision floating-point in calculations that would accumulate enough accuracy error that I had to do approximate equality conditions throughout the parts of the code that determined these solutions. This not involve monetary amounts, and we needed solutions in a few seconds, not 20-30 seconds. Each step in the solution built on the former, so I could not break it up any more to solve in parallel than it already was. Throwing faster hardware at it wasn't an option available at the time. I still think I did the right thing, and it's still an integral part of production. Just going with the standard "just use BigDecimal because it's accurate" approach would have been a mistake.
I would love to have floating point decimal on embedded systems rather than a binary floating point unit. But the libraries are generally huge.
I use the equivalent of decimals WAY more on embedded hardware. User entry is always decimal. Percentages--decimal. Time specifications--milliseconds, microseconds, nanoseconds--decimal with precision.
I wind up writing integer fixed-point arithmetic versions of this crap, over and over and over.
Maybe since Moore's law broke and memory transistors are now way more expensive that processor transistors, we'll get decimal floating point as a feature soon.
I won't hold my breath, though.
We only store to hundredths ... oops ... new regulations require us to decimal round to thousandths. Cue full reload of the database with all your numbers in them.
Or, even better, try dealing with mm and mils in the same CAD database simultaneously. (conversion factor of 25.4--a clean number in decimal but very much not in binary)
In addition, you forget that simply adding decimals doesn't work in binary floating point. Adding 0.10 10 times doesn't equal 1.00 in binary floating point no matter how much precision you use.
http://www.vrworld.com/2015/03/24/the-evils-of-floating-poin...
http://sites.ieee.org/scv-cs/files/2013/03/Right-SizingPreci...
One interesting thing, John and I had an argument about the implementation, because there is one part about it that really sucks. Eventually he admitted that it had rankled him too and that the reason why he made this design choice was so that float64 could bitwise map smoothly onto unum{4,6} and float32 onto unum{4,5}... And that people would actually refuse to use unums if not for this direct bitwise mapping! So I capitulated.
And which part would that be? I'm mostly asking out of curiosity, so don't put yourself out if the answer is too long and involved.
As someone who has implemented a couple FPUs, I can assure you that there are quite a few pieces of IEEE 754 that suck to implement.
Don’t leave us hanging! What is the part that really sucks?
Do we really expect everyone who does linear regression to say "I did linear regression, using the following implementation of a linear solver". Because that's what is being asked.
A much better alternative is to test that algorithms give expected answers (within some tolerance) on simulated but non-trivial data. It will still require some care to distinguish bugs from rounding errors, but it is more, er realistic, than expecting bitwise reproducibility.
Maybe the optimization is important. In that case, couldn't you add another layer devoted to that special case? For instance, reorder matrix multiplies in a source-to-source transformation? Put leap seconds in the presentation layer, not the chronology layer?
Everyone who does linear regression for the purposes of publishing a scientific paper should post their code and data, so that anyone else can recompute it and get the same bits. How is this controversial in 2015?
What do you mean by "reorder matrix multiplies in a source-to-source transformation?" To be clear, the issue is that matrix multiplication (which forms the basis for a huge part of numerical computing) is only deterministic when the order of operations is known. But any kind of fast algorithm is going to have a highly complex order of operations that depends on the algorithm and parameters. You can't reorder these back to some canonical order without completely changing the algorithm (and destroying its performance gains).
Given the above, posting code and data won't be enough for binary reproducibility. Source code for every dependency would be needed too.
As I noted I do support testing and reproducibility, just not at the level of binary data.
This is a classic source-to-source transformation problem. You have an abstract matrix multiplication algebra which needs to be converted into a deterministic algorithm with a known order of operations. You need a second algorithm, essentially a macro, which converts the abstract operation into the concrete operations, which are then compiled to deterministic code.
This macro should itself be deterministic, even if its inputs contain information about local hardware configuration that's needed to make the optimized code run as fast as possible. If this information is in your data set, it's in your data set. Optimization is typically much less important to the reproduction pass, so a reproduction will probably just use your configuration details rather than those matched to the reproducer's machine.
Either way, both algorithms are deterministic and the result is reproducible. What's wrong with this picture? I ask because I genuinely want to know :-)
[Edit: it's disappointing to see "disagree == downvote" applied to the parent.]
Yes, reproducibility requires source code for the entire dependency graph, down to a set of bootstrap binaries. This is what tools such as GNU Guix and Nix allow you to do. They enable reproducible science.
My article argues that infrastructure tools (compilers, runtimes, ...) should ensure bitwise reproducibility, making it possible for a programmer to define a computational result exactly through a program's source code.
This does not mean that we can't have different algorithms. It doesn't even mean that no compiler could ever re-arrange operations for optimization. The latter could well be enabled through a compiler option.
All I am asking for is that infrastructure tools leave all these choices to the programmer.