Skip to content

Code for the note "NF4 Isn't Information Theoretically Optimal (and that's Good)

Notifications You must be signed in to change notification settings

davisyoshida/abnormal-floats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This repo contains the code for generating AF4 codes described in this note. It also contains a a JAX transform which allows for quantizing arbitrary JAX models with new 4-bit codes.

Generating codes

The script generate_af4.py will produce the AF4 code for a variety of block sizes. It's really slow to run since a ton of numerical integration is needed, so you may want to swap in the approximate CDF as described in the appendix.

JAX transform

I've put helper code for doing absmax quantization with 4-bit codes in transform.py. It doesn't use a custom matmul kernel, so it will be a few times slower than solutions which do. On the othe hand it's extremely easy to use and modify if you're interested in messing around with different types of quantization.

About

Code for the note "NF4 Isn't Information Theoretically Optimal (and that's Good)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages