Glow: [New operator] ReplaceNaN

Created on 25 Sep 2018  路  8Comments  路  Source: pytorch/glow

We need to support ReplaceNaN operator from Caffe2. Spec can be found here:
https://caffe2.ai/docs/operators-catalogue.html#replacenan

Most helpful comment

I'm in favor of making it a special node. NaN semantics are pretty weird even on standard hardware. I think std::isnan is probably the way to go.

All 8 comments

I want to implement this and I'm thinking of doing immediate lowering using CmpEq and Select nodes. But how do I portably represent NaN? I know there is some IEEE-defined bit pattern that indicates NaN, but I can't find a nice helper function anywhere.

The link that you provided works, and Caffe2 uses std::isnan. But using it would require creating this new operator for every single backend.

However, we can use a trick that x == x is true for every floating number except NaN. So compare input to itself, elements that are not equal are NaNs. And of course, this needs a test.

@artemrakhov Ah, interesting. We need to ensure that the optimizer does not replace "x==x" with "true". I wonder if isNaN is special enough to be a dedicated node. I wonder if this operation would be translated to NOP on some hardware accelerators that never produce NaN. I guess that the fact that we need to replace the value with some other scalar forces us to implement the compare-select semantics. This is a hard one. What do other people think?

I'm in favor of making it a special node. NaN semantics are pretty weird even on standard hardware. I think std::isnan is probably the way to go.

Some additions.

This needs ONNX loader as well.

@rdzhabarov

Is this officially part of the ONNX spec? Is there a standard way to represent this operator in a .onnxtxt?

Is this officially part of the ONNX spec? Is there a standard way to represent this operator in a .onnxtxt?

As discussed offline, that's our custom extension.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artemrakhov-glow picture artemrakhov-glow  路  4Comments

dati91 picture dati91  路  3Comments

tkclimb picture tkclimb  路  4Comments

stoklund picture stoklund  路  5Comments

mciprian13 picture mciprian13  路  4Comments