{"record":{"id":"174ff12e955bbaea","repo":"deeplearning4j/deeplearning4j","slug":"not-yet-implemnted-fp16-reading-from-buffer","errorCode":null,"errorMessage":"Not yet implemnted: FP16 reading from buffer","messagePattern":"Not yet implemnted: FP16 reading from buffer","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/imports/graphmapper/tf/tensors/TFTensorMappers.java","lineNumber":212,"sourceCode":"\n    public static class Float16TensorMapper extends BaseTensorMapper<float[], Buffer>  {\n        public Float16TensorMapper(TensorProto tensorProto) {\n            super(tensorProto);\n        }\n\n        @Override\n        public int valueCount() {\n            return tfTensor.getHalfValCount();\n        }\n\n        @Override\n        public float[] newArray(int length) {\n            return new float[length];\n        }\n\n        @Override\n        public Buffer getBuffer(ByteBuffer bb) {\n            throw new UnsupportedOperationException(\"Not yet implemnted: FP16 reading from buffer\");\n        }\n\n        @Override\n        public void getValue(float[] jArr, int i) {\n            int asIntBytes = tfTensor.getHalfVal(i);\n            jArr[i] = HalfIndexer.toFloat(asIntBytes);\n        }\n\n        @Override\n        public void getValue(float[] jArr, Buffer buffer, int i){\n            throw new UnsupportedOperationException(\"Not yet implemented: FP16 reading from buffer\");\n        }\n\n        @Override\n        public INDArray arrayFor(long[] shape, float[] jArr) {\n            //Edge case: sometimes tf has single float value for entire array (getFloatValCount() == 1)\n            if(jArr.length == 1 && ArrayUtil.prod(shape) > 1)\n                return Nd4j.createUninitialized(DataType.HALF, shape).assign(jArr[0]);","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/imports/graphmapper/tf/tensors/TFTensorMappers.java#L194-L230","documentation":"The TensorFlow FP16 tensor mapper's getBuffer() hook has not been implemented, so reading FP16 tensor data through the NIO buffer path is unsupported. The library can read FP16 values element-wise via getValue() (using HalfIndexer.toFloat on halfVal bytes) but throws this UnsupportedOperationException when the buffer-based read API is used. It is a deliberate stub, not a data corruption issue.","triggerScenarios":"Importing a TensorFlow graph/protobuf containing a HALF (float16) tensor through TFTensorMappers when the code path calls getBuffer(ByteBuffer) instead of the element-wise getValue() path — e.g. a mapper implementation or caller that prefers the bulk buffer read.","commonSituations":"Importing TF frozen graphs or checkpoints that contain float16 weights (e.g. FP16-optimized models); using APIs that materialize tensor contents via ByteBuffer rather than per-element access during TF model import into ND4J/DL4J.","solutions":["Convert the FP16 tensor to FP32 (float) in the original TensorFlow model before export so the float mapper path is used.","Read values element-wise via getValue(float[], int), which is implemented for FP16 using HalfIndexer.toFloat.","Patch/override the mapper's getBuffer() to decode the ByteBuffer shorts with HalfIndexer and file an issue upstream.","Avoid the code path that requests buffer-based reads for HALF dtypes (check the import API used)."],"exampleFix":"// before\nByteBuffer buf = mapper.getBuffer(byteBuffer);\nfloat[] vals = ...;\n// after\nfloat[] vals = new float[tensorInfoCount];\nfor (int i = 0; i < vals.length; i++) {\n    mapper.getValue(vals, i); // uses HalfIndexer.toFloat(getHalfVal(i))\n}","handlingStrategy":"fallback","validationCode":"if (tensor.getDtype() == org.tensorflow.proto.DataType.DT_HALF) {\n    // avoid getBuffer(); use per-element reads or convert to DT_FLOAT first\n}","typeGuard":null,"tryCatchPattern":"try {\n    ByteBuffer buf = mapper.getBuffer(bb);\n} catch (UnsupportedOperationException e) {\n    // fall back to per-element getValue(int) reads\n}","preventionTips":["Convert FP16 tensors to FP32 before TF import.","Route HALF-dtype tensors to element-wise getValue paths.","Check dtype before choosing a buffer-based read API.","Pin an nd4j version known to cover your model's dtypes."],"tags":["nd4j","fp16","unsupported-operation","tensorflow-import"],"backgroundTag":"method-not-implemented","analyzedSha":"4c22ac5fe4a8350d05d224e7f4499429f7f69c93","analyzedAt":"2026-09-07T05:27:04.714Z","contentChangedAt":"2026-09-07T05:27:04.714Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}