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.0.tar.gz (88.5 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.0-py3-none-any.whl (63.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ffcc-0.1.0.tar.gz
  • Upload date:
  • Size: 88.5 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.0.tar.gz
Algorithm Hash digest
SHA256 7a17605fb10fd56eecd7f26f4527c1a7ab269da4db2374e6fe9c932799e3a56d
MD5 e74bbb60a9b999f40fccd5004ec89c43
BLAKE2b-256 8026e7f51e8a1b40729c75424d156bf27c3b83fc8d7091e22739e6b659767236

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ffcc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 63.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18734640809ea38b8d9a1e627af04c9151b2f436d2cfa98d10f9b23fa1809549
MD5 d13537c1d902068606d3a95c3cc86351
BLAKE2b-256 f6c645597dad767bb1df6fb46c5208deb0b5a68df2ee401a2ddf08b5201dd9a8

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