
ããããã²ãŒã ãã§ã³ãžã£ãŒã!ãæŸå°Ÿç ã®Tanuki-8BãšTanuki-8x8Bã詊ã
æ±å€§æŸå°Ÿç ãã€ãã«çæãšãèšããã¹ããªãŒãã³ãªæ¥æ¬èªLLMãçºè¡šããããã®åãTanuki
ãªãã¿ãããªã®ã?
ãã®è¬ã¯è¬ã®ãŸãŸã ãããšã«ããæ¥æ¬èªæ§èœãGemini1.5Proã«æ¬¡ããå°ãåã®GPT-4ãããé«ãäžã«åçšå©çšå¯èœãšãã倪ã£è
¹ä»æ§ãªã®ã§äœ¿ããªãæã¯ãªãããããããããããã°ãã誰ãGPTã«èª²éããªããŠæžãããããªæªæ¥ãæ¥ãã®ãããããªãã
ããããTanukiã¯ç¹æ®ãªäœããããŠããããMLXã«ç°¡åã«ã³ã³ããŒãã§ããvllmã§åãããšããã¡ãã£ãšéæ¹é ããvllmãå¿ èŠã«ãªããšããã
æè¿ããŒã«ã«ã¥ããŠãåŸèŒ©ãšããŠã¯ã§ããã°MLXã§åããããã®ã ãMLXããŸã Tanukiã«å¯Ÿå¿ããŠãªã(ããããããäœãããã°Tanuki察å¿ã«ã§ããã®ãããããããªã)ã®ã§ããšãããããéæšå¥šããšãããŠã¯ãããã®ã®ãMacã§ãã®ãªã®ãªåããããªGGUFçãåãããŠã¿ãã
from llama_cpp import Llama
filename = "Tanuki-8B-dpo-v1.0-IQ4_NL.gguf"
model_name = "team-hatakeyama-phase2/Tanuki-8B-dpo-v1.0-GGUF"
llm = Llama.from_pretrained(repo_id=model_name,
filename=filename, n_gpu_layers=99)ããã§èªã¿èŸŒãããã¡ãªã¿ã«8x8Bã«ããããšããããã¢ãã«ã ãã§34GBãããã«ãªã£ãŠã軜ãåŸèŒ©ã®MacBookPro M2ã®ã¡ã€ã³ã¡ã¢ãªå®¹éãè¶ ããŠããŸãã®ã§è«Šããã
ãµã³ãã«ã³ãŒããã®ãŸãŸãå®è¡ãããšãã°ããæéãçµã£ãŠãããªæååã衚瀺ãããã
>>> prompt = """<s>以äžã¯ãã¿ã¹ã¯ã説æããæç€ºã§ããèŠæ±ãé©åã«æºããå¿çãæžããªããã
...
... ### æç€º:
... AIã«ãã£ãŠç§ãã¡ã®æ®ããã¯ã©ã®ããã«å€ãããŸããïŒ
...
... ### å¿ç:
... """
>>>
>>> output = llm.create_completion(prompt, max_tokens=1024, temperature=0.5, echo=True)
llama_print_timings: load time = 4946.28 ms
llama_print_timings: sample time = 23.61 ms / 453 runs ( 0.05 ms per token, 19185.16 tokens per second)
llama_print_timings: prompt eval time = 4946.12 ms / 59 tokens ( 83.83 ms per token, 11.93 tokens per second)
llama_print_timings: eval time = 61475.78 ms / 452 runs ( 136.01 ms per token, 7.35 tokens per second)
llama_print_timings: total time = 66943.07 ms / 511 tokens
>>>
>>> print(output['choices'][0]['text'])
<s>以äžã¯ãã¿ã¹ã¯ã説æããæç€ºã§ããèŠæ±ãé©åã«æºããå¿çãæžããªããã
### æç€º:
AIã«ãã£ãŠç§ãã¡ã®æ®ããã¯ã©ã®ããã«å€ãããŸããïŒ
### å¿ç:
AIã®é²åã¯ç§ãã¡ã®ç掻ã«å€å²ã«ããã圱é¿ãããããããã®å€åã¯å€å²ã«ããããŸãããŸããæ¥åžžçæŽ»ã«ãããŠã¯ãã¹ããŒãããŒã æè¡ãé²åããå®¶åºå
ã®å®¶é»ãã»ãã¥ãªãã£ã·ã¹ãã ãAIã«ãã£ãŠèªååãããŸããããã«ããããšãã«ã®ãŒå¹çã®åäžãã»ãã¥ãªãã£ã®åŒ·åãå®çŸããçæŽ»ã®è³ªãåäžããŸããäŸãã°ãé³å£°èªèãèªåå¶åŸ¡ã·ã¹ãã ã«ãããç
§æã枩床調æŽãããã«ã¯é²ç¯ã«ã¡ã©ã®ç£èŠãç°¡åã«ãªããŸãã
次ã«ãä»äºç°å¢ã«ãããŠã倧ããªå€åãæåŸ
ãããŸããAIã¯ã«ãŒãã³äœæ¥ã®èªååãããŒã¿åæã®å¹çåãéããŠãåŸæ¥å¡ãããåµé çã§æŠç¥çãªæ¥åã«éäžã§ããããæ¯æŽããŸããããã«ãããçç£æ§ãåäžããæ°ããããžãã¹ã¢ãã«ããµãŒãã¹ã®åµåºãå éããã§ãããããŸãããªã¢ãŒãã¯ãŒã¯ãããªãŒã©ã³ã¹ã®åãæ¹ãããã«æ®åããå°ççå¶çŽãè¶
ããåãæ¹ãäžè¬çã«ãªããããããŸããã
æè²åéã§ãAIã¯å€§ããªå€é©ããããããŸããåå¥åŠç¿æ¯æŽã·ã¹ãã ãAIãã¥ãŒã¿ãŒããåçåŸã®åŠç¿é²åºŠãç解床ã«å¿ããã«ã¹ã¿ãã€ãºãããæè²ãæäŸããããšã§ãåŠç¿å¹çãé£èºçã«åäžããŸããããã«ãããããå€ãã®äººã
ã質ã®é«ãæè²ã«ã¢ã¯ã»ã¹ã§ããããã«ãªããŸãã
å»çåéã§ãAIã¯éèŠãªåœ¹å²ãæãããŸãã蚺æã®ç²ŸåºŠåäžãæ©æçºèŠãããŒãœãã©ã€ãºãã¡ãã£ã¹ã³ïŒåå¥åå»çïŒã®å®çŸã«ãããç
æ°ã®äºé²ãæ²»çããã广çãã€è¿
éã«è¡ãããããã«ãªããŸãããŸããé éå»çã®æ®åã«ãããå°æ¹ãéçå°ã§ãé«åºŠãªå»çãµãŒãã¹ãåããããããã«ãªããŸãã
ããã«ã亀éã亀é管çã«ãããŠãAIã¯é©æ°ããããããŸããèªåé転è»ãã¹ããŒãã·ãã£æè¡ã«ãããäº€éæžæ»ã®ç·©åãäºæ
ã®æžå°ãæåŸ
ãããç§»åãããå®å
šã§å¹ççã«ãªããŸããå
Œ
±äº€éæ©é¢ãAIã«ãã£ãŠæé©åãããå©çšè
ã®å©äŸ¿æ§ãåäžããŸãã
ãšã³ã¿ãŒãã€ã³ã¡ã³ãã嚯楜ã®åéã§ãã
>>>
>>>
éæšå¥šã§ã¯ããããããçµæ§ãããã
ã¡ãã£ãšäœ¿ããããããã«ãããªé¢æ°ãäœã£ãŠã¿ã
def q(prompt,max_tokens=4096):
prompt = f"""<s>以äžã¯ãã¿ã¹ã¯ã説æããæç€ºã§ããèŠæ±ãé©åã«æºããå¿çãæžããªããã
### æç€º:
{prompt}
### å¿ç:
"""
output = llm.create_completion(prompt, max_tokens=max_tokens, temperature=0.5, echo=True)
return output['choices'][0]['text']
ããã§çµæ§ãªãã§ãèãããšãã§ããã
æ¥æ¬èªç¿»èš³ããããŠã¿ã
>>> q("""以äžã®è±æãæ¥æ¬èªã«èš³ããªãã
...
... The term "washoku" embodies the essence of Japanese food, which is not just about the ingredients and recipes but also about the philosophy and etiquette surrounding it. It reflects a way of life that emphasizes balance, harmony, and respect for nature, which is evident in the meticulous preparation, presentation, and consumption of food. The concept of washoku has been recognized by UNESCO as an intangible cultural heritage, underscoring its global significance and the need to preserve and promote it.
...
... Understanding the importance of Japanese culinary culture requires delving into its historical roots. The development of Japanese cuisine is a testament to the country's geographical diversity and its people's ingenuity in harnessing natural resources. From the ancient times of the Jomon and Yayoi periods, where foraging and early agricultural practices laid the foundation, to the sophisticated tea ceremonies of the Heian period and the culinary innovations of the Edo period, Japanese food has evolved through centuries of cultural exchange and indigenous creativity.
... """)
Llama.generate: 30 prefix-match hit, remaining 335 prompt tokens to eval
llama_print_timings: load time = 4946.28 ms
llama_print_timings: sample time = 6.75 ms / 147 runs ( 0.05 ms per token, 21774.55 tokens per second)
llama_print_timings: prompt eval time = 902.43 ms / 335 tokens ( 2.69 ms per token, 371.22 tokens per second)
llama_print_timings: eval time = 23509.85 ms / 146 runs ( 161.03 ms per token, 6.21 tokens per second)
llama_print_timings: total time = 24482.43 ms / 481 tokens
'<s>以äžã¯ãã¿ã¹ã¯ã説æããæç€ºã§ããèŠæ±ãé©åã«æºããå¿çãæžããªããã\n\n\t### æç€º:\n\t以äžã®è±æãæ¥æ¬èªã«èš³ããªãã\n\nThe term "washoku" embodies the essence of Japanese food, which is not just about the ingredients and recipes but also about the philosophy and etiquette surrounding it. It reflects a way of life that emphasizes balance, harmony, and respect for nature, which is evident in the meticulous preparation, presentation, and consumption of food. The concept of washoku has been recognized by UNESCO as an intangible cultural heritage, underscoring its global significance and the need to preserve and promote it.\n\nUnderstanding the importance of Japanese culinary culture requires delving into its historical roots. The development of Japanese cuisine is a testament to the country\'s geographical diversity and its people\'s ingenuity in harnessing natural resources. From the ancient times of the Jomon and Yayoi periods, where foraging and early agricultural practices laid the foundation, to the sophisticated tea ceremonies of the Heian period and the culinary innovations of the Edo period, Japanese food has evolved through centuries of cultural exchange and indigenous creativity.\n\n\n\t### å¿ç:\n\t åé£ãšããçšèªã¯ãæ¥æ¬æçã®æ¬è³ªãäœçŸããŠãããåãªã飿ãã¬ã·ãã«ãšã©ãŸããããã®èåŸã«ããå²åŠãšç€Œåã«ãæ·±ãæ ¹ãããŠããŸããããã¯ãé£äºã«å¯Ÿãããã©ã³ã¹ã調åããããŠèªç¶ãžã®æ¬æãéèŠããçæŽ»ã¹ã¿ã€ã«ãåæ ããŠããŸããæçã®æºåããã¬ãŒã³ããŒã·ã§ã³ããããŠæ¶è²»ã«è³ããŸã§ã现éšã«ãããé
æ
®ãæããããŸãã\n\nåé£ã¯ãŠãã¹ã³ã«ãã£ãŠç¡åœ¢æåéºç£ãšããŠèªãããããã®éèŠæ§ã¯åœéçã«ãèªèãããŠããŸãããã®èªå®ã¯ãåé£ãæã€æåç䟡å€ãšããããä¿è·ãåºããå¿
èŠæ§ã匷調ããŠããŸãã\n'
>>>
åºåãããæ¥æ¬èªèš³
åé£ãšããçšèªã¯ãæ¥æ¬æçã®æ¬è³ªãäœçŸããŠãããåãªã飿ãã¬ã·ãã«ãšã©ãŸããããã®èåŸã«ããå²åŠãšç€Œåã«ãæ·±ãæ ¹ãããŠããŸããããã¯ãé£äºã«å¯Ÿãããã©ã³ã¹ã調åããããŠèªç¶ãžã®æ¬æãéèŠããçæŽ»ã¹ã¿ã€ã«ãåæ ããŠããŸããæçã®æºåããã¬ãŒã³ããŒã·ã§ã³ããããŠæ¶è²»ã«è³ããŸã§ã现éšã«ãããé æ ®ãæããããŸãã\n\nåé£ã¯ãŠãã¹ã³ã«ãã£ãŠç¡åœ¢æåéºç£ãšããŠèªãããããã®éèŠæ§ã¯åœéçã«ãèªèãããŠããŸãããã®èªå®ã¯ãåé£ãæã€æåç䟡å€ãšããããä¿è·ãåºããå¿ èŠæ§ã匷調ããŠããŸãã
åèãŸã§ã«GPT-4ã«ããèš³ãèŒããŠãã
ãåé£ããšããèšèã¯ãåã«é£æãã¬ã·ãã«ãšã©ãŸããããããåãå·»ãå²åŠãäœæ³ããå«ãæ¥æ¬æçã®æ¬è³ªã衚ããŠããŸããããã¯ãé£æã®æºåãçãä»ãããããŠé£ã¹æ¹ã«è³ããŸã§ãèªç¶ãžã®æ¬æã調åããããŠãã©ã³ã¹ãéãããçãæ¹ãåæ ããŠããŸãããã®åé£ã®æŠå¿µã¯ãŠãã¹ã³ã«ãã£ãŠç¡åœ¢æåéºç£ãšããŠèªããããŠããããã®äžççãªéèŠæ§ãšä¿åã»ä¿é²ã®å¿ èŠæ§ã匷調ãããŠããŸãã
æ¥æ¬ã®é£æåã®éèŠæ§ãçè§£ããããã«ã¯ããã®æŽå²çãªæ ¹æºãæ¢ãå¿ èŠããããŸããæ¥æ¬æçã®çºå±ã¯ãåœã®å°çç倿§æ§ãšãèªç¶è³æºã掻çšããåœæ°ã®åµæå·¥å€«ã蚌æããŠããŸããçžææä»£ã匥çæä»£ã®ç©çæ¡éãåæã®èŸ²æ¥ã®å®è·µãåºç€ãç¯ããå¹³å®æä»£ã®æŽç·Žãããè¶éãæ±æžæä»£ã®æç驿°ã«è³ããŸã§ãæ¥æ¬ã®é£æåã¯äœäžçŽã«ããããæå亀æµãšç¬èªã®åµé æ§ã«ãã£ãŠé²åããŠããŸããã
åæ
The term "washoku" embodies the essence of Japanese food, which is not just about the ingredients and recipes but also about the philosophy and etiquette surrounding it. It reflects a way of life that emphasizes balance, harmony, and respect for nature, which is evident in the meticulous preparation, presentation, and consumption of food. The concept of washoku has been recognized by UNESCO as an intangible cultural heritage, underscoring its global significance and the need to preserve and promote it. Understanding the importance of Japanese culinary culture requires delving into its historical roots. The development of Japanese cuisine is a testament to the country's geographical diversity and its people's ingenuity in harnessing natural resources. From the ancient times of the Jomon and Yayoi periods, where foraging and early agricultural practices laid the foundation, to the sophisticated tea ceremonies of the Heian period and the culinary innovations of the Edo period, Japanese food has evolved through centuries of cultural exchange and indigenous creativity.
8Bã¢ãã«ã®GGUFçãšãããã ãã¶èŠããæ¡ä»¶ã§ãããŸããŸãã¡ãããšåãããã ããã¡ããChatGPTã®ã»ããèš³ã¯å¿ å®ã®ããã ãã
8x8Bçã詊ããŠã¿ããããæµç³ã«Macã®ããŒã«ã«ã§åããªãã®ã§GPUãæèŒãããã·ã³ã§è©ŠããŠã¿ãã
ãŸãã¯AWQç
ãã¹ãã©è¬¹è£œA6000x2ã®ãã·ã³ã§ããããã
ãåé£ããšããèšèã¯ãæ¥æ¬ã®é£æåã®æ¬è³ªãäœçŸããŠããŸããããã¯åãªã飿ãã¬ã·ãã«ãšã©ãŸãããå²åŠã瀌åäœæ³ã«ãæ·±ãæ ¹ãããŠããŸããé£äºãéããŠãã©ã³ã¹ã調åããããŠèªç¶ãžã®æ¬æãéèŠãããã®å§¿å¢ã¯ã飿ã®äžå¯§ãªæºåãèŠãç®ã®çŸããããããŠé£ã¹ãéã®ç€Œåã«è¡šããŠããŸãããã®ãåé£ãã®æŠå¿µã¯ãŠãã¹ã³ã®ç¡åœ¢æåéºç£ãšããŠèªããããŠããããã®éèŠæ§ãšäŸ¡å€ãäžççã«èªèãããŠããŸãã
æ¥æ¬ã®é£æåãçè§£ããããã«ã¯ããã®æŽå²çãªèæ¯ãæ¢ãããšãäžå¯æ¬ ã§ããæ¥æ¬ã®é£æåã®çºå±ã¯ãå°ççãªå€æ§æ§ãšäººã ã®åµæå·¥å€«ã«ãã£ãŠæ¯ããããŠããŸãããçžææä»£ã匥çæä»£ã®ç©çæ¡éãåæã®èŸ²æ¥ããå§ãŸãã平宿代ã®è¶äŒãæ±æžæä»£ã®æç驿°ã«è³ããŸã§ãé·ãæŽå²ã®äžã§ããŸããŸãªæå亀æµãšç¬èªã®åµé æ§ãèåããŠããŸããã
äŸãã°ãçžææä»£ã®ç©çæ¡éçæŽ»ã§ã¯ãèªç¶ã®æµã¿ãæå€§éã«æŽ»çšããç¥æµãè²ãŸããŸããããã®åŸãçš²äœãå°å ¥ãããããšã§èŸ²æ¥ãçºå±ãã飿ã®å€æ§åãé²ã¿ãŸããã平宿代ã«ã¯è¶éãèªçããé£äºãã®ãã®ãèžè¡ã®äžéšãšãªããŸãããæ±æžæä»£ã«ã¯ãéœåžã®çºå±ãšãšãã«å€é£æåãæ ãã寿åžã倩ã·ããšãã£ãçŸä»£ã§ã芪ããŸããæçãçãŸããŸããã
ãã®ããã«ããåé£ãã¯åãªãé£äºã®æ ãè¶ ããæ¥æ¬ã®æåãæŽå²ã䟡å€èгãåæ ããç·åçãªæŠå¿µã§ãããã®ããããã®ä¿åãšæ®åã¯ãåã«é£æåã®ä¿è·ã«ãšã©ãŸãããæ¥æ¬æåå šäœã®çè§£ãšç¶æ¿ã«ãã€ãªãããŸãã
ããã ãã§å®ç§ãšèšããããããChatGPTãããäžå¯§ã§ã¯ãªãã ãããã
ã€ãã§ã«HuggingFaceçã詊ããã
ãåé£ããšããèšèã¯ãæ¥æ¬ã®é£æåã®æ¬è³ªãäœçŸããŠããŸããããã¯åã«é£æãã¬ã·ãã«ãšã©ãŸãããå²åŠã瀌åäœæ³ã«ãæ·±ãæ ¹ãããŠããŸãããã©ã³ã¹ã調åããããŠèªç¶ãžã®æ¬æãéãããå§¿å¢ããæçã®æºå
ãã¬ãŒã³ããŒã·ã§ã³ããããŠæ¶è²»ã®å段éã«åæ ãããŠããŸãããã®æŠå¿µã¯ãŠãã¹ã³ã«ãã£ãŠç¡åœ¢æåéºç£ãšããŠèªããããŠããããã®éèŠæ§ãšäžççãªæçŸ©ãèªèãããŠããŸãã
æ¥æ¬ã®é£æåãçè§£ããããã«ã¯ããã®æŽå²çãªèæ¯ãæãäžããå¿ èŠããããŸããæ¥æ¬ã®é£æåã®çºå±ã¯ãå°çç倿§æ§ãšèªç¶è³æºãå·§ã¿ã«å©çšãã人ã ã®åµæå·¥å€«ã®çµæã§ããçžææä»£ã匥çæä»£ã®ç©çæ¡éãå
ã®èŸ²æ¥ããå§ãŸãã平宿代ã®è¶éãæ±æžæä»£ã®æç驿°ã«è³ããŸã§ãæ¥æ¬ã®é£æåã¯äœäžçŽã«ããããæåç亀æµãšç¬èªã®åµé æ§ã«ãã£ãŠåœ¢äœãããŠããŸããã
ãããå®ç§
ããŸã:Tanuku8x8Bã®åããæ¹
vllmãAWQãGPTQã¯ç¹æ®ãªæ¹é çãå ¥ããªããšåãããããããããã©ã®CUDAããŒãžã§ã³ãªã®ãã©ã®PythonããŒãžã§ã³ãªã®ãã©ãã«ãæèšãããŠããããªãã£ã·ã£ã«(https://zenn.dev/matsuolab/articles/a3b42ddbf5d121)ã§ç€ºãããŠããæ å ±ã ãã§ã¯ãªããªããŸããããããã£ãã
åçŸæ§ã確èªã§ããã®ã¯ä»¥äžã®æ¹æ³
$ conda create -n tanuki python=3.10
$ conda activate tanuki
$ export PATH=/usr/local/cuda-12.1/bin:$PATH
$ pip install transformers accelerate bitsandbytes
$ pip install flash_attn
$ python hf.pyhf.pyã®äžèº«ã¯ä»¥äž
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
model_name = "weblab-GENIAC/Tanuki-8B-dpo-v1.0"
# model_name = "team-hatakeyama-phase2/Tanuki-8x8B-dpo-v1.0-AWQ"
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_name)
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
messages = [
{"role": "system", "content": "以äžã¯ãã¿ã¹ã¯ã説æããæç€ºã§ããèŠæ±ãé©åã«æºããå¿çãæžããªããã"},
{"role": "user", "content": '''以äžã®è±æãæ¥æ¬èªã«èš³ããªãã\nThe term "washoku" embodies the essence of Japanese food, which is not just about the ingredients and recipes but also about the philosophy and etiquette surrounding it. It reflects a way of life that emphasizes balance, harmony, and respect for nature, which is evident in the meticulous preparation, presentation, and consumption of food. The concept of washoku has been recognized by UNESCO as an intangible cultural heritage, underscoring its global significance and the need to preserve and promote it.
Understanding the importance of Japanese culinary culture requires delving into its historical roots. The development of Japanese cuisine is a testament to the country's geographical diversity and its people's ingenuity in harnessing natural resources. From the ancient times of the Jomon and Yayoi periods, where foraging and early agricultural practices laid the foundation, to the sophisticated tea ceremonies of the Heian period and the culinary innovations of the Edo period, Japanese food has evolved through centuries of cultural exchange and indigenous creativity.'''}
]
input_ids = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
output_ids = model.generate(input_ids, max_new_tokens=1024, temperature=0.5, streamer=streamer)pipããã±ãŒãžã®ããŒãžã§ã³ãªã©ã¯ä»¥äž
$ pip list|grep tor
torch 2.4.0
$ pip list|grep trans
transformers 4.44.2
$ pip list|grep flash
flash-attn 2.6.3
$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Mon_Apr__3_17:16:06_PDT_2023
Cuda compilation tools, release 12.1, V12.1.105
Build cuda_12.1.r12.1/compiler.32688072_0