Skip to content

near-zero negative values must convert to 0 not NAN - #18473

Merged
Tianlei Wu (tianleiwu) merged 3 commits into
microsoft:mainfrom
arnej27959:main
Sep 6, 2024
Merged

Tianlei Wu (tianleiwu) merged 3 commits into
microsoft:mainfrom
arnej27959:main

Conversation

@arnej27959

Copy link
Copy Markdown
Contributor

for the Float8 types with unsigned zero, we must clear the sign bit when rounding to zero;
otherwise we end up with 0x80 which is the encoding for NAN.

Description

Handle all zero and near-zero values the same way, rounding to positive zero.
Note that I removed one "if" level but did not re-indent the code in this PR, to make it
easier to see what the actual changes are.

Motivation and Context

For the two new 8-bit floating point types Float8E4M3FNUZ and Float8E5M2FNUZ,
converting from a near-zero negative value would end up with the sign bit set only;
this bit pattern is not negative zero but instead means NAN.

for the Float8 types with unsigned zero, we must clear
the sign bit when rounding to zero; otherwise we end
up with 0x80 which is the encoding for NAN.
@arnej27959

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company="Vespa.ai"

@xadupre

Copy link
Copy Markdown
Member

Thanks for finding this issue, I applied your fix onnx as well (see onnx/onnx#5764).

@arnej27959

Copy link
Copy Markdown
Contributor Author

note: last commit is a whitespace-only change.

@xadupre

Copy link
Copy Markdown
Member

/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux QNN CI Pipeline, Windows CPU CI Pipeline, Windows GPU CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline,

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 7 pipeline(s).

@xadupre

Copy link
Copy Markdown
Member

/azp run orttraining-ortmodule-distributed, orttraining-linux-gpu-ci-pipeline, orttraining-linux-ci-pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@xadupre

Copy link
Copy Markdown
Member

/azp run Windows x64 QNN CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@xadupre

Copy link
Copy Markdown
Member

/azp run Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Windows ARM64 QNN CI Pipeline, Windows GPU TensorRT CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 4 pipeline(s).

@xadupre

Copy link
Copy Markdown
Member

/azp run MacOS CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

github-merge-queue Bot pushed a commit to onnx/onnx that referenced this pull request Dec 8, 2023
### Description
-0.00001 must be converted into 0 and not negative zero which does not
exist for types Float8E4M3FNUZ and Float8E5M2UZ.
See microsoft/onnxruntime#18473 for further
details.

Signed-off-by: Xavier Dupre <xadupre@microsoft.com>
@arnej27959

Copy link
Copy Markdown
Contributor Author

can this be merged into main branch now?

@arnej27959

Copy link
Copy Markdown
Contributor Author

Xavier Dupré (@xadupre) this looks like it has been forgotten, can you please take another look

@arnej27959

Copy link
Copy Markdown
Contributor Author

Tianlei Wu (@tianleiwu) can you please help me with this PR?
Our group doesn't use 8-bit floats (yet) but I would like to get this resolved.

@xadupre

Copy link
Copy Markdown
Member

/azp run Big Models, Linux Android Emulator QNN CI Pipeline, ONNX Runtime Web CI Pipeline, Windows GPU CUDA CI Pipeline, Windows GPU DML CI Pipeline

@xadupre

Copy link
Copy Markdown
Member

/azp run Windows GPU Doc Gen CI Pipeline

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 5 pipeline(s).

@tianleiwu
Tianlei Wu (tianleiwu) merged commit 493159b into microsoft:main Sep 6, 2024
deoxy (linshokaku) pushed a commit to linshokaku/onnx that referenced this pull request Oct 2, 2024
### Description
-0.00001 must be converted into 0 and not negative zero which does not
exist for types Float8E4M3FNUZ and Float8E5M2UZ.
See microsoft/onnxruntime#18473 for further
details.

Signed-off-by: Xavier Dupre <xadupre@microsoft.com>
Signed-off-by: Linsho Kaku <linsho@preferred.jp>
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