{"id":14212722,"url":"https://github.com/neuralmagic/AutoFP8","last_synced_at":"2025-08-09T07:31:39.430Z","repository":{"id":236116405,"uuid":"791495148","full_name":"neuralmagic/AutoFP8","owner":"neuralmagic","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-23T16:26:48.000Z","size":94,"stargazers_count":95,"open_issues_count":7,"forks_count":13,"subscribers_count":14,"default_branch":"main","last_synced_at":"2024-07-23T19:18:41.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neuralmagic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-24T20:26:27.000Z","updated_at":"2024-07-23T16:26:51.000Z","dependencies_parsed_at":"2024-06-15T23:32:26.631Z","dependency_job_id":"28619b8e-7007-49e5-b071-d2329a5c3aa6","html_url":"https://github.com/neuralmagic/AutoFP8","commit_stats":null,"previous_names":["neuralmagic/autofp8"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuralmagic%2FAutoFP8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuralmagic%2FAutoFP8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuralmagic%2FAutoFP8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuralmagic%2FAutoFP8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neuralmagic","download_url":"https://codeload.github.com/neuralmagic/AutoFP8/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":215988515,"owners_count":15959120,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-19T12:00:40.730Z","updated_at":"2025-08-09T07:31:39.411Z","avatar_url":"https://github.com/neuralmagic.png","language":"Python","funding_links":[],"categories":["Tools"],"sub_categories":["Other"],"readme":"# AutoFP8\n\n**ATTENTION: AutoFP8 has been deprecated in preference of [`llm-compressor`](https://github.com/vllm-project/llm-compressor), a library for producing all sorts of model compression in addition to FP8. Check out the [FP8 example here](https://github.com/vllm-project/llm-compressor/tree/main/examples/quantization_w8a8_fp8).**\n\n\u003cdetails\u003e\n\u003csummary\u003eOld content\u003c/summary\u003e\n  \nOpen-source FP8 quantization library for producing compressed checkpoints for running in vLLM - see https://github.com/vllm-project/vllm/pull/4332 for details on the implementation for inference. This library focuses on providing quantized weight, activation, and kv cache scales for FP8_E4M3 precision.\n\n[FP8 Model Collection from Neural Magic](https://huggingface.co/collections/neuralmagic/fp8-llms-for-vllm-666742ed2b78b7ac8df13127) with many accurate (\u003c1% accuracy drop) FP8 checkpoints ready for inference with vLLM. \n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/neuralmagic/AutoFP8/assets/3195154/c6bb9ddb-1bc9-48df-bf5f-9d7916dbd1f9\" width=\"40%\" /\u003e\n  \u003cimg src=\"https://github.com/neuralmagic/AutoFP8/assets/3195154/2e30d4c0-340a-4527-8ff7-e8d48a8807ca\" width=\"40%\" /\u003e\n\u003c/p\u003e\n\n## Installation\n\nClone this repo and install it from source:\n```bash\ngit clone https://github.com/neuralmagic/AutoFP8.git\npip install -e AutoFP8\n```\n\nA stable release will be published.\n\n## Quickstart\n\nThis package introduces the `AutoFP8ForCausalLM` and `BaseQuantizeConfig` objects for managing how your model will be compressed.\n\nOnce you load your `AutoFP8ForCausalLM`, you can tokenize your data and provide it to the `model.quantize(tokenized_text)` function to calibrate+compress the model.\n\nFinally, you can save your quantized model in a compressed checkpoint format compatible with vLLM using `model.save_quantized(\"my_model_fp8\")`.\n\nHere is a full example covering that flow:\n\n```python\nfrom transformers import AutoTokenizer\nfrom auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig\n\npretrained_model_dir = \"meta-llama/Meta-Llama-3-8B-Instruct\"\nquantized_model_dir = \"Meta-Llama-3-8B-Instruct-FP8\"\n\ntokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True)\nexamples = [\"auto_fp8 is an easy-to-use model quantization library\"]\nexamples = tokenizer(examples, return_tensors=\"pt\").to(\"cuda\")\n\nquantize_config = BaseQuantizeConfig(quant_method=\"fp8\", activation_scheme=\"dynamic\")\n\nmodel = AutoFP8ForCausalLM.from_pretrained(\n    pretrained_model_dir, quantize_config=quantize_config\n)\nmodel.quantize(examples)\nmodel.save_quantized(quantized_model_dir)\n```\n\nFinally, load it into vLLM for inference! Support began in v0.4.2 (`pip install vllm\u003e=0.4.2`). Note that hardware support for FP8 tensor cores must be available in the GPU you are using (Ada Lovelace, Hopper, and newer).\n\n```python\nfrom vllm import LLM\n\nmodel = LLM(\"Meta-Llama-3-8B-Instruct-FP8\")\n# INFO 05-10 18:02:40 model_runner.py:175] Loading model weights took 8.4595 GB\n\nprint(model.generate(\"Once upon a time\"))\n# [RequestOutput(request_id=0, prompt='Once upon a time', prompt_token_ids=[128000, 12805, 5304, 264, 892], prompt_logprobs=None, outputs=[CompletionOutput(index=0, text=' there was a man who fell in love with a woman. The man was so', token_ids=[1070, 574, 264, 893, 889, 11299, 304, 3021, 449, 264, 5333, 13, 578, 893, 574, 779], cumulative_logprob=-21.314169232733548, logprobs=None, finish_reason=length, stop_reason=None)], finished=True, metrics=RequestMetrics(arrival_time=1715378569.478381, last_token_time=1715378569.478381, first_scheduled_time=1715378569.480648, first_token_time=1715378569.7070432, time_in_queue=0.002267122268676758, finished_time=1715378570.104807), lora_request=None)]\n```\n\n## How to run FP8 quantized models\n\n[vLLM](https://github.com/vllm-project/vllm) has full support for FP8 models quantized with this package. Install vLLM with: `pip install vllm\u003e=0.4.2`\n\nThen simply pass the quantized checkpoint directly to vLLM's entrypoints! It will detect the checkpoint format using the `quantization_config` in the `config.json`.\n```python\nfrom vllm import LLM\nmodel = LLM(\"neuralmagic/Meta-Llama-3-8B-Instruct-FP8\")\n# INFO 05-06 10:06:23 model_runner.py:172] Loading model weights took 8.4596 GB\n\noutputs = model.generate(\"Once upon a time,\")\nprint(outputs[0].outputs[0].text)\n# ' there was a beautiful princess who lived in a far-off kingdom. She was kind'\n```\n\n## Checkpoint structure explanation\n\nHere we detail the experimental structure for the fp8 checkpoints.\n\nThe following is added to config.json\n```python\n\"quantization_config\": {\n    \"quant_method\": \"fp8\",\n    \"activation_scheme\": \"static\" or \"dynamic\"\n  },\n```\n\nEach quantized layer in the state_dict will have:\n\nIf the config has `\"activation_scheme\": \"static\"`:\n```\nmodel.layers.0.mlp.down_proj.weight              \u003c F8_E4M3\nmodel.layers.0.mlp.down_proj.input_scale         \u003c F32\nmodel.layers.0.mlp.down_proj.weight_scale        \u003c F32\n```\nIf config has `\"activation_scheme\": \"dynamic\"`:\n```\nmodel.layers.0.mlp.down_proj.weight              \u003c F8_E4M3\nmodel.layers.0.mlp.down_proj.weight_scale        \u003c F32\n```\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuralmagic%2FAutoFP8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneuralmagic%2FAutoFP8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuralmagic%2FAutoFP8/lists"}