Views
No views yet
mkdir ./templates && mkdir ./utils && wget -P ./templates https://raw.githubusercontent.com/jongmin-oh/korean-LLM-quantize/main/templates/kullm.json && wget -P ./utils https://raw.githubusercontent.com/jongmin-oh/korean-LLM-quantize/main/utils/prompter.pypip install torch==2.0.1 auto-gptq==0.4.21import torch
2from transformers import pipeline
3from auto_gptq import AutoGPTQForCausalLM
4
5from utils.prompter import Prompter
6
7MODEL = "j5ng/kullm-5.8b-GPTQ-8bit"
8model = AutoGPTQForCausalLM.from_quantized(MODEL, device="cuda:0", use_triton=False)
9
10pipe = pipeline('text-generation', model=model,tokenizer=MODEL)
11
12prompter = Prompter("kullm")
13
14def infer(instruction="", input_text=""):
15 prompt = prompter.generate_prompt(instruction, input_text)
16 output = pipe(
17 prompt, max_length=512,
18 temperature=0.2,
19 repetition_penalty=3.0,
20 num_beams=5,
21 eos_token_id=2
22 )
23 s = output[0]["generated_text"]
24 result = prompter.get_response(s)
25
26 return result
27
28instruction = """
29손흥민(한국 한자: 孫興慜, 1992년 7월 8일 ~ )은 대한민국의 축구 선수로 현재 잉글랜드 프리미어리그 토트넘 홋스퍼에서 윙어로 활약하고 있다.
30또한 대한민국 축구 국가대표팀의 주장이자 2018년 아시안 게임 금메달리스트이며 영국에서는 애칭인 "쏘니"(Sonny)로 불린다.
31아시아 선수로서는 역대 최초로 프리미어리그 공식 베스트 일레븐과 아시아 선수 최초의 프리미어리그 득점왕은 물론 FIFA 푸스카스상까지 휩쓸었고 2022년에는 축구 선수로는 최초로 체육훈장 청룡장 수훈자가 되었다.
32손흥민은 현재 리그 100호를 넣어서 화제가 되고 있다.
33"""
34result = infer(instruction=instruction, input_text="손흥민의 애칭은 뭐야?")
35print(result) # 손흥민의 애칭은 Sonny입니다.