270 points · by rbanffy · 7y ago · 131 comments
Numerical details: https://software.intel.com/sites/default/files/managed/40/8b...
Support for bfloat16 is already present in MKL-DNN (https://github.com/intel/mkl-dnn)
Disclaimer: I work for Intel
Dropping denormals is a huge mistake. This is easy to see if you draw out a number line for a very tiny floating-point format, for example with a 2-bit exponent and a 2-bit fraction. (do this on a sheet of graph paper) Without denormals, there is a huge gap surrounding zero.
Strangely, the infinities were kept. Treating these as NaN is far less harmful than dropping denormals. Treating -0.0 as 0.0 and never producing -0.0 would be less harmful. (the PDF didn't say what happens) Even treating NaN values as normal numbers is probably less harmful than screwing up the denormals.
IEEE floating point has lots of crazy stuff to annoy hardware vendors. Most of it isn't all that important, but denormals matter.
Having Nervana and friends on a Xeon chip could be a huge positive change for software. Not only could we toss out the issue of GPU memory transfer, but Nvidia GPUs aren’t so great with concurrency, and here with the linux kernel we might have a chance to beat Nvidia. Naveen sure would like that... Nervana once had a Maxwell compiler that was better than Nvidia’s.
Nowadays it's really a moot point with Nvidia's Cutlass being open source.
One other thought about the Nervana-Xeon convergence is that the support for more memory (thru DDR, Optane, or even just mmap'ed NVME) will be a big win for modeling and large-minibatch SGD. For example, the minibatch fetching could be pushed to the hardware / OS instead of Tensorflow (or the crazy guy behind Tensorpack) using a threadpool. A lot of training is still I/O bound at some level, and processors only support so many PCI-e lanes...
bfloat helps with this because the data is half as large. But of course if you're doing Nvidia you're probably already doing (IEEE) fp16.
Why implement bfloat if you get just slightly less performance emulating it with AVX512, which already exists? Maybe it’s an “us too” claim?
=> A vector multiply using bfloat16 may not be much faster than one using float32, but it will do more multiplications.
I'm unclear on the advantage you are trying to explain. If both AVX and bfloat are SIMD instructions that cannot be the reason implementing bfloat is better. I'm expecting something like "bfloat16 is more specialised so it can have larger registers" or something?
[Edit]
Sorry re-reading your comment, I think you are trying to say that. The key part being:
> fit more numbers vector registers
(vs AVX i assume), so adding bfloat16 would provide more registers vs AVX with similar gate usage due to greater specialization?
For CPU-bound algorithms, one would expect that bfloat16 in 512 bit vector registers would be about equal in speed to float32 in (hypothetical) 1024 bit vector registers.
Also, for algorithms that are memory-bandwidth bound, halving the size of your numbers will (about) halve memory pressure.
AVX512 is expensive. I believe if you have an AVX512-heavy workload it can cause the processor to throttle.
Running programs doing the same thing (eg, Hamiltonian Monte Carlo where the likelihood function has or has not been vectorized), the avx512 version is far faster than scalar, and routinely 50%+ faster than avx2.
The avx512 instruction set itself also provides conveniences that make it easier to explicitly vectorize, even if most compilers don't take advantage of them on their own. Masking load and store operations in particular (they're better about masking to handle branches).
On why avx512 vs a graphics card: I need double precision, and my code routinely has maximum widths smaller than the 32 or 64 a graphics card would want to computer in parallel.
Tensorflow OpenCL support bug [1] has been open for FOUR years now (with the discussion devolving into an Intel PlaidML flame war).
AMD OpenCL is now ROCm ?
At the end of the day, I cant run ANY accelerated workloads using Intel graphics or AMD ....because there's simply no software support anywhere.
OTOH, if you have a nVidia stack... boom. you get accelerated python https://developer.nvidia.com/how-to-cuda-python
Are you running containerized workloads on kubernetes ? it has BAKED-IN support for nvidia-docker (https://kubernetes.io/docs/tasks/manage-gpus/scheduling-gpus...)
Is anything going to change ?
You can, there’s an Intel framework: OpenVINO that is targeting Intel hardware, processors and HD video cards, you can convert TF graph to Vino and use their inference server, that mimics TF serving.
There’s TF ROCm port by AMD as well.
As it stands, CUDA is the only API with a decent implementation available on the three major desktop OSes. It's ridiculous.
I don't see how GPU with AVX512 can compete with TPU's or GPU's, BF16 or not.
You don't really anyway. A GPU instance in Azure will beat whatever extension accel intel does on CPUs by a mile either way.
Where there is lock in is one level higher...for ML all the other players are going FPGA which I reckon is a bad move.
FB's approach on the other side requires entirely redesigned and separate execution units. That's harder to justify, that silicon will remain dark for non-DL usage.
I imagine it still keeps most of the performance benefits since it's eliminating around 2/3rds of the longest binary component.
Ditto for them calling it "Brain Floating Point" [1]. I mean it appears to be a typical floating-point numeric data type with some of the precision truncated to reduce its cost.
I guess they might be trying to make it sound super-fancy to preempt people seeing it as cheap or/and low-tech?
[1]: https://en.wikipedia.org/wiki/Bfloat16_floating-point_format
Also, converting BF16 to FP32 and back is just a vector shuffle that sticks/drops 16 extra mantissa bits at the end of each FP16 value, so it's cheaper than other floating point conversions. This means that even if you occasionally have to escape to FP32, the overhead is low and you keep all of the memory bandwidth benefits.
It may well be a stupid q but I really don't know, and always assumed they would be [-1..+1] and that fixed point would suffice. Clearly not.
So not quite as good as a 6-inch slide rule.
Edit: voters in this thread seem pretty uptight.
Speaking of boiling the ocean . . .
It's possible that some other custom format is better in absolute terms for models trained specifically for the custom format. But for the current ecosystem, where models are trained primarily using float32, bfloat16 is a very good choice.
It seems like a huge mistake if they missed key optimizations, but I'm happy to take your word for it.
Are there write-ups that go in detail about these mistakes? It's the kind of somebody-is-wrong-on-the-Internet topic that would result in flaming blog posts. :-)
But I'd be rather glad if they implemented unums already.
[1] https://github.com/kstenerud/compact-float/blob/master/compa...
For weights during training, 7 bits of mantissa also seems a bit low - it's common for weights to adjust much less than 1% during a single batch of training, which this couldn't represent.
I think this is more a "we want something which is faster but is compatible with existing code written for fp32's".
You're right that the mantissa is small. The trick is that you always accumulate into fp32 and then truncate down to 16 bits at the end. You'd do this for any 16-bit floating type.
Source: I work on this at Google.
In particular the latter describes a generic framework that can be used to generate a lot of different number systems. Could hardware implement this, allowing us to compose and choose the number system by just setting some simple flags?
Intel (for better or worse) takes a very experiment-results-driven approach to choosing which features to implement in hardware. So this result -- that software emulation of a feature works almost as well as a hardware implementation would -- probably makes Intel less likely to implement the feature in hardware.
ARM, AMD, RISCV etc, will probably come to similar conclusions.
https://www.nextplatform.com/2018/12/16/intel-unfolds-roadma...
Just in case, since I can see someone else being serious about this, I think the gist is that neural-networks tend to be fairly approximate things such that we're not particularly concerned with having a lot of precision in many cases. This use-case wouldn't seem to demand a 32-bit variant too often.
But.. if you want it anyway...
Higher-bit extensions would seem to be floating-point values that favor range-over-precision more than typical floating-point numerics with the same bit-count.
If we take that to an extreme, we can talk about ranges over infinities and infinitesimals -- this is, much like the hyperreal-number system [1].
And ya know what's funny?
Some guy's been pushing for such a primitive numeric data type [2] since the early-2000's [3]!
[1]: https://en.wikipedia.org/wiki/Hyperreal_number
Graft, as understood in American English, is a form of political corruption, being the unscrupulous use of a politician's authority for personal gain.
Edit: by the way, I really couldn't fit the term with the article. And realized I was probably looking at the wrong definition. This one might be much more apt:
a shoot or twig inserted into a slit on the trunk or stem of a living plant, from which it receives sap.
Does that really deserve downvoting? If so, explain it to me please, because I just can't see why.
On the other hand, many of the readers of this blog are native English speakers, and to most of us the metaphorical meaning of the title was clear. A very useful function of voting is to re-order the comments on the page. This is a useful comment, but only for a small subset of readers. As such, it's perfectly reasonable that it would appear after the other more technical comments.
Which is to say that while you don't deserve to be downvoted, the comment arguably does. I personally upvoted it, because of my personal experience with intercontinental miscommunication involving the word "graft", but I can see why others would want to prioritize other comments. Not because it's a bad comment --- I'm sure a few people found it really helpful --- but because it's a meta-comment on a technical site that helps only a small portion of the audience.
So you should proudly keep making helpful comments like this, and not take it at all personally when they are downvoted to the bottom of the page. This is a case where you should feel confident that you did the right thing, despite the apparent feedback.
In this situation I would personally not downvote, but rather upvote the other more technical comments, which provides a similar result, without penalizing the commenter.
Your interpretation might be right, but a downvote will often be interpreted as "I didn't contribute to the conversation". The fact that "graft" is confusing, and that I am trying to shed light on it, is a way for me to try contributing, and therefore, in my view, shouldn't be penalized.
This is the definition they most likely meant.