gizatechxyz / orion

ONNX Runtime in Cairo 1.0 for verifiable ML inference using STARK
https://orion.gizatech.xyz
MIT License
163 stars 81 forks source link

Refactor Fixed Point Representation to Use Native Signed Integers #633

Open raphaelDkhn opened 7 months ago

raphaelDkhn commented 7 months ago

Currently, fixed points in Orion are represented by a struct defined as follows:

FP {
  mag: usize,
  sign: bool
}

The mag field represents the magnitude, and the sign field indicates the sign of the number, with false being positive and true being negative. This structure was initially chosen because Cairo did not natively support signed integers at the time. Presently, we support four fixed point types: FP16x16, FP8x23, FP32x32, and FP64x64. The last two types were adopted from the Cubit library.

Given that Cairo now natively supports signed integers, we should update our fixed point implementation to use native signed integers instead of the current struct-based approach.

Given the extensive changes required, an initial PR could focus on the FP16x16 implementation. Since the Tensor and NN libraries heavily rely on FP16x16, we can start by introducing a new implementation in the fixed point directory named f16x16. This will allow us to refactor without removing the existing FP16x16 implementation and plan further updates in the Tensor and NN libraries in subsequent PRs.

zintarh commented 7 months ago

Hi @raphaelDkhn I would like to work on this