mlc-ai / mlc-llm

Universal LLM Deployment Engine with ML Compilation
https://llm.mlc.ai/
Apache License 2.0
19.04k stars 1.56k forks source link

[Bug] FP8 quantization accuracy loss with TinyLlama-1.1B-Chat-v1.0 #2579

Open razetime opened 4 months ago

razetime commented 4 months ago

🐛 Bug

When FP8 quantization is applied to the TinyLlama-1.1B-Chat-v1.0 model, the model responses are exclusively composed of the simplified chinese character . mlc chat with the quantized model gives the following:

$ mlc_llm chat --model-lib ./dist/libs/TinyLlama-1.1B-Chat-v1.0-fp8-cuda.so ./dist/TinyLlama-1.1B-Chat-v1.0-fp8-MLC
[2024-06-14 10:32:01] INFO auto_device.py:79: Found device: cuda:0
[2024-06-14 10:32:02] INFO auto_device.py:88: Not found device: rocm:0
[2024-06-14 10:32:03] INFO auto_device.py:88: Not found device: metal:0
[2024-06-14 10:32:03] INFO auto_device.py:79: Found device: vulkan:0
[2024-06-14 10:32:03] INFO auto_device.py:79: Found device: vulkan:1
[2024-06-14 10:32:04] INFO auto_device.py:88: Not found device: opencl:0
[2024-06-14 10:32:04] INFO auto_device.py:35: Using device: cuda:0
[2024-06-14 10:32:04] INFO engine_base.py:141: Using library model: ./dist/libs/TinyLlama-1.1B-Chat-v1.0-fp8-cuda.so
[10:32:04] /workspace/mlc-llm/cpp/serve/config.cc:649: Under mode "local", max batch size will be set to 4, max KV cache token capacity will be set to 2048, prefill chunk size will be set to 2048. 
[10:32:04] /workspace/mlc-llm/cpp/serve/config.cc:649: Under mode "interactive", max batch size will be set to 1, max KV cache token capacity will be set to 2048, prefill chunk size will be set to 2048. 
[10:32:04] /workspace/mlc-llm/cpp/serve/config.cc:649: Under mode "server", max batch size will be set to 80, max KV cache token capacity will be set to 163840, prefill chunk size will be set to 2048. 
[10:32:04] /workspace/mlc-llm/cpp/serve/config.cc:729: The actual engine mode is "interactive". So max batch size is 1, max KV cache token capacity is 2048, prefill chunk size is 2048.
[10:32:04] /workspace/mlc-llm/cpp/serve/config.cc:734: Estimated total single GPU memory usage: 1641.198 MB (Parameters: 1174.176 MB. KVCache: 110.518 MB. Temporary buffer: 356.504 MB). The actual usage might be slightly larger than the estimated number.
You can use the following special commands:
  /help               print the special commands
  /exit               quit the cli
  /stats              print out stats of last request (token/sec)
  /metrics            print out full engine metrics
  /reset              restart a fresh chat
  /set [overrides]    override settings in the generation config. For example,
                      `/set temperature=0.5;top_p=0.8;seed=23;max_tokens=100;stop=str1,str2`
                      Note: Separate stop words in the `stop` option with commas (,).
  Multi-line input: Use escape+enter to start a new line.

>>> hello
给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给给 [output truncated due to context length limit...]

To Reproduce

Steps to reproduce the behavior:

mkdir fp8-debug && cd fp8-debug
mkdir -p dist/models && cd dist/models
git lfs install # if not done yet
git clone https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0
cd ../..

mlc_llm convert_weight ./dist/models/TinyLlama-1.1B-Chat-v1.0/ \
    --quantization e4m3_e4m3_f16 \
    -o dist/TinyLlama-1.1B-Chat-v1.0-fp8-MLC

mlc_llm gen_config dist/models/TinyLlama-1.1B-Chat-v1.0/ \
    --quantization e4m3_e4m3_f16 --conv-template llama \
    -o dist/TinyLlama-1.1B-Chat-v1.0-fp8-MLC

mlc_llm compile dist/TinyLlama-1.1B-Chat-v1.0-fp8-MLC/mlc-chat-config.json --device cuda -o dist/libs/TinyLlama-1.1B-Chat-v1.0-fp8-cuda.so

mlc_llm chat --model-lib ./dist/libs/TinyLlama-1.1B-Chat-v1.0-fp8-cuda.so ./dist/TinyLlama-1.1B-Chat-v1.0-fp8-MLC

Expected behavior

The model must reply with english words, and in general avoid severe loss of accuracy in response.

Environment

fan-niu commented 1 week ago

@razetime Hi I have the same problem, I used the same command as you, and mlc used the latest main branch. Do you have any progress? Thank you

@tqchen Can you help take a look this issue? thanks