Skip to content

Add 16-bit float tensor types#15

Merged
karllessard merged 2 commits intotensorflow:masterfrom
karllessard:float16-types
Jan 16, 2020
Merged

Add 16-bit float tensor types#15
karllessard merged 2 commits intotensorflow:masterfrom
karllessard:float16-types

Conversation

@karllessard
Copy link
Collaborator

This PR shows how to make use of DataLayouts to implement new tensor data types not directly supported by Java primitive types. It adds 2 new tensor types to the Java bindings: TFloat16 and TBFloat16. The former implements the IEEE-754 half-precision floating-point specification while the latter is for truncated 32-bit floats, called "Brain float-16".

In addition, you'll notice that the PR also include a lot of javadoc updates, which is a work continuously in progress.

@Craigacp
Copy link
Collaborator

Craigacp commented Jan 14, 2020

Javadoc looks good.

Is it worth adding a method to the BFloat16 and Float16 interfaces that accepts a Tensor<Float16> and returns a Tensor<Float32>? That'll make it simpler for users to convert the result of a computation into something they can easily use from Java.

@saudet
Copy link
Contributor

saudet commented Jan 15, 2020

Intel capitalizes it "Bfloat16" so it might be better to do it like that here as well?
https://software.intel.com/en-us/download/bfloat16-hardware-numerics-definition
There are also more instances of "Bfloat16" than "BFloat16" in TensorFlow's main repository,
but it's not too clear cut...

BTW, again, why do we need to prefix all those types with "T"? What's wrong with just Float16, etc?

@Craigacp
Copy link
Collaborator

Craigacp commented Jan 15, 2020

I think the prefixing helps to distinguish them from things that implement Number. At the moment they are more like tag types to make things flow through the type system properly rather than data carriers.

I've no opinion either way on BFloat16 vs Bfloat16, whatever is more prevalent in the community is fine by me.

@karllessard
Copy link
Collaborator Author

For the prefix, please see my reply in the group thread as this question has been asked in many different places :) https://groups.google.com/a/tensorflow.org/d/msg/jvm/Zp362xTQahc/Ho6iUEJfAgAJ

For the BFloat16 vs Bfloat16, I'm fine with both as well so let's follow @samuel suggestion then, I'll rename it.

@karllessard
Copy link
Collaborator Author

What about TUInt8 vs TUint8? Again, both are used in TF core.

@karllessard
Copy link
Collaborator Author

karllessard commented Jan 15, 2020

Haha, worst, all of QUInt8, QUint8 and Quint8 are present in TF.

I guess if we go with TBfloat16, we should apply the same pattern of capitalizing only the first letter for all types. It looks like that is what the Go client is doing. So if everyone is ok, I'll make the changes for TUint8 as well.

@karllessard karllessard merged commit 49945fe into tensorflow:master Jan 16, 2020
@karllessard karllessard deleted the float16-types branch January 16, 2020 14:02
karllessard added a commit that referenced this pull request Mar 6, 2026
Craigacp added a commit that referenced this pull request Mar 6, 2026
* Move NdArray library to subfolder

* Add missing dependencies

* Fix settings.xml path

* Kotlin friendly names (Shape.get)

* Fix bug when slicing on a segmented dimension (#2)

* Sparse tensor (#3)

* Allow SparseNdArray impls to be inherited (#5)

* Better examples in Sparse array documentation (#6)

* Build on JDK11 by default (#7)

* Add missing export

* Adding toString to AbstractDenseNdArray and AbstractSparseNdArray (#8)

* Test Java copyFrom Ok

* Test Java copyFrom - trying to replicate Scala error

* Test Java copyFrom - trying to replicate Scala error v2

* Added basic index tests (rank 2)

* Added module-info to tests

* Module-info for tests use the same module name of src

* Value streaming for NdArrays (#15)

* Release 0.4.0

* Prepare next iteration

* Viewing arrays with different shapes (#18)

* Rename read/write to copyTo/From (#19)

* Releasing 1.0.0-rc.1

* Increase version for next iteration

* Move ndarray to tensorflow-java

* Apply spotless

---------

Co-authored-by: Ryan Nett <JNett96@gmail.com>
Co-authored-by: Jim Clarke <JimClarke5@me.com>
Co-authored-by: Adam Pocock <craigacp@gmail.com>
Co-authored-by: hmf <hugo6ferreira@gmail.com>
Co-authored-by: Adam Pocock <adam.pocock@oracle.com>
nfeybesse pushed a commit to nfeybesse/tensorflow that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants