Update README.md
Browse files
README.md
CHANGED
@@ -59,4 +59,54 @@ The following hyperparameters were used during training:
|
|
59 |
- Transformers 4.35.2
|
60 |
- Pytorch 2.1.2+cu121
|
61 |
- Datasets 2.14.5
|
62 |
-
- Tokenizers 0.14.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
- Transformers 4.35.2
|
60 |
- Pytorch 2.1.2+cu121
|
61 |
- Datasets 2.14.5
|
62 |
+
- Tokenizers 0.14.1
|
63 |
+
|
64 |
+
## Usage
|
65 |
+
|
66 |
+
```python
|
67 |
+
from transformers import pipeline
|
68 |
+
|
69 |
+
pipe = pipeline("text-generation", model="ayousanz/japanese-mistral-0.3b-base")
|
70 |
+
|
71 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
|
72 |
+
import torch
|
73 |
+
|
74 |
+
MODEL_NAME = "ayousanz/japanese-mistral-0.3b-base"
|
75 |
+
torch.set_float32_matmul_precision('high')
|
76 |
+
|
77 |
+
DEVICE = "cuda"
|
78 |
+
if torch.cuda.is_available():
|
79 |
+
print("cuda")
|
80 |
+
DEVICE = "cuda"
|
81 |
+
else:
|
82 |
+
print("cpu")
|
83 |
+
DEVICE = "cpu"
|
84 |
+
|
85 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME,use_fast=False)
|
86 |
+
model = AutoModelForCausalLM.from_pretrained(
|
87 |
+
MODEL_NAME,
|
88 |
+
trust_remote_code=True,
|
89 |
+
).to(DEVICE)
|
90 |
+
|
91 |
+
prompt = "大規模言語モデルとは、"
|
92 |
+
|
93 |
+
inputs = tokenizer(prompt, add_special_tokens=False,return_tensors="pt").to(model.device)
|
94 |
+
with torch.no_grad():
|
95 |
+
|
96 |
+
outputs = model.generate(
|
97 |
+
inputs["input_ids"],
|
98 |
+
max_new_tokens=256,
|
99 |
+
do_sample=True,
|
100 |
+
early_stopping=False,
|
101 |
+
top_p=0.95,
|
102 |
+
top_k=50,
|
103 |
+
temperature=0.9,
|
104 |
+
# streamer=streamer,
|
105 |
+
no_repeat_ngram_size=2,
|
106 |
+
num_beams=3
|
107 |
+
)
|
108 |
+
|
109 |
+
outputs_txt = tokenizer.decode(outputs[0])
|
110 |
+
print(outputs_txt)
|
111 |
+
|
112 |
+
```
|