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 + (-12104085.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.1.tar.gz (88.4 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.1-py3-none-any.whl (63.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ffcc-0.1.1.tar.gz
  • Upload date:
  • Size: 88.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","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.1.tar.gz
Algorithm Hash digest
SHA256 943d40d66533b60932f15425057a203bf42cc3d9ade5404b0909646797d2d1a8
MD5 7287f2cfd0cdd09685a15dfa0f663037
BLAKE2b-256 d82d21a6a5de320e8389de23548ed3f51e885db901f4977727b1cd05e98405ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ffcc-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 63.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a81e264eaeec717cee0cf93699648a17aaf1bc8d705ef057835554daad671af1
MD5 a6e906a5aa81b3b59b7cfd110aba1237
BLAKE2b-256 1a1c18ef3b98a229b317c1d290f99c017a842711a754540d021c56722c5052a2

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