101 points xenophonf 2 days ago 33 comments
LoganDark 2 days ago | parent
Still, it's quite nice to see yet another option for representing magnitudes in programming. Given the right domain, these could show many benefits indeed.
Dylan16807 2 days ago | parent
But yeah the tradeoff between precision and range is harsh.
LoganDark 2 days ago | parent
At least with IEEE 754 Infinity, it corrupts your entire calculation into Infinity or NaN and then that's obvious in the result. Rounding errors, even compounding ones are also not nearly such a big issue.
Dylan16807 2 days ago | parent
Edit: I guess if you saturate and later divide you might escape maxpos without ever hitting infinity/NaR but that risk doesn't seem significantly worse than standard floating point, just different.
LoganDark 2 days ago | parent
dnautics 1 day ago | parent
IshKebab 2 days ago | parent
These are frequently ditched in AI accelerators anyway, so that's arguably a feature (at least for AI).
augment_me 2 days ago | parent
Source: (https://www.researchgate.net/publication/417276683_Hardware_...)
TLDR; The leading 0 + dynamic length and the 512-bit accumulators for quires require hardware specifics like extra register per MAC and barrel shifters which take up about 30% of the total unit area.
Probably not impossible to get around but in no way a drop-in or currently better supported by HW.
---
Also non-uniform relative error is a nightmare for any numerical formal verifier that are used by most frontier labs today to avoid numerical divergence during training.
Lerc 2 days ago | parent
andrepd 2 days ago | parent
You do pretty much always have to convert to an intermediate representation of "mantissa + exponent". That is how IEEE754 impls work also. It is a bit more complex than IEEE to do so, because of the variable-length field, but surprisingly not too much so (count-leading-0 plus a couple of shifts and xors do the trick!) Less than 2ns on my machine :)
schiffern 2 days ago | parent
andrepd 2 days ago | parent
schiffern 2 days ago | parent
Slide-rules are handy because they convert multiplication into addition. Or technically that's what logarithms do, and slide-rules are a physical implementation of logarithms.
Recall the classic identity:
log(x * y) = log(x) + log(y)
Slide-rules have multiple rulers, and some are marked in log scale, which lets you multiply totally mechanically! By aligning the markings, you effectively add two lengths, which (when read back on the log tick marks) becomes multiplication.
If you perform the same algebra transform as above, you see that addition becomes (oddly, but more intuitive the more you think about it) the Softmax function.
https://en.wikipedia.org/wiki/Softmax_function
This is my first time seeing Posits, but (having had similar ideas loosely inspired by the Doom bit-hacks) I just assumed this was one of the main sales pitches for Posits!
dnautics 1 day ago | parent
https://github.com/interplanetary-robot/mullinengine/blob/ma...
and multiply:
https://github.com/interplanetary-robot/mullinengine/blob/ma...
Here is an example generated verilog files:
https://github.com/interplanetary-robot/mullinengine/blob/ma...
You may find the handcrafted "circ" files more useful.
https://github.com/interplanetary-robot/mullinengine/blob/ma...
https://github.com/interplanetary-robot/mullinengine/blob/ma...
This was the julia library I wrote to be able to output verilog from julia. In the case of the posit math, it's verified by compiling with verlator, and doing a comprehensive (256 x 256 8-bit) scan comparing the emitted C-abi .so file, the wire values from verilog.jl, soft-values from the SigmoidNumbers package, the "true" value.
yababa_y 2 days ago | parent
AlotOfReading 1 day ago | parent
cycomanic 2 days ago | parent
andrepd 2 days ago | parent
> Also non-uniform relative error is a nightmare for any numerical formal verifier that are used by most frontier labs today to avoid numerical divergence during training.
I'm not sure what you mean by this. Yes IEEE has 40+ years of study behind it so its numerical properties are very well understood, that much is obvious. But I don't see what you are claiming exactly.
adrian_b 2 days ago | parent
The floating-point number format has not been chosen due to some historical accident, but because it is the only number format that combines fast computation with almost constant relative error over the domain of the represented numbers.
In almost all scientific/technical computing applications, constant relative error is what is desired, and it also enables a relatively simple analysis of the error propagation.
The non-constant relative error of the posits makes the analysis of the error propagation very difficult. Many applications need accurate estimations of the worst-case errors that can affect the results.
For any number representation system where the relative error is not constant, decreasing the error in some part of the domain increases the error in other parts of the domain, because the number of values is the same, being determined by the number of bits.
For some weird reason, posits want smaller errors around the origin, and this is paid by greater errors far from the origin.
Perhaps there are applications where this is useful, but in decades of experience with various applications of scientific/engineering computing I never wanted this error behavior, but I always wanted the constant relative error provided by FP numbers, even very far from the origin, with few exceptions where constant absolute error was desired, which is provided by fixed-point numbers, not by posits.
So for me, posits are a solution in search for a problem, because I do not see which professional would want such a thing. Tailors might work with feet and inches, so posits might be adequate for them, but fixed-point numbers are even better for them, being easier to use and having a lower absolute error. On the other hand, an electronics engineer works with picoseconds, femtofarads, nanoamperes, megavolts, terahertz, the elementary electric charge, Planck's constant, Boltzmann's constant, Avogadro's constant and so on, for which posits are useless.
Perhaps posits might be better than floating-point for ML/AI applications, but I say this only because I do not know which properties of the numbers really matter in that application, unlike for scientific/engineering computations, where I know with certainty that posits are not suitable, by leading to greater computational errors, while having a chance to be faster only for small number formats, not for 64-bit or bigger numbers.
jcranmer 1 day ago | parent
Evidently, Gustafson felt he had to change tack because he seems to have dropped unums after that debate and changed entirely to posits. And in the change to posits, he seems to have dropped most of the actual benefits of unums he was touting, although he hasn't quite dropped some of the cultish language he uses around the concept. The main trick of posits is to achieve greater precision for numbers around ±1 and greater exponent range, but by brushing the trade-offs used to achieve that under the rug. Except there's not really any demand for greater exponent range, so the trade-offs really overwhelm the marginal benefit of higher precision for a very specific range of numbers.
The new paper linked in the comment you replied to appears to acknowledge this, even in the AI tiny floating-point space, by basically fixing a maximum exponent range so that you have usable precision at higher exponents.
[1] I'd say IEEE floating-point, but the principles that Gustafson is attacking are found in virtually all formats pre-IEEE 754, with the exception of NaNs.
[2] The transcript is here, for the reader to decide for themselves: http://www.johngustafson.net/pdfs/DebateTranscription.pdf
dnautics 1 day ago | parent
https://github.com/interplanetary-robot/SigmoidNumbers/blob/...
dnautics 1 day ago | parent
I mean this is kind of "intuitive" error behavior. At some point the bigness of something is more important than the exact number. However, for sci/eng applications where peoples lives depend on your error analysis maybe not so much. For a lot of applications you want higher resolution around 1 -- and really you should be normalizing back to 1 after operations in general. And yes, I kept pointing out that error analysis and propagation was going to be a bitch =D which is why I kept pushing away from applications where you care a LOT about errors and towards applications where you care less about errors (like ML inference)
dnautics 1 day ago | parent
https://github.com/interplanetary-robot/mullinengine/blob/ma...
At the time IEEE-16 vs posit-16 was not really a thing yet, so I can't say if the multiplication would be worse because the extended size of the multiplier is not as dramatic as it is with posit-32, and the special-case handling (denormals, NaNs) is expensive.
larodi 2 days ago | parent
chaboud 2 days ago | parent
librasteve 2 days ago | parent
I have made a spreadsheet app in Rust with exact and fast arithmetic, centered on Apache Arrow and Polars, so Integer (i64) and Float (f64) are joined by Decimal[n] (.parquet Decimal38) and Fraction(num/dec).
After considering some alternatives for Fraction, including BigRat and maybe interval arithmetic the current pick is symbolic handling of num/dec stored as .parquet Strings. Why? Well the other three types are fast, so it seems OK to have a slow but sure “back stop”.
It works well for Googol ranges of arithmetic and knows that 1/7+4/7 is 5/7. This seems good for teaching purposes and scratching the exactness itch.
Anyway, I’m open to adding Posit provided there’s a Rust crate (fast-posit.rs?) and a way to shoe horn them into parquet. Please raise an issue over at https://omasheet.org repo if this is of interest.
gregates 2 days ago | parent
It's very easy to make a spreadsheet that adds binary64 numbers faster than Excel.
Someone 2 days ago | parent
William Kahan, father of IEEE 754, wrote about that: https://people.eecs.berkeley.edu/~wkahan/Mind1ess.pdf
> And many Excel features work on numbers as displayed, rather than the underlying bytes.
I think that’s a configuration flag
librasteve 2 days ago | parent
librasteve 2 days ago | parent
Unlike Excel, Omasheet is kind of aimed at folk who know and care about numeric types. It has 6 base numeric types Integer(1), Fraction(1/1), Decimal(1.0), Float(1e0), Scientific(1e0(00)) and Complex(1+0i) to cover ℤ, ℚ, ℝ and ℂ conceptually [with basic uncertainty to handle CODATA 2022]. And, like Raku, operations between unlike operands go to the more infectious type - so sin(x) is always irrational (Float or Complex).
So this, necessarily, is a forced compromise between helping a wide number of math/ science/ data/ education centric users with a sensible set of strict types and having an eye to the Excel level of usability since in the main most users of a spreadsheet are just going to be chucking numbers in and expect it to work.
I started with Rust BigRat for Fraction, but I couldn't work out a way to line it up with the .parquet file format. Since the goal was to cover all kinds of arithmetic examples including "how many atoms in the universe" and "what is a Googol (100*100)" as well as proper fractions and ℚ without rounding. This works fine atm with symbolic num/den representation (stored as Parquet Struct of Strings. You need to cast into one of the other types to get the Polars engine speed of course, so this is mainly for extreme edge cases and purity.
andrepd 2 days ago | parent
You're welcome to give it a try! https://github.com/andrepd/posit-rust/
I'm not sure how relevant it is to you, since you require exact arithmetic! In fact I'm not sure how you even use floats at all.
librasteve 2 days ago | parent
wmwragg 2 days ago | parent