| --- |
| base_model: |
| - meituan-longcat/LongCat-Next |
| pipeline_tag: any-to-any |
| --- |
| |
| ## Model Details |
|
|
| 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. |
| |
| ## How to Use |
| |
| ### HF Usage |
| |
| - Remember to modify WEIGHT_PATH_TO_LONGCAT_NEXT in ./config.json, because decoders use lazy loading. |
| - assets/cosy24k_ocoder/image_decoder/nmm_infer can be obtained from https://huggingface.co/meituan-longcat/LongCat-Next/tree/main |
|
|
| ```python |
| import torch |
| from transformers import AutoModelForCausalLM, AutoTokenizer, AutoProcessor |
| |
| # Load model |
| model_name = "Intel/LongCat-Next-int4-AutoRound" |
| model = AutoModelForCausalLM.from_pretrained( |
| model_name, |
| torch_dtype=torch.bfloat16, |
| device_map="auto", |
| trust_remote_code=True, |
| ) |
| model.eval() |
| |
| tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, fix_mistral_regex=True) |
| model.text_tokenizer = tokenizer # Dynamic binding |
| processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True) |
| |
| # Set messages |
| messages = [ |
| {"role": "system", "content": "You are a helpful assistant."}, |
| {"role": "user", "content": "What book is this?<longcat_img_start>./assets/book.png<longcat_img_end>"} |
| ] |
| |
| # Apply chat-template |
| text_input = tokenizer.apply_chat_template( |
| messages, |
| tokenize=False, |
| add_generation_prompt=True, |
| ) |
| print(f"{text_input=}") |
| |
| # Preprocessing |
| text_inputs, visual_inputs, audio_inputs = processor(text=text_input, return_tensors="pt") |
| text_inputs = text_inputs.to(model.device) |
| if visual_inputs is not None: |
| visual_inputs = visual_inputs.to(model.device) |
| if audio_inputs is not None: |
| audio_inputs = audio_inputs.to(model.device) |
| |
| # AR |
| with torch.no_grad(): |
| outputs = model.generate( |
| input_ids=text_inputs["input_ids"], |
| visual_inputs=visual_inputs, |
| audio_inputs=audio_inputs, |
| return_dict_in_generate=True, |
| ) |
| |
| # Text decoding |
| output_input_ids = outputs.sequences |
| text_output = tokenizer.decode(output_input_ids[0][len(text_inputs["input_ids"][0]):], skip_special_tokens=True) |
| print(f"{text_output=}") |
| |
| # Images decoding |
| output_visual_ids = outputs.visual_ids |
| if output_visual_ids.size(0) > 0: |
| image_path_list = model.model.decode_visual_ids_and_save( |
| output_visual_ids, |
| save_prefix="./output_image", |
| **model.generation_config.visual_generation_config["custom_params"], |
| ) |
| print(f"{image_path_list=}") |
| |
| # Audio decoding |
| output_audio_text_ids = outputs.audio_text_ids |
| output_audio_ids = outputs.audio_ids |
| if output_audio_text_ids.size(-1) > 0: |
| audio_text = tokenizer.decode(output_audio_text_ids[0], skip_special_tokens=True) |
| print(f"{audio_text=}") |
| if output_audio_ids.size(0) > 0: |
| audio_path_list = model.model.decode_audio_ids_and_save( |
| output_audio_ids, |
| save_prefix="./output_audio", |
| **model.generation_config.audio_generation_config["custom_params"], |
| ) |
| print(f"{audio_path_list=}") |
| ``` |
|
|
| ## Generate the Model |
|
|
| ```bash |
| # Need https://github.com/intel/auto-round/pull/1637 |
| AR_CALIB_FORCE_CUDA=1 auto-round --bits 4 --iters 200 --model_name meituan-longcat/LongCat-Next |
| ``` |
|
|
| ## 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](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) |
|
|