Skip to content

PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度

refine mllm docs (#336)

WeiweiZhang1182dd3fb9b2c
diff --git a/README.md b/README.md
index 5fd40c0e8..59fe9e2ba 100644
--- a/README.md
+++ b/README.md
@@ -313,6 +313,11 @@ release most of the models ourselves.
Model | Supported |
|----------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| Qwen/Qwen2-VL-Instruct | [recipe](./docs/Qwen2-VL-7B-Instruct_sym.md) |
+| meta-llama/Llama-3.2-11B-Vision | [recipe](./docs/Llama-3.2-11B-Vision-Instruct_sym.md) |
+| microsoft/Phi-3.5-vision-instruct | [recipe](./docs/Phi-3.5-vision-instruct_sym.md) |
+| liuhaotian/llava-v1.5-7b | [recipe](./docs/llava-v1.5-7b_sym.md) |
+| Qwen/Qwen2.5-7B-Instruct | [recipe](./docs/Qwen2.5-7B-Instruct_sym.md) |
| meta-llama/Meta-Llama-3.1-70B-Instruct | [recipe](https://huggingface.co/Intel/Meta-Llama-3.1-70B-Instruct-int4-inc) |
| meta-llama/Meta-Llama-3.1-8B-Instruct | [model-kaitchup-autogptq-int4*](https://huggingface.co/kaitchup/Meta-Llama-3.1-8B-Instruct-autoround-gptq-4bit-asym), [model-kaitchup-autogptq-sym-int4*](https://huggingface.co/kaitchup/Meta-Llama-3.1-8B-Instruct-autoround-gptq-4bit-sym), [recipe](https://huggingface.co/Intel/Meta-Llama-3.1-8B-Instruct-int4-inc) |
| meta-llama/Meta-Llama-3.1-8B | [model-kaitchup-autogptq-sym-int4*](https://huggingface.co/kaitchup/Meta-Llama-3.1-8B-autoround-gptq-4bit-sym) |
diff --git a/auto_round/mllm/README.md b/auto_round/mllm/README.md
index 50efca1e6..c2a05df35 100644
--- a/auto_round/mllm/README.md
+++ b/auto_round/mllm/README.md
@@ -1,105 +1,142 @@
# AutoRound for MLLMs
-## Basic Usage (Gaudi2/CPU/GPU)
+## Quantization
-A user guide detailing the full list of supported arguments is provided by calling ```auto-round-mllm -h``` on the
-terminal.Alternatively, you can use ```auto_round_mllm``` instead of ```auto-round-mllm```. Set the format you want
-in `format` and
-multiple formats exporting has been supported.
+### API Usage (Gaudi2/CPU/GPU) Recommended
+AutoRound uses the text module of MLLM (LLM component) as the main quantization target. with NeelNanda/pile-10k as the default calibration dataset.
-```bash
-# experimental feature, default hyperparameters may be changed later
-auto—round-mllm \
- --model Qwen/Qwen2-VL-2B-Instruct\
- --bits 4 \
- --batch_size 1 \
- --gradient_accumulate_steps 4 \
- --group_size 128 \
- --format "auto_round" \
- --output_dir ./tmp_autoround
+```python
+ from auto_round import AutoRoundMLLM
+ from transformers import Qwen2VLForConditionalGeneration, AutoProcessor, AutoTokenizer
+ ## load the model
+ model_name = "Qwen/Qwen2-VL-2B-Instruct"
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
+ processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=trust_remote_code)
+ model = Qwen2VLForConditionalGeneration.from_pretrained(
+ model_name, trust_remote_code=True)
+
+ ## quantize the model
+ bits, group_size = 4, 128
+ autoround = AutoRoundMLLM(model, tokenizer, processor, bits=bits, group_size=group_size)
+ autoround.quantize()
+
+ # save the quantized model, set format='auto_gptq' to use AutoGPTQ format
+ output_dir = "./tmp_autoround"
+ autoround.save_quantized(output_dir, format='auto_round', inplace=True)
```
-## API Usage (Gaudi2/CPU/GPU)
+<details>
+<summary style="font-size:17px;">Basic Usage (Gaudi2/CPU/GPU)</summary>
+ A user guide detailing the full list of supported arguments is provided by calling ```auto-round-mllm -h``` on the terminal. Alternatively, you can use ```auto_round_mllm``` instead of ```auto-round-mllm```. Set the format you want in `format` and
+ multiple formats exporting has been supported.
-```python
-from auto_round import AutoRoundMLLM
-from transformers import Qwen2VLForConditionalGeneration, AutoProcessor, AutoTokenizer
-
-model_name = "Qwen/Qwen2-VL-2B-Instruct"
-tokenizer = AutoTokenizer.from_pretrained(model_name)
-processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=trust_remote_code)
-tokenizer.processor = processor
-model = Qwen2VLForConditionalGeneration.from_pretrained(
- model_name, trust_remote_code=True)
-dataset = "/path/to/llava.json"
-extra_data_dir = "/path/to/images/dir"
-
-bits, group_size = 4, 128
-autoround = AutoRoundMLLM(model, tokenizer, bits=bits, group_size=group_size, dataset=dataset,
- extra_data_dir=extra_data_dir)
-
-autoround.quantize()
-output_dir = "./tmp_autoround"
-autoround.save_quantized(output_dir, format='auto_round', inplace=True)
+```bash
+ # experimental feature, default hyperparameters may be changed later
+ auto—round-mllm \
+ --model Qwen/Qwen2-VL-2B-Instruct \
+ --bits 4 \
+ --group_size 128 \
+ --format "auto_round" \
+ --output_dir ./tmp_autoround
```
-### Dataset
+- `dataset`: the dataset for quantization training. current support NeelNanda/pile-10k,llava_conv_58k,llava_instruct_80k. It can be a custom one.
-For mllm, we used liuhaotian/llava_conv_58k as our default calib datasets. Through argument ```--dataset```, user can
-use other datasets such as "liuhaotian/llava_instruct_80k", "liuhaotian/llava_instruct_150k" or a file path to use local
-file.
+- `quant_nontext_module`: whether to quantize non-text module, e.g. vision component.
-### Support Matrix
+- `extra_data_dir`:dataset dir for storing images/audio/videos, default to None. Can be a dir path or multiple dir path with format as 'image=path_to_image,video=path_to_video,audio=path_to_audio' By default, it will search in the relative path, and if not find, will automatic download.
+
+</details>
+
+
+<details>
+<summary style="font-size:17px;">Calibration Dataset</summary>
-So far, auto-round for mllm supports five model families, include Qwen2-VL, Llama-Vision, Phi3-Vision, Llava-v1.5 and
-CogVLM2.
+For mllm, we used **text-only** calibration dataset (NeelNanda/pile-10k) as our default. If the model type does not support plain text calibration(e.g. Llama-3.2-vision), it will also automatically switch to llava dataset and adjust the hyperparameters.
-| Model | Eval Lib | calibration dataset | quant nontext module |
-|--------------|-----------|---------------------|----------------------|
-| Qwen2-VL | vlmeval | pile/llava | - |
-| Llama-Vision | lmms_eval | llava | ✔ |
-| Phi3-Vision | vlmeval | pile/llava | ✔ |
-| Llava-v1.5 | lmms_eval | pile/llava | - |
-| CogVLM2 | lmms_eval | pile/llava | ✔ |
+Through argument --dataset(text file), user can use other datasets such as "liuhaotian/llava_conv_58k" "liuhaotian/llava_instruct_80k", "liuhaotian/llava_instruct_150k" or a file path to use local file.
-## New Models Support
-### Template
+### Support List
+
+The llava calibration dataset supports the five existing MLLMs.
+
+|Model |Eval Lib |calibration dataset|Feasibility of quantification|
+|---------------|-----------|-------------------|--------------------|
+|Qwen/Qwen2-VL-Instruct |vlmeval |llava |✔ |
+|meta-llama/Llama-3.2-11B-Vision |vlmeval/lmms_eval |llava |✔ |
+|microsoft/Phi-3.5-vision-instruct |vlmeval |llava |✔ |
+|liuhaotian/llava-v1.5-7b |lmms_eval |llava |✔ |
+|THUDM/cogvlm2-llama3-chat-19B |lmms_eval |llava |✔ |
+
+</details>
+
+
+
+<details>
+<summary style="font-size:17px;">Nontext Module Quantization</summary>
+
+### Support Matrix
-For autoround MLLMs, using Template to customize different operations for different models. User can add a custom chat
-template through json file as below.
+The design of the MLLM model API is not uniform, and some models do not support the quantization nontext module. Quantization of the vision components of Llama-3.2-11B-Vision, Phi-3.5-vision-instruct and llava-v1.5-7b is currently supported.
+|Model |Eval Lib |quant nontext module|
+|---------------|-----------|-------------------|
+|Qwen/Qwen2-VL-Instruct |vlmeval |- |
+|meta-llama/Llama-3.2-11B-Vision |lmms_eval |✔ |
+|microsoft/Phi-3.5-vision-instruct |vlmeval |✔ |
+|liuhaotian/llava-v1.5-7b |lmms_eval |- |
+|THUDM/cogvlm2-llama3-chat-19B |lmms_eval |✔ |
+
+
+
+### New Models Support
+#### Template
+For autoround MLLMs, using Template to customize different operations for different models. User can add a custom chat template through json file as below.
```json
{
- "model_type": "qwen2_vl",
- "format_user": "<|im_start|>user\n{{content}}<|im_end|>\n",
- "format_assistant": "<|im_start|>assistant\n{{content}}<|im_end|>\n",
- "format_system": "<|im_start|>system\n{{content}}<|im_end|>\n",
- "format_observation": "<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n",
- "format_separator": "\n",
- "default_system": "You are a helpful assistant.",
- "replace_tokens": [
- "<image>",
- "<|vision_start|><|image_pad|><|vision_end|>"
- ],
- "extra_encode": "True",
- "processor": "qwen2_vl"
+ "model_type": "qwen2_vl",
+ "format_user": "<|im_start|>user\n{{content}}<|im_end|>\n",
+ "format_assistant": "<|im_start|>assistant\n{{content}}<|im_end|>\n",
+ "format_system": "<|im_start|>system\n{{content}}<|im_end|>\n",
+ "format_observation": "<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n",
+ "format_separator": "\n",
+ "default_system": "You are a helpful assistant.",
+ "replace_tokens": ["<image>", "<|vision_start|><|image_pad|><|vision_end|>"],
+ "extra_encode": "True",
+ "processor": "qwen2_vl"
}
```
-
-The special token ```{{content}}``` is a placeholder to tell the preprocessor where to fill in the corresponding
-dialogue content.
+The special token ```{{content}}``` is a placeholder to tell the preprocessor where to fill in the corresponding dialogue content.
```format_*```: Add specific token to chat content depends on different role names.
For example, the input conversations:<br>
-```[{'role': 'user', 'value': '<image>\nWhat are the colors of the bus in the image?'}, {'role': 'assistant', 'value': 'The bus in the image is white and red.'}]```
+ ```[{'role': 'user', 'value': '<image>\nWhat are the colors of the bus in the image?'}, {'role': 'assistant', 'value': 'The bus in the image is white and red.'}]```
Using the above template, the input will be converted to the specified format required by Qwen2-vl as below: <br>
-```'<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<|vision_start|><|image_pad|><|vision_end|>\nWhat are the colors of the bus in the image?<|im_end|>\n<|im_start|>assistant\nThe bus in the image is white and red.<|im_end|>\n<|im_start|>user\nWhat feature can be seen on the back of the bus?<|im_end|>\n<|im_start|>assistant\nThe back of the bus features an advertisement.<|im_end|>\n<|im_start|>user\nIs the bus driving down the street or pulled off to the side?<|im_end|>\n<|im_start|>assistant\nThe bus is driving down the street, which is crowded with people and other vehicles.<|im_end|>\n'```.
+ ```'<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<|vision_start|><|image_pad|><|vision_end|>\nWhat are the colors of the bus in the image?<|im_end|>\n<|im_start|>assistant\nThe bus in the image is white and red.<|im_end|>\n<|im_start|>user\nWhat feature can be seen on the back of the bus?<|im_end|>\n<|im_start|>assistant\nThe back of the bus features an advertisement.<|im_end|>\n<|im_start|>user\nIs the bus driving down the street or pulled off to the side?<|im_end|>\n<|im_start|>assistant\nThe bus is driving down the street, which is crowded with people and other vehicles.<|im_end|>\n'```.
+
+#### Processor
+Processor is callback interface for calling different processors, such as texts or images processors, for MLLMs. User can define own processor and use registration function to declare. For more information, please refer to the relevant code in ```auto_round/mllm/processor.py```.
+
+</details>
+
+
+
+## Inference for Models
+For the AutoRound format, please add the following code at the beginning of the original model's inference code.
+
+```python
+from auto_round import AutoRoundConfig ## must import for auto-round format
+```
+
+For more details on quantization, inference, evaluation, and environment, see the following recipe:
+
+- [Qwen2-VL-Instruct](../../docs/Qwen2-VL-7B-Instruct_sym.md)
+- [Llama-3.2-11B-Vision](../../docs/Llama-3.2-11B-Vision-Instruct_sym.md)
+- [Phi-3.5-vision-instruct](../../docs/Phi-3.5-vision-instruct_sym.md)
+- [llava-v1.5-7b](../../docs/llava-v1.5-7b_sym.md)
+
-### Processor
-Processor is callback interface for calling different processors, such as texts or images processors, for MLLMs. User
-can define own processor and use registration function to declare. For more information, please refer to the relevant
-code in ```auto_round/mllm/processor.py```.
\ No newline at end of file
diff --git a/docs/Llama-3.2-11B-Vision-Instruct_sym.md b/docs/Llama-3.2-11B-Vision-Instruct_sym.md
new file mode 100644
index 000000000..86a17ab98
--- /dev/null
+++ b/docs/Llama-3.2-11B-Vision-Instruct_sym.md
@@ -0,0 +1,144 @@
+
+## Model Details
+
+This model is an int4 model with group_size 128 and symmetric quantization of [meta-llama/Llama-3.2-11B-Vision-Instruct](https://huggingface.co/meta-llama/Llama-3.2-11B-Vision-Instruct). Load the model with revision="f036ca" to use AutoGPTQ format.
+
+## How To Use
+
+### Requirements
+Please use Transformers version 4.45.0 or later
+
+
+### INT4 Inference
+```python
+from auto_round import AutoRoundConfig ## must import for auto-round format
+import requests
+import torch
+from PIL import Image
+from transformers import MllamaForConditionalGeneration, AutoProcessor
+
+quantized_model_path="Intel/Llama-3.2-11B-Vision-Instruct-inc-private"
+
+model = MllamaForConditionalGeneration.from_pretrained(
+ quantized_model_path,
+ torch_dtype="auto",
+ device_map="auto",
+ ##revision="f036ca" ##AutoGPTQ format
+)
+processor = AutoProcessor.from_pretrained(quantized_model_path)
+image_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/0052a70beed5bf71b92610a43a52df6d286cd5f3/diffusers/rabbit.jpg"
+messages = [
+ {"role": "user", "content": [
+ {"type": "image"},
+ {"type": "text", "text": "Please write a haiku for this one, it would be: "}
+ ]}
+]
+
+# Preparation for inference
+image = Image.open(requests.get(image_url, stream=True).raw)
+input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
+inputs = processor(
+ image,
+ input_text,
+ add_special_tokens=False,
+ return_tensors="pt"
+).to(model.device)
+
+output = model.generate(**inputs, max_new_tokens=50)
+print(processor.decode(output[0]))
+
+##INT4:
+## Here is a haiku for the rabbit:
+
+## Whiskers twitching bright
+## Ears perked up, alert and keen
+## Spring's gentle delight<|eot_id|>
+
+
+##BF16:
+## Here is a haiku for the rabbit:
+
+## Whiskers twitching fast
+## In a coat of blue and brown
+## Hoppy little soul<|eot_id|>
+
+image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
+messages = [
+ {"role": "user", "content": [
+ {"type": "image"},
+ {"type": "text", "text": "How many people are on the baseball field in the picture?"}
+ ]}
+]
+##INT4: There are five people on the baseball field in the picture.
+##
+
+##BF16: There are five people on the baseball field in the picture.
+##
+
+image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
+messages = [
+ {"role": "user", "content": [
+ {"type": "image"},
+ {"type": "text", "text": "Which company does this picture represent?"}
+ ]}
+]
+##INT4: This picture represents Intel.
+##
+
+##BF16: This image represents Intel, a multinational semiconductor corporation headquartered in Santa Clara, California.
+##
+
+```
+
+## Evaluation the model
+pip3 install git+https://github.com/open-compass/VLMEvalKit.git@7de2dcb
+```bash
+auto-round-mllm --eval --model Intel/Llama-3.2-11B-Vision-Instruct-inc-private --tasks MMBench_DEV_EN_V11,ScienceQA_VAL,TextVQA_VAL,POPE --output_dir "./eval_result"
+```
+|Metric |16bits|Pile Calib INT4 |Llava Calib INT4|
+|:-------------------|:------|:------|:------|
+|avg |66.05 |67.81 |66.02 |
+|MMBench_DEV_EN_V11 |52.86 |53.48 |52.17 |
+|ScienceQA_VAL |68.86 |70.39 |69.15 |
+|TextVQA_VAL |54.49 |59.62 |55.07 |
+|POPE |88.00 |87.76 |87.71 |
+
+### Generate the model
+Here is the sample command to reproduce the model.
+```bash
+pip install auto_round
+auto-round-mllm
+--model meta-llama/Llama-3.2-11B-Vision-Instruct \
+--device 0 \
+--group_size 128 \
+--bits 4 \
+--iters 1000 \
+--nsample 512 \
+--seqlen 512 \
+--format 'auto_gptq,auto_round' \
+--output_dir "./tmp_autoround"
+```
+
+## Ethical Considerations and Limitations
+
+The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
+
+Therefore, before deploying any applications of the model, developers should perform safety testing.
+
+## Caveats and Recommendations
+
+Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
+
+Here are a couple of useful links to learn more about Intel's AI software:
+
+- Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
+
+## Disclaimer
+
+The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
+
+## Cite
+
+@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
+
+[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)
diff --git a/docs/Phi-3.5-vision-instruct_sym.md b/docs/Phi-3.5-vision-instruct_sym.md
new file mode 100644
index 000000000..bb1f94238
--- /dev/null
+++ b/docs/Phi-3.5-vision-instruct_sym.md
@@ -0,0 +1,156 @@
+
+## Model Details
+
+This model is an int4 model with group_size 128 and symmetric quantization of [microsoft/Phi-3.5-vision-instruct](https://huggingface.co/microsoft/Phi-3.5-vision-instruct). Load the model with revision="13b4c3d" to use AutoGPTQ format.
+## How To Use
+
+
+### Requirements
+
+The current `transformers` version can be verified with: `pip list | grep transformers`.
+
+Examples of required packages:
+```
+flash_attn==2.5.8
+numpy==1.24.4
+Pillow==10.3.0
+Requests==2.31.0
+torch==2.3.0
+torchvision==0.18.0
+transformers==4.43.0
+accelerate==0.30.0
+```
+
+
+### INT4 Inference
+```python
+from auto_round import AutoRoundConfig ##must import for auto-round format
+import requests
+from PIL import Image
+from transformers import AutoModelForCausalLM, AutoTokenizer, AutoProcessor
+
+model_id = "Intel/Phi-3.5-vision-instruct-inc-private"
+
+model = AutoModelForCausalLM.from_pretrained(
+ model_id,
+ device_map="auto",
+ trust_remote_code=True,
+ torch_dtype="auto",
+ ##revision="13b4c3d" ##AutoGPTQ format
+)
+processor = AutoProcessor.from_pretrained(model_id,
+ trust_remote_code=True,
+ num_crops=4
+)
+
+image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
+content = "Describe this image."
+messages = [
+ {"role": "user",
+ "content": "<|image_1|>\n"+content},
+]
+
+prompt = processor.tokenizer.apply_chat_template(
+ messages,
+ tokenize=False,
+ add_generation_prompt=True
+)
+image_inputs = Image.open(requests.get(image_url, stream=True).raw)
+inputs = processor(prompt, image_inputs, return_tensors="pt").to(model.device)
+
+generation_args = {
+ "max_new_tokens": 1000,
+ "temperature": 0.0,
+ "do_sample": False,
+}
+
+generate_ids = model.generate(**inputs,
+ eos_token_id=processor.tokenizer.eos_token_id,
+ **generation_args
+)
+
+# remove input tokens
+generate_ids = generate_ids[:, inputs['input_ids'].shape[1]:]
+response = processor.batch_decode(generate_ids,
+ skip_special_tokens=True,
+ clean_up_tokenization_spaces=False)[0]
+
+print(response)
+##INT4:
+## The image captures a serene beach scene at sunset with a person and a dog. The person is seated on the sand, reading a book, while the dog, wearing a harness, sits attentively beside them. The sun is low on the horizon, casting a warm glow and long shadows on the sand. The ocean is calm, and the sky is clear, suggesting a peaceful end to the day.
+
+##BF16:
+## The image shows a person sitting on a sandy beach with a dog. The person is wearing a plaid shirt and is holding a book, while the dog is sitting next to them, looking at the book. The beach is near the ocean, and the sun is low in the sky, suggesting it is either sunrise or sunset. The sky is clear, and the overall atmosphere is calm and serene.
+
+
+image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
+content = "How many people are there on the baseball field in the image?"
+##INT4:
+## There are three people on the baseball field in the image.
+
+##BF16:
+## There are three people on the baseball field in the image.
+
+
+image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
+content = "This image represents which company?"
+##INT4:
+## The image represents the company Intel, as indicated by the text 'intel INSIDE'.
+
+##BF16:
+## The image represents the company Intel, as indicated by the logo and the text 'INSIDE'.
+```
+
+
+## Evaluation the model
+pip3 install git+https://github.com/open-compass/VLMEvalKit.git@7de2dcb
+```bash
+auto-round-mllm --eval --model Intel/Qwen2-VL-7B-Instruct-inc-private --tasks MMBench_DEV_EN_V11,ScienceQA_VAL,TextVQA_VAL,POPE --output_dir "./eval_result"
+```
+|Metric |16bits|Pile Calib INT4 | Llava Calib INT4 |
+|-------------------|:------|:------|:------|
+|avg |77.64 |77.14 |76.87|
+|MMBench_DEV_EN_V11 |71.83 |71.36 |70.90|
+|ScienceQA_VAL |90.56 |89.75 |89.13|
+|TextVQA_VAL |65.36 |64.77 |64.66|
+|POPE |82.82 |82.67 |82.80|
+
+### Generate the model
+Here is the sample command to reproduce the model.
+```bash
+pip install auto_round
+auto-round-mllm
+--model microsoft/Phi-3.5-vision-instruct \
+--device 0 \
+--group_size 128 \
+--bits 4 \
+--iters 1000 \
+--nsample 512 \
+--seqlen 2048 \
+--format 'auto_gptq,auto_round' \
+--output_dir "./tmp_autoround"
+```
+
+## Ethical Considerations and Limitations
+
+The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
+
+Therefore, before deploying any applications of the model, developers should perform safety testing.
+
+## Caveats and Recommendations
+
+Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
+
+Here are a couple of useful links to learn more about Intel's AI software:
+
+- Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
+
+## Disclaimer
+
+The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
+
+## Cite
+
+@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
+
+[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)
diff --git a/docs/Qwen2-VL-7B-Instruct_sym.md b/docs/Qwen2-VL-7B-Instruct_sym.md
new file mode 100644
index 000000000..0ac51b53d
--- /dev/null
+++ b/docs/Qwen2-VL-7B-Instruct_sym.md
@@ -0,0 +1,162 @@
+
+## Model Details
+
+This model is an int4 model with group_size 128 and symmetric quantization of [Qwen/Qwen2-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct). Load the model with revision="a7269c6" to use AutoGPTQ format.
+
+## How To Use
+
+
+### Requirements
+Please use Transformers version 4.45.0 or later, or you might encounter the following error:
+```
+KeyError: 'qwen2_vl'
+```
+
+### INT4 Inference
+```python
+from auto_round import AutoRoundConfig ## must import for auto-round format
+import requests
+from PIL import Image
+from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
+
+model = Qwen2VLForConditionalGeneration.from_pretrained(
+ "Intel/Qwen2-VL-7B-Instruct-inc-private",
+ torch_dtype="auto",
+ device_map="auto",
+ ##revision="a7269c6" ##AutoGPTQ format
+)
+processor = AutoProcessor.from_pretrained("Intel/Qwen2-VL-7B-Instruct-inc-private")
+image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
+messages = [
+ {
+ "role": "user",
+ "content": [
+ {
+ "type": "image",
+ "image": image_url,
+ },
+ {"type": "text", "text": "Describe this image."},
+ ],
+ }
+]
+
+# Preparation for inference
+text = processor.apply_chat_template(
+ messages, tokenize=False, add_generation_prompt=True
+)
+image_inputs = Image.open(requests.get(image_url, stream=True).raw)
+inputs = processor(
+ text=[text],
+ images=image_inputs,
+ padding=True,
+ return_tensors="pt",
+)
+inputs = inputs.to(model.device)
+
+generated_ids = model.generate(**inputs, max_new_tokens=128)
+generated_ids_trimmed = [
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
+]
+output_text = processor.batch_decode(
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
+)
+print(output_text[0])
+
+##INT4:
+## 'The image depicts a serene beach scene with a woman and her dog. The woman is sitting on the sand, facing the ocean, and appears to be engaging in a playful interaction with her dog. The dog, which is wearing a harness, is sitting beside her and has its front paw raised, seemingly giving a high-five to the woman. The woman is smiling and seems to be enjoying the moment. The beach is relatively empty, with gentle waves in the background, and the lighting suggests it is either early morning or late afternoon, creating a warm and peaceful atmosphere.'
+
+##BF16:
+## "The image depicts a serene beach scene with a woman and her dog enjoying a moment together. The woman is sitting on the sandy beach, facing the ocean, and appears to be engaging in a playful activity with her dog. She is wearing a plaid shirt and dark pants, and her hair is long and dark. The dog, which is a large breed, possibly a Labrador Retriever, is sitting in front of her, wearing a harness. The dog is extending its front paw towards the woman's hand, as if it is giving her a high-five. The woman is smiling and seems to be enjoying the interaction.\n\nThe beach is"
+
+image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
+messages = [
+ {
+ "role": "user",
+ "content": [
+ {
+ "type": "image",
+ "image": image_url,
+ },
+ {"type": "text", "text": "图片中的棒球场上有多少人?"},
+ ],
+ }
+]
+##INT4:
+## 图片中的棒球场上有五个人。
+
+##BF16:
+## 图片中的棒球场上有三个人。
+
+image_url = "https://intelcorp.scene7.com/is/image/intelcorp/processor-overview-framed-badge:1920-1080?wid=480&hei=270"
+messages = [
+ {
+ "role": "user",
+ "content": [
+ {
+ "type": "image",
+ "image": image_url,
+ },
+ {"type": "text", "text": "这张图片代表哪家公司?"},
+ ],
+ }
+]
+##INT4:
+## 这张图片代表英特尔公司(Intel)。英特尔是全球领先的半导体公司,主要生产中央处理器(CPU)和其他计算机硬件。
+
+##BF16:
+## 这张图片代表英特尔公司(Intel)。图片中的标志是英特尔的标志,标志下方的文字“Intel Inside”表明这是英特尔的宣传标志,用于表明该产品使用了英特尔的处理器或其他技术。
+
+```
+
+## Evaluation the model
+pip3 install git+https://github.com/open-compass/VLMEvalKit.git@7de2dcb
+```bash
+auto-round-mllm --eval --model Intel/Qwen2-VL-7B-Instruct-inc-private --tasks MMBench_DEV_EN_V11,ScienceQA_VAL,TextVQA_VAL,POPE --output_dir "./eval_result"
+```
+|Metric |16bits|Pile Calib INT4 | Llava Calib INT4 |
+|:-------------------|:------|:------|:------|
+|avg |83.92 |83.82 |83.42 |
+|MMBench_DEV_EN_V11 |80.50 |79.64 |80.42 |
+|ScienceQA_VAL |84.69 |83.88 |83.26 |
+|TextVQA_VAL |84.36 |84.28 |84.11 |
+|POPE |86.13 |87.57 |85.89 |
+
+### Generate the model
+Here is the sample command to reproduce the model.
+```bash
+pip install auto_round
+auto-round-mllm
+--model Qwen/Qwen2-VL-7B-Instruct \
+--device 0 \
+--group_size 128 \
+--bits 4 \
+--iters 1000 \
+--nsample 512 \
+--seqlen 2048 \
+--format 'auto_gptq,auto_round' \
+--output_dir "./tmp_autoround"
+```
+
+## Ethical Considerations and Limitations
+
+The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
+
+Therefore, before deploying any applications of the model, developers should perform safety testing.
+
+## Caveats and Recommendations
+
+Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
+
+Here are a couple of useful links to learn more about Intel's AI software:
+
+- Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
+
+## Disclaimer
+
+The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
+
+## Cite
+
+@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
+
+[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)
diff --git a/docs/Qwen2.5-7B-Instruct_sym.md b/docs/Qwen2.5-7B-Instruct_sym.md
new file mode 100644
index 000000000..f20e652a1
--- /dev/null
+++ b/docs/Qwen2.5-7B-Instruct_sym.md
@@ -0,0 +1,185 @@
+## Model Details
+
+This model is an int4 model with group_size 128 and symmetric quantization of [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) generated by [intel/auto-round](https://github.com/intel/auto-round). Load the model with `revision="5a6d912"` to use AutoGPTQ format
+
+## How To Use
+
+### INT4 Inference(CPU/HPU/CUDA)
+
+CPU requires auto-round version>0.3.1
+
+```python
+from auto_round import AutoRoundConfig ##must import for auto-round format
+from transformers import AutoModelForCausalLM,AutoTokenizer
+quantized_model_dir = "Intel/Qwen2.5-7B-Instruct-int4-inc"
+tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir)
+
+model = AutoModelForCausalLM.from_pretrained(
+ quantized_model_dir,
+ torch_dtype='auto',
+ device_map="auto",
+ ##revision="0b70f95" ##AutoGPTQ format
+ ##revision="5a6d912" ##Quantized lm-head version
+
+)
+
+##import habana_frameworks.torch.core as htcore ## uncommnet it for HPU
+##import habana_frameworks.torch.hpu as hthpu ## uncommnet it for HPU
+##model = model.to(torch.bfloat16).to("hpu") ## uncommnet it for HPU
+
+prompt = "There is a girl who likes adventure,"
+messages = [
+ {"role": "system", "content": "You are a helpful assistant."},
+ {"role": "user", "content": prompt}
+]
+
+text = tokenizer.apply_chat_template(
+ messages,
+ tokenize=False,
+ add_generation_prompt=True
+)
+model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
+
+generated_ids = model.generate(
+ model_inputs.input_ids,
+ max_new_tokens=200, ##change this to align with the official usage
+ do_sample=False ##change this to align with the official usage
+)
+generated_ids = [
+output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
+]
+
+response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
+print(response)
+
+prompt = "There is a girl who likes adventure,"
+##INT4:
+"""That's great! It sounds like this girl has an exciting spirit. How can I help you explore her love for adventure? Are you looking for ideas for adventurous activities, planning a trip, or perhaps looking for ways to support her adventurous nature?
+"""
+
+##BF16:
+"""That sounds exciting! What kind of adventures does she enjoy? Is there something specific you'd like to plan or discuss related to her love for adventure?
+"""
+
+prompt = "9.11和9.8哪个数字大"
+#INT4:
+"""在比较9.11和9.8时,我们从左到右逐位进行比较:
+
+1. 首先比较整数部分:两个数的整数部分都是9,相等。
+2. 接下来比较小数部分:
+ - 9.11的小数部分是0.11
+ - 9.8的小数部分是0.8
+
+将0.11和0.8进行比较,显然0.8大于0.11。
+
+因此,9.8比9.11大。
+"""
+
+##BF16:
+"""在比较9.11和9.8这两个数字时,我们可以直接进行比较:
+
+- 9.11 是九点一一
+- 9.8 是九点八
+
+显然,9.8 比 9.11 大。这是因为9.8中的十分位是8,而9.11中的十分位是1,8大于1。
+
+所以,9.8 > 9.11。"""
+
+
+prompt = "Once upon a time,"
+##INT4:
+"""Once upon a time, in a land filled with wonder and magic, there lived a young girl named Elara. She had bright eyes that sparkled like the stars on a clear night and hair as golden as the sun-kissed fields of wheat. Elara's home was a cozy cottage nestled at the edge of a vast, enchanted forest, where ancient trees whispered secrets to one another and mystical creatures roamed freely.
+
+Every day, Elara would venture into the forest, exploring its hidden paths and marveling at the wonders it held. One sunny morning, as she wandered deeper into the woods than ever before, she stumbled upon a glade bathed in a soft, ethereal light. In the center of this glade stood an enormous tree, its trunk wider than any building Elara had ever seen, and its branches stretching high into the sky.
+
+As she approached the tree, she noticed a small, shimmering door carved into its bark. Curious, Elara reached out and"""
+
+##BF16:
+"""Once upon a time, in a land filled with wonder and magic, there lived a young girl named Elara. She had bright eyes that sparkled like the stars on a clear night and hair as golden as the sun-kissed fields of wheat. Elara's home was a cozy cottage nestled at the edge of a vast, enchanted forest, where mythical creatures roamed freely and ancient trees whispered secrets of old.
+
+Every day, Elara would venture into the forest to gather herbs and flowers for her grandmother, who was a skilled healer. The forest was her sanctuary, a place where she could escape the worries of the world and find solace in nature's embrace. As she walked through the dense underbrush, she often stumbled upon hidden glades and sparkling streams, each more enchanting than the last.
+
+One sunny morning, as Elara was collecting wildflowers near a babbling brook, she heard a faint cry for help. Curious, she followed the sound to a clearing where"""
+
+
+prompt = "请简短介绍一下阿里巴巴公司"
+##INT4:
+"""阿里巴巴集团是一家总部位于中国杭州的全球领先电子商务和科技公司,成立于1999年。它由马云创立,旗下拥有包括淘宝、天猫、阿里云等在内的多个知名业务。阿里巴巴致力于构建全球化的商业生态系统,为消费者、企业和政府提供创新的在线解决方案。同时,阿里巴巴也是中国最大的零售市场之一,并在云计算、数字娱乐、物流等领域具有重要影响力。
+"""
+
+##BF16:
+"""阿里巴巴集团是一家总部位于中国杭州的全球领先电子商务和科技公司,成立于1999年。阿里巴巴旗下拥有淘宝、天猫、阿里云等知名业务,致力于构建全球化的商业生态系统。阿里巴巴愿景是让世界各地的企业都能够平等地进行贸易,并通过技术创新推动社会进步。
+"""
+```
+
+### Evaluate the model
+
+pip3 install lm-eval==0.4.5
+
+```bash
+auto-round --model "Intel/Qwen2.5-7B-Instruct-int4-inc" --eval --eval_bs 16 --tasks leaderboard_ifeval,leaderboard_mmlu_pro,gsm8k,lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,arc_easy,arc_challenge,cmmlu,ceval-valid
+```
+
+| Metric | BF16 | INT4 (5.3G) | INT4 lm-head (4.5G) |
+| :----------------------------------------- | :----: | :----: | ------------------- |
+| Avg | 0.6649 | 0.6586 | 0.6577 |
+| leaderboard_mmlu_pro 5 shots | 0.4458 | 0.4436 | 0.4384 |
+| leaderboard_ifeval inst_level_strict_acc | 0.6859 | 0.6715 | 0.6595 |
+| leaderboard_ifeval prompt_level_strict_acc | 0.5730 | 0.5508 | 0.5379 |
+| mmlu | 0.7174 | 0.7147 | 0.7145 |
+| cmmlu | 0.8028 | 0.7888 | 0.7888 |
+| ceval-valid | 0.7935 | 0.7838 | 0.7741 |
+| gsm8k 5 shots | 0.7665 | 0.7544 | 0.8006 |
+| lambada_openai | 0.6949 | 0.6878 | 0.6763 |
+| hellaswag | 0.6195 | 0.6139 | 0.6121 |
+| winogrande | 0.7119 | 0.7064 | 0.7135 |
+| piqa | 0.7938 | 0.7873 | 0.7845 |
+| truthfulqa_mc1 | 0.4786 | 0.4774 | 0.4810 |
+| openbookqa | 0.3480 | 0.3580 | 0.3540 |
+| boolq | 0.8636 | 0.8602 | 0.8609 |
+| arc_easy | 0.8131 | 0.8068 | 0.8081 |
+| arc_challenge | 0.5282 | 0.5316 | 0.5188 |
+
+
+
+### Generate the model
+
+Here is the sample command to generate the model.
+
+```bash
+auto-round \
+--model Qwen/Qwen2.5-7B-Instruct \
+--device 0 \
+--group_size 128 \
+--nsamples 512 \
+--bits 4 \
+--iter 1000 \
+--disable_eval \
+--model_dtype "fp16" \
+--format 'auto_gptq,auto_round' \
+--output_dir "./tmp_autoround"
+```
+
+## Ethical Considerations and Limitations
+
+The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
+
+Therefore, before deploying any applications of the model, developers should perform safety testing.
+
+## Caveats and Recommendations
+
+Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
+
+Here are a couple of useful links to learn more about Intel's AI software:
+
+- Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
+
+## Disclaimer
+
+The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
+
+## Cite
+
+@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
+
+[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)
diff --git a/docs/llava-v1.5-7b_sym.md b/docs/llava-v1.5-7b_sym.md
new file mode 100644
index 000000000..8c91b33e4
--- /dev/null
+++ b/docs/llava-v1.5-7b_sym.md
@@ -0,0 +1,133 @@
+
+## Model Details
+
+This model is an int4 model with group_size 128 and symmetric quantization of [liuhaotian/llava-v1.5-7b](https://huggingface.co/liuhaotian/llava-v1.5-7b). Load the model with revision="8ab8ff" to use AutoGPTQ format.
+
+## How To Use
+
+### Requirements
+
+1. Clone this repository and navigate to LLaVA folder
+```shell
+git clone https://github.com/haotian-liu/LLaVA.git
+cd LLaVA
+```
+
+2. Refine LLaVA repo
+```
+vi llava/model/language_model/llava_llama.py
+# add 'cache_position = None,' to line 71.
+```
+3. Install Package
+```
+pip install --upgrade pip # enable PEP 660 support
+pip install -e .
+```
+
+### INT4 Inference
+```python
+from auto_round import AutoRoundConfig ## must import for auto-round format
+import requests
+import torch
+from PIL import Image
+from llava.model.builder import load_pretrained_model
+from llava.train.train import preprocess, preprocess_multimodal, DataCollatorForSupervisedDataset
+class DataArgs:
+ is_multimodal = True
+ mm_use_im_start_end = False
+
+quantized_model_path="Intel/llava-v1.5-7b-inc-private"
+
+tokenizer, model, image_processor, _ = load_pretrained_model(
+ quantized_model_path,
+ model_base=None,
+ model_name=quantized_model_path,
+ torch_dtype="auto",
+ device_map="auto",
+ ##revision="8ab8ff" ##AutoGPTQ format
+)
+image_url = "http://images.cocodataset.org/train2017/000000116003.jpg"
+messages = [{"from": "human", "value": "What is the tennis player doing in the image?\n<image>"}]
+
+# Preparation for inference
+image = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
+image_input = image_processor.preprocess(image, return_tensors='pt')['pixel_values'][0].to(model.device)
+input_data = preprocess_multimodal([messages], DataArgs())
+inputs = preprocess(input_data, tokenizer, has_image=(image_input is not None))
+
+output = model.generate(inputs['input_ids'].to(model.device), images=image_input.unsqueeze(0).half(), max_new_tokens=50)
+print(tokenizer.batch_decode(output))
+
+##INT4: The tennis player is celebrating a victory, raising his arms in the air, and holding his tennis racket.
+
+##BF16: The tennis player is celebrating a victory, raising his arms in the air, and holding a tennis racket.
+
+image_url = "http://images.cocodataset.org/train2017/000000411975.jpg"
+messages = [{"from": "human", "value": "How many people are on the baseball field in the picture?\n<image>"}]
+
+##INT4: There are three people on the baseball field in the picture.
+
+##BF16: There are three people on the baseball field in the picture.
+
+
+image_url = "http://images.cocodataset.org/train2017/000000093025.jpg"
+messages = [{"from": "human", "value": "How many people and animals are there in the image?\n<image>"}]
+
+##INT4: There are two people and one animal in the image.
+
+##BF16: There are two people and one animal in the image.
+
+```
+
+## Evaluation the model
+pip3 install lmms_eval
+```bash
+auto_round --lmms --model llava-v1.5-7b-inc-private --tasks pope,textvqa_val,scienceqa,mmbench_en --output_dir "./eval_result" --device cuda:0
+```
+|Metric |16bits|Pile Calib INT4 | Llava Calib INT4 |
+|:-------------------|:------|:------|:--------------|
+|avg |65.40 |65.91 | 65.79 |
+|MMBench_DEV_EN_V11 |64.09 |64.43 |64.43 |
+|ScienceQA_VAL |64.87 |67.20 |66.80 |
+|TextVQA_VAL |45.56 |45.71 |45.81 |
+|POPE |87.09 |86.31 |86.12 |
+
+### Generate the model
+Here is the sample command to reproduce the model.
+```bash
+pip install auto_round
+auto-round-mllm
+--model liuhaotian/llava-v1.5-7b \
+--device 0 \
+--group_size 128 \
+--bits 4 \
+--iters 1000 \
+--nsample 512 \
+--seqlen 2048 \
+--format 'auto_gptq,auto_round' \
+--output_dir "./tmp_autoround"
+```
+
+## Ethical Considerations and Limitations
+
+The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
+
+Therefore, before deploying any applications of the model, developers should perform safety testing.
+
+## Caveats and Recommendations
+
+Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
+
+Here are a couple of useful links to learn more about Intel's AI software:
+
+- Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
+
+## Disclaimer
+
+The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
+
+## Cite
+
+@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
+
+[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)