Views
No views yet
1
2model_name = "Kohsaku/gemma-2-9b-finetune-2"
3
4max_seq_length = 1024
5
6dtype = None
7load_in_4bit = True
8
9model, tokenizer = FastLanguageModel.from_pretrained(
10 model_name = model_name,
11 max_seq_length = max_seq_length,
12 dtype = dtype,
13 load_in_4bit = load_in_4bit,
14 token = HF_TOKEN,
15)
16FastLanguageModel.for_inference(model)
17
18text = "自然言語処理とは何か"
19tokenized_input = tokenizer.encode(text, add_special_tokens=True , return_tensors="pt").to(model.device)
20
21with torch.no_grad():
22 output = model.generate(
23 tokenized_input,
24 max_new_tokens = 1024,
25 use_cache = True,
26 do_sample=False,
27 repetition_penalty=1.2
28 )[0]
29print(tokenizer.decode(output))