--- inference: false license: llama2 language: - ja - en --- # Model Card for Model ID Original model [elyza/ELYZA-japanese-Llama-2-7b-instruct](https://huggingface.co/elyza/ELYZA-japanese-Llama-2-7b-instruct) which is based on Meta's "Llama 2" and has undergone additional pre-training in Japanese instruction. This model is a [AWQ](https://arxiv.org/abs/2306.00978) quantized(miniaturized to 3.89GB) version of the original model(13.48GB). ## Model Details Currently, this model is confirmed to work with **Colab A100** or RTX 3060 on local PC. There is a problem with Free Colab(T4) and Colab Pro(V100) that prevents text from being output even though there is sufficient GPU memory. However, I still don't know the cause. Quantization reduces the amount of memory required and improves execution speed, but unfortunately performance deteriorates. In particular, the original model is tuned for the purpose of strengthening the ability to follow Japanese instructions, not as a benchmark. Although the ability to follow instructions cannot be measured using existing automated benchmarks, we have confirmed that quantized model significantly deteriorates the ability to follow instructions. But this model has better ability to follow instructions than the previous [GPTQ version](https://huggingface.co/dahara1/ELYZA-japanese-Llama-2-7b-fast-instruct-GPTQ). ## Sample Script ### Colab [AWQ version Colab sample A100 only](https://github.com/webbigdata-jp/python_sample/blob/main/ELYZA_japanese_Llama_2_7b_instruct_AWQ_sample.ipynb) ### local PC install Library. ``` pip install autoawq ``` script example. ``` from awq import AutoAWQForCausalLM from transformers import AutoTokenizer quant_path = 'dahara1/ELYZA-japanese-Llama-2-7b-instruct-AWQ' quant_config = { "zero_point": True, "q_group_size": 128, "w_bit": 4 } quantized_model_dir = "ELYZA-japanese-Llama-2-7b-instruct-AWQ" quant_file = "awq_model_w4_g128.pt" model = AutoAWQForCausalLM.from_quantized(quantized_model_dir, quant_file) tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir, trust_remote_code=True) B_INST, E_INST = "[INST]", "[/INST]" B_SYS, E_SYS = "<>\n", "\n<>\n\n" DEFAULT_SYSTEM_PROMPT = "あなたは誠実で優秀な日本人のアシスタントです。" elyza_tasks_100_over_4score_prompt = [ """リラックマが船橋市に行ってふなっしーと強敵(トモ)になり、最終的にはトー横に住みつくというプロットの短編小説を劇画風文体で書いてみてください。""", ] for i in range(len(elyza_tasks_100_over_4score_prompt)): prompt = "{bos_token}{b_inst} {system}{prompt} {e_inst} ".format( bos_token=tokenizer.bos_token, b_inst=B_INST, system=f"{B_SYS}{DEFAULT_SYSTEM_PROMPT}{E_SYS}", prompt=elyza_tasks_100_over_4score_prompt[i], e_inst=E_INST, ) tokens = tokenizer(prompt, return_tensors="pt").to("cuda:0").input_ids output = model.generate( input_ids=tokens, max_new_tokens=256, pad_token_id=tokenizer.pad_token_id, eos_token_id=tokenizer.eos_token_id) print(tokenizer.decode(output[0])) ``` Output ``` [INST] <> あなたは誠実で優秀な日本人のアシスタントです。 <> リラックマが船橋市に行ってふなっしーと強敵(トモ)になり、最終的にはトー横に住みつくというプロットの短編小説を劇画風文体で書いてみてください。 [/INST] リラックマが船橋市にやってきた。 彼はふなっしーと強敵(トモ)になるために、船橋競艇場へと向かった。 ふなっしーはリラックマの登場に驚いたが、すぐに強気のレースを展開した。 リラックマはその走りに感化され、自身も熱くなっていく。 ふなっしーは最終周回で逆転を狙うが、リラックマはそれをかわして優勝を飾った。 ふなっしーは敗北を喫しながらも、リラックマの強さを認める。 ふなっしーはリラックマに船橋を後にするよ ``` ## Citations This model is based on the work of the following people: ```tex @misc{elyzallama2023, title={ELYZA-japanese-Llama-2-7b}, url={https://huggingface.co/elyza/ELYZA-japanese-Llama-2-7b}, author={Akira Sasaki and Masato Hirakawa and Shintaro Horie and Tomoaki Nakamura}, year={2023}, } ``` ```tex @misc{touvron2023llama, title={Llama 2: Open Foundation and Fine-Tuned Chat Models}, author={Hugo Touvron and Louis Martin and Kevin Stone and Peter Albert and Amjad Almahairi and Yasmine Babaei and Nikolay Bashlykov and Soumya Batra and Prajjwal Bhargava and Shruti Bhosale and Dan Bikel and Lukas Blecher and Cristian Canton Ferrer and Moya Chen and Guillem Cucurull and David Esiobu and Jude Fernandes and Jeremy Fu and Wenyin Fu and Brian Fuller and Cynthia Gao and Vedanuj Goswami and Naman Goyal and Anthony Hartshorn and Saghar Hosseini and Rui Hou and Hakan Inan and Marcin Kardas and Viktor Kerkez and Madian Khabsa and Isabel Kloumann and Artem Korenev and Punit Singh Koura and Marie-Anne Lachaux and Thibaut Lavril and Jenya Lee and Diana Liskovich and Yinghai Lu and Yuning Mao and Xavier Martinet and Todor Mihaylov and Pushkar Mishra and Igor Molybog and Yixin Nie and Andrew Poulton and Jeremy Reizenstein and Rashi Rungta and Kalyan Saladi and Alan Schelten and Ruan Silva and Eric Michael Smith and Ranjan Subramanian and Xiaoqing Ellen Tan and Binh Tang and Ross Taylor and Adina Williams and Jian Xiang Kuan and Puxin Xu and Zheng Yan and Iliyan Zarov and Yuchen Zhang and Angela Fan and Melanie Kambadur and Sharan Narang and Aurelien Rodriguez and Robert Stojnic and Sergey Edunov and Thomas Scialom}, year={2023}, eprint={2307.09288}, archivePrefix={arXiv}, primaryClass={cs.CL} } ``` ```tex @article{lin2023awq, title={AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration}, author={Lin, Ji and Tang, Jiaming and Tang, Haotian and Yang, Shang and Dang, Xingyu and Han, Song}, journal={arXiv}, year={2023} } ``` ## about this work - **This Quantization work was done by :** [webbigdata](https://webbigdata.jp/) ## See also [AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration](https://arxiv.org/abs/2306.00978) [mit-han-lab/llm-awq](https://github.com/mit-han-lab/llm-awq) [casper-hansen/AutoAWQ](https://github.com/casper-hansen/AutoAWQ)