File size: 5,715 Bytes
b2506ed
 
 
 
 
 
 
 
 
 
 
 
 
783219b
8ca7b1b
514ab7c
 
783219b
 
 
 
21b90db
783219b
b2506ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158d8b8
b2506ed
 
 
 
158d8b8
b2506ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
datasets:
- NeelNanda/pile-10k
base_model:
- mistralai/Mistral-Small-3.1-24B-Instruct-2503
---
## Model Details

This model is an int4 model with group_size 128 and symmetric quantization of [mistralai/Mistral-Small-3.1-24B-Instruct-2503](https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503) generated by [intel/auto-round](https://github.com/intel/auto-round) algorithm.

Please follow the license of the original model.

## INT4 Inference

transformers>=4.52


**Requirements**
~~~bash
pip install git+https://github.com/huggingface/transformers.git
~~~
**Note:** There is no official HuggingFace sample code of the original model. The following code may have issues.

```python
from transformers import AutoProcessor, Mistral3ForConditionalGeneration, AutoTokenizer
from huggingface_hub import hf_hub_download
import torch
from datetime import datetime, timedelta

model_id = "OPEA/Mistral-Small-3.1-24B-Instruct-2503-int4-AutoRound-gptq-sym"

def load_system_prompt(repo_id: str, filename: str) -> str:
    file_path = hf_hub_download(repo_id=repo_id, filename=filename)
    with open(file_path, "r") as file:
        system_prompt = file.read()
    today = datetime.today().strftime("%Y-%m-%d")
    yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
    model_name = repo_id.split("/")[-1]
    return system_prompt.format(name=model_name, today=today, yesterday=yesterday)


SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")

model = Mistral3ForConditionalGeneration.from_pretrained(
    model_id, torch_dtype=torch.float16, device_map="auto"
).eval()

processor = AutoProcessor.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/europe.png"

prompt = "Which of the depicted countries has the best food? Which the second and third and fourth? Name the country, its color on the map and one its city that is visible on the map, but is not the capital. Make absolutely sure to only name a city that can be seen on the map."

messages = [
    {"role": "system", "content": SYSTEM_PROMPT},
    {
        "role": "user",
        "content": [
            {
                "type": "text",
                "text": prompt,
            },
            {"type": "image"}
        ],
    },
]
inputs = processor.apply_chat_template(
    messages, add_generation_prompt=True, tokenize=False,
    return_dict=True
)
inputs =processor(images=url,
    text=inputs,
    add_special_tokens=False,
    return_tensors="pt").to(model.device).to(torch.float16)

input_len = inputs["input_ids"].shape[-1]

with torch.inference_mode():
    generation = model.generate(**inputs, max_new_tokens=512, do_sample=True)
    generation = generation[0][input_len:]

decoded = processor.decode(generation, skip_special_tokens=True)
print(decoded)
## Output:
## The map shows many countries, but here are some general notes for countries often recognized for their culinary traditions:
## 
## 1. **Italy (Green)**: Known for its rich and diverse cuisine, including pasta, pizza, and gelato and many more.
##    - City: Torino
##
## 2. **France (Yellow-brown)**: Renowned for its refined techniques, high-quality ingredients, and iconic dishes.
##    - City: Marseille
##
## 3. **Spain (Light Brown-Yellow)**: Famous for tapas, paella, and jamón ibérico and many more.
##    - City: Barcelona
## 
## 4. **Germany (Orange)**: Celebrated for its hearty dishes like sausages, pretzels, and beer. Also has a high quality of bread.
##    - City: Munich
## 
## 5. **Greece (Red-Brown)**: Known for Mediterranean flavors in dishes like moussaka, souvlaki, and tzatziki and many more.
##    - City: Thessaloniki
## 
## 6. **Turkey (Yellow-Green)**: Offers a blend of European and Middle Eastern flavors, known for kebabs, baklava and many more.
##    - City: Antalya
## 
## There are many more countries in Europe with great food. The culinary preferences can vary widely depending on personal tastes and cultural backgrounds.
```

## Generate the model
Here is the sample command to reproduce the model.
```bash
pip install git+https://github.com/intel/auto-round.git@main
auto-round-mllm \
--model mistralai/Mistral-Small-3.1-24B-Instruct-2503 \
--device 0 \
--bits 4 \
--format 'auto_awq,auto_gptq' \
--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)