INC4AI commited on
Commit
d735da8
·
verified ·
1 Parent(s): 1a740f1

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +128 -0
README.md CHANGED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - meituan-longcat/LongCat-Next
4
+ pipeline_tag: any-to-any
5
+ ---
6
+
7
+ ## Model Details
8
+
9
+ This model is an int4 model with group_size 128 and symmetric quantization of [meituan-longcat/LongCat-Next](https://huggingface.co/meituan-longcat/LongCat-Next) generated by [intel/auto-round](https://github.com/intel/auto-round). Please follow the license of the original model.
10
+
11
+ ## How to Use
12
+
13
+ ### HF Usage
14
+
15
+ - Remember to modify WEIGHT_PATH_TO_LONGCAT_NEXT in ./config.json, because decoders use lazy loading.
16
+ - assets/cosy24k_ocoder/image_decoder/nmm_infer can be obtained from https://huggingface.co/meituan-longcat/LongCat-Next/tree/main
17
+
18
+ ```python
19
+ import torch
20
+ from transformers import AutoModelForCausalLM, AutoTokenizer, AutoProcessor
21
+
22
+ # Load model
23
+ model_name = "Intel/LongCat-Next-int4-AutoRound"
24
+ model = AutoModelForCausalLM.from_pretrained(
25
+ model_name,
26
+ torch_dtype=torch.bfloat16,
27
+ device_map="auto",
28
+ trust_remote_code=True,
29
+ )
30
+ model.eval()
31
+
32
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, fix_mistral_regex=True)
33
+ model.text_tokenizer = tokenizer # Dynamic binding
34
+ processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
35
+
36
+ # Set messages
37
+ messages = [
38
+ {"role": "system", "content": "You are a helpful assistant."},
39
+ {"role": "user", "content": "What book is this?<longcat_img_start>./assets/book.png<longcat_img_end>"}
40
+ ]
41
+
42
+ # Apply chat-template
43
+ text_input = tokenizer.apply_chat_template(
44
+ messages,
45
+ tokenize=False,
46
+ add_generation_prompt=True,
47
+ )
48
+ print(f"{text_input=}")
49
+
50
+ # Preprocessing
51
+ text_inputs, visual_inputs, audio_inputs = processor(text=text_input, return_tensors="pt")
52
+ text_inputs = text_inputs.to(model.device)
53
+ if visual_inputs is not None:
54
+ visual_inputs = visual_inputs.to(model.device)
55
+ if audio_inputs is not None:
56
+ audio_inputs = audio_inputs.to(model.device)
57
+
58
+ # AR
59
+ with torch.no_grad():
60
+ outputs = model.generate(
61
+ input_ids=text_inputs["input_ids"],
62
+ visual_inputs=visual_inputs,
63
+ audio_inputs=audio_inputs,
64
+ return_dict_in_generate=True,
65
+ )
66
+
67
+ # Text decoding
68
+ output_input_ids = outputs.sequences
69
+ text_output = tokenizer.decode(output_input_ids[0][len(text_inputs["input_ids"][0]):], skip_special_tokens=True)
70
+ print(f"{text_output=}")
71
+
72
+ # Images decoding
73
+ output_visual_ids = outputs.visual_ids
74
+ if output_visual_ids.size(0) > 0:
75
+ image_path_list = model.model.decode_visual_ids_and_save(
76
+ output_visual_ids,
77
+ save_prefix="./output_image",
78
+ **model.generation_config.visual_generation_config["custom_params"],
79
+ )
80
+ print(f"{image_path_list=}")
81
+
82
+ # Audio decoding
83
+ output_audio_text_ids = outputs.audio_text_ids
84
+ output_audio_ids = outputs.audio_ids
85
+ if output_audio_text_ids.size(-1) > 0:
86
+ audio_text = tokenizer.decode(output_audio_text_ids[0], skip_special_tokens=True)
87
+ print(f"{audio_text=}")
88
+ if output_audio_ids.size(0) > 0:
89
+ audio_path_list = model.model.decode_audio_ids_and_save(
90
+ output_audio_ids,
91
+ save_prefix="./output_audio",
92
+ **model.generation_config.audio_generation_config["custom_params"],
93
+ )
94
+ print(f"{audio_path_list=}")
95
+ ```
96
+
97
+ ## Generate the Model
98
+
99
+ ```bash
100
+ # Need https://github.com/intel/auto-round/pull/1637
101
+ AR_CALIB_FORCE_CUDA=1 auto-round --bits 4 --iters 200 --model_name meituan-longcat/LongCat-Next
102
+ ```
103
+
104
+ ## Ethical Considerations and Limitations
105
+
106
+ 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.
107
+
108
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
109
+
110
+ ## Caveats and Recommendations
111
+
112
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
113
+
114
+ Here are a couple of useful links to learn more about Intel's AI software:
115
+
116
+ - [Intel Neural Compressor](https://github.com/intel/neural-compressor)
117
+
118
+ ## Disclaimer
119
+
120
+ 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.
121
+
122
+ ## Cite
123
+
124
+ ```
125
+ @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} }
126
+ ```
127
+
128
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)