1kbooks commited on
Commit
b4022cd
·
verified ·
1 Parent(s): 1ba11a0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -1
README.md CHANGED
@@ -45,7 +45,42 @@ This is the model card of a 🤗 transformers model that has been pushed on the
45
 
46
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
47
 
48
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  ### Downstream Use [optional]
51
 
 
45
 
46
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
47
 
48
+ ```python
49
+ model_id = "1kbooks/llm-jp-3-13b-finetuned-ver2"
50
+ bnb_config = BitsAndBytesConfig(
51
+ load_in_4bit=True,
52
+ bnb_4bit_quant_type="nf4",
53
+ bnb_4bit_compute_dtype=torch.bfloat16,
54
+ )
55
+ model = AutoModelForCausalLM.from_pretrained(
56
+ model_id,
57
+ quantization_config=bnb_config,
58
+ device_map="auto"
59
+ )
60
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
61
+
62
+ input = "ここに指示を入力"
63
+ with torch.no_grad():
64
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
65
+
66
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
67
+ tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
68
+ attention_mask = torch.ones_like(tokenized_input)
69
+
70
+ outputs = model.generate(
71
+ tokenized_input,
72
+ attention_mask=attention_mask,
73
+ max_new_tokens = 512,
74
+ use_cache = True,
75
+ do_sample=False,
76
+ repetition_penalty=1.2,
77
+ pad_token_id=tokenizer.eos_token_id
78
+ )
79
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
80
+
81
+ print(prediction)
82
+
83
+ ```
84
 
85
  ### Downstream Use [optional]
86