GithubHelp home page GithubHelp logo

Comments (14)

qcolombet avatar qcolombet commented on May 28, 2024 2

Since, #1444 landed, do we have anything else left here?

from glow.

rdzhabarov avatar rdzhabarov commented on May 28, 2024 1

Do you think it should be more complicated than just an enum today?

Enum for symmetric, asymmetric seems to be fine.

from glow.

qcolombet avatar qcolombet commented on May 28, 2024 1

Send a PR for the plumbing to the loader #1324.

from glow.

rdzhabarov avatar rdzhabarov commented on May 28, 2024 1

The idea behind quantized sigmoid node is that CPU/Interpreter implementations are based on the prebuilt table which maps quantized input to quantized output (same for quantized tanh). Table contains a mapping (input -> output) for the input with the specific floating point range, that's why we need to select {S,O} to make sure input is within that range.

So if the backend does not want to use that mapping mechanism it will reject lowering of the quantized sigmoid/tanh. For the default case, CPU/Backend we'll make sure to restrict inputs of those nodes to some floating point range, that's why we need to find out what {S,O} correspond to that floating point range. I think it does not matter which schema will be used in the lowering of those nodes.

from glow.

rdzhabarov avatar rdzhabarov commented on May 28, 2024 1

Indeed, UInt8 with a zero offset is equal to Int8 with an offset of 128.

I assume int8 with -128 offset.
Having int8 with values [-128, 127] it would require to add +128 to shift the interval to [0, 255] (given that +128 is calculated on int32 type). Which would result in offset to be reduced by 128 (given fp = x * ( q - offset)).

Now, for the motivating use case, UInt8 with offset 0, maybe we could get away with adding a new schema "symmetric with uint8 range"

From the software layer this is OK, but how would it translate to the hardware which does not support non-0 offset?

from glow.

qcolombet avatar qcolombet commented on May 28, 2024 1

I assume int8 with -128 offset.

Exactly! I keep forgetting that the offset is subtracted not added :).

From the software layer this is OK, but how would it translate to the hardware which does not support non-0 offset

I was expecting this to be sorted out during lowering by each backend. Given that would be a specific schema, I would assume that the related support is in place before someone request it.

Admittedly I havenโ€™t sorted out the details, I wanted to check first if it was somewhat reasonable. It sounds like it is so let us think what it practically means.

from glow.

qcolombet avatar qcolombet commented on May 28, 2024

For starter, I was planning to introduce some code conditionally executed (via command line option) to force the offset to be zero.

That way we can start playing with it and see how it impacts the accuracy.

@rdzhabarov How does that sound?

from glow.

rdzhabarov avatar rdzhabarov commented on May 28, 2024

@qcolombet I'm fine as long as it could be easily testable.

Another way would be to introduce quantizationSchema (or something like that) and pass it to the chooseQuantizationParams method. The schema itself can be controlled through the loader command line option.

from glow.

qcolombet avatar qcolombet commented on May 28, 2024

Another way would be to introduce quantizationSchema (or something like that) and pass it to the chooseQuantizationParams method.

@rdzhabarov Works for me.

Do you think it should be more complicated than just an enum today?
In particular, do we want to support the cartesian product of (symmetric, asymmetric) x (zero offset, any offset)?

from glow.

qcolombet avatar qcolombet commented on May 28, 2024

I was looking at the uses of chooseQuantizationParams and some of them happens during our lowering process. Most of them request symmetric ranges, so that's technically not a big deal if we don't provide a schema there, but one ask for an asymmetric range: lowerQuantizedSigmoidNode.

@rdzhabarov Any ideas on how should we tell those nodes which schema to use?

It seems weird to me to have to surface the quantization schema in the lowering API.

from glow.

qcolombet avatar qcolombet commented on May 28, 2024

Introduce the symmetric schema and deal with the int8 activations (accuracy loss)

We're done with that step thanks to #1324.

from glow.

qcolombet avatar qcolombet commented on May 28, 2024

For the second step, "Introduce int8, uint8 activations", @nadavrot pointed out that we could use Int8 as a canonical representation. Indeed, UInt8 with a zero offset is equal to Int8 with an offset of 128. More generally UInt8 with whatever offset O is equal to Int8 with offset O + 128. Therefore using only Int8, we simply fail to capture a small portion of what UInt8 would cover when O + 128 overflows and in my opinion, that's not worth adding a new UInt8Q type.

Now, for the motivating use case, UInt8 with offset 0, maybe we could get away with adding a new schema "symmetric with uint8 range", that would allow both offset == 0 (regular symmetric int8) and offset == 128 ("symmetric" uint8).

@rdzhabarov what do you think?

from glow.

rdzhabarov avatar rdzhabarov commented on May 28, 2024

uint8 + symmetric schema support: #1444

from glow.

rdzhabarov avatar rdzhabarov commented on May 28, 2024

Looks like we covered necessary parts! Thanks for working on this!

from glow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.