hiroshij commited on
Commit
92bd997
·
verified ·
1 Parent(s): 784c809

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +53 -0
README.md CHANGED
@@ -20,3 +20,56 @@ language:
20
  This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
21
 
22
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
21
 
22
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
23
+
24
+ How to finetune llm-jp/llm-jp-3-13b
25
+
26
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
27
+ from unsloth import FastLanguageModel
28
+ import torch
29
+ max_seq_length = 2048 # Original 512
30
+ dtype = None
31
+ load_in_4bit = True
32
+
33
+ model_id = "hiroshij/llm-jp-3-13b-finetune-joga-20241202"
34
+ new_model_id = "llm-jp-3-13b-finetune-joga-20241202-2"
35
+
36
+ model, tokenizer = FastLanguageModel.from_pretrained(
37
+ model_name=model_id,
38
+ dtype=dtype,
39
+ load_in_4bit=load_in_4bit,
40
+ trust_remote_code=True,
41
+ )
42
+
43
+ model = FastLanguageModel.get_peft_model(
44
+ model,
45
+ r = 32,
46
+ target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
47
+ "gate_proj", "up_proj", "down_proj",],
48
+ lora_alpha = 32,
49
+ lora_dropout = 0.05,
50
+ bias = "none",
51
+ use_gradient_checkpointing = "unsloth",
52
+ random_state = 3407,
53
+ use_rslora = False,
54
+ loftq_config = None,
55
+ max_seq_length = max_seq_length,
56
+ )
57
+
58
+ -----------------------------------------------------------------------
59
+
60
+ from tqdm import tqdm
61
+
62
+ FastLanguageModel.for_inference(model)
63
+
64
+ results = []
65
+ for dt in tqdm(datasets):
66
+ input = dt["input"]
67
+
68
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
69
+
70
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
71
+
72
+ outputs = model.generate(**inputs, max_new_tokens = 1024, use_cache = True, do_sample=False, repetition_penalty=1.2) #Original 512
73
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
74
+
75
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})