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