Skip to main content

Compiler for fast floating-point approximations

Project description

Fast Math Program Synthesis Tool:

Tool for generating fast approximations of floating point math by (ab)using the floating point representation.

This tool was produced for the ICML paper "Faster Activation Functions at the Edge for Post-Training Speedups" link.

Usage:

Basic usage (ffcc tool):

$ ffcc -e "silu(x) = x / (1 + exp(-x))" --approx=exp --tune=[-6,6] -o torch

This should give you, after some tuning time, the following torch module:

import torch
from torch import nn, Tensor


class FastSilu(nn.Module):
        def forward(self, x: Tensor) -> Tensor:
                v0 = (1064873152.0 + (-12104086.0 * x))
                v1 = v0.type(torch.int32).view(torch.float32)
                return (x / (1.0 + v1))

Flags explained:

  • -e $expr provides the input expression to approximate
  • -approx=exp approximates exponentiation (log and div can be added as well, though div support is experimental)
  • -tune=[-6,6] performs gradient-descent based constant tuning on the domain $[-6,6]$
  • -o torch prints the resulting code as a pytorch module

Development Environment:

There's a flake.nix file for all nixos users.

The python dependencies are managed through uv. Setting everything up usually involves running a combination of uv venv; uv sync --all-extras; source .venv/bin/activate.

To run tests, use lit tests/filecheck, there are no pytests yet.

There is an ffcc-opt tool available for testing.

License:

ffcc - fast float compiler - Copyright (C) 2025 Anton Lydike

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ffcc-0.1.3.tar.gz (90.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ffcc-0.1.3-py3-none-any.whl (63.8 kB view details)

Uploaded Python 3

File details

Details for the file ffcc-0.1.3.tar.gz.

File metadata

  • Download URL: ffcc-0.1.3.tar.gz
  • Upload date:
  • Size: 90.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ffcc-0.1.3.tar.gz
Algorithm Hash digest
SHA256 00c058228e26061ef7369207a4dec29e50d5cce40cd8413d50bfaa0aaac9992e
MD5 e7c95c1bb89f3f8490c92ae0caa6007e
BLAKE2b-256 ae76372c0426bc49582dab7c91b945482e68ccb22f5f6648f660f00f37cdf01f

See more details on using hashes here.

File details

Details for the file ffcc-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ffcc-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 63.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ffcc-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 49ea54c5564ceb286d0c95801bdcbe04a300d53df6ffeadd83b465bdbc4e5281
MD5 be35437bc3c13308e72e48b3c24035b6
BLAKE2b-256 8c5a72e5cfced27994f15921ee2194719b3690673ad0f512123fdc03de81657d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page