Update README.md
Browse files
README.md
CHANGED
|
@@ -33,3 +33,65 @@ experts:
|
|
| 33 |
The `positive_prompts` in the above configuration are extracted from the instructions of benchmarks that each model excels in.
|
| 34 |
For reference on the benchmarks for each model, please see the LM Benchmark at [rinnakk's LM Benchmark](https://rinnakk.github.io/research/benchmarks/lm/index.html).
|
| 35 |
These benchmarks provide a detailed overview of the areas where each individual model performs particularly well, guiding the effective use of the merged model in various natural language processing tasks.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
The `positive_prompts` in the above configuration are extracted from the instructions of benchmarks that each model excels in.
|
| 34 |
For reference on the benchmarks for each model, please see the LM Benchmark at [rinnakk's LM Benchmark](https://rinnakk.github.io/research/benchmarks/lm/index.html).
|
| 35 |
These benchmarks provide a detailed overview of the areas where each individual model performs particularly well, guiding the effective use of the merged model in various natural language processing tasks.
|
| 36 |
+
|
| 37 |
+
## 💻 Usage
|
| 38 |
+
|
| 39 |
+
Here's a [Colab notebook](https://colab.research.google.com/drive/1k6C_oJfEKUq0mtuWKisvoeMHxTcIxWRa?usp=sharing) to run Phixtral in 4-bit precision on a free T4 GPU.
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
!pip install -q --upgrade transformers einops accelerate bitsandbytes
|
| 43 |
+
|
| 44 |
+
import torch
|
| 45 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 46 |
+
|
| 47 |
+
model_name = "HachiML/youri-2x7b_dev"
|
| 48 |
+
torch.set_default_device("cuda")
|
| 49 |
+
|
| 50 |
+
# Load the model and tokenizer
|
| 51 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 52 |
+
model_name,
|
| 53 |
+
torch_dtype="auto",
|
| 54 |
+
load_in_4bit=True,
|
| 55 |
+
trust_remote_code=True
|
| 56 |
+
)
|
| 57 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 58 |
+
model_name,
|
| 59 |
+
trust_remote_code=True
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
torch.set_default_device("cuda")
|
| 63 |
+
|
| 64 |
+
# Create input
|
| 65 |
+
instruction = "次の日本語を英語に翻訳してください。"
|
| 66 |
+
input = "大規模言語モデル(だいきぼげんごモデル、英: large language model、LLM)は、多数のパラメータ(数千万から数十億)を持つ人工ニューラルネットワークで構成されるコンピュータ言語モデルで、膨大なラベルなしテキストを使用して自己教師あり学習または半教師あり学習によって訓練が行われる。"
|
| 67 |
+
prompt = f"""
|
| 68 |
+
以下は、タスクを説明する指示と、文脈のある入力の組み合わせです。要求を適切に満たす応答を書きなさい。
|
| 69 |
+
|
| 70 |
+
### 指示:
|
| 71 |
+
{instruction}
|
| 72 |
+
|
| 73 |
+
### 入力:
|
| 74 |
+
{input}
|
| 75 |
+
|
| 76 |
+
### 応答:
|
| 77 |
+
"""
|
| 78 |
+
|
| 79 |
+
# Tokenize the input string
|
| 80 |
+
token_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
|
| 81 |
+
|
| 82 |
+
# Generate text using the model
|
| 83 |
+
with torch.no_grad():
|
| 84 |
+
output_ids = model.generate(
|
| 85 |
+
token_ids.to(model.device),
|
| 86 |
+
max_new_tokens=200,
|
| 87 |
+
do_sample=True,
|
| 88 |
+
temperature=0.5,
|
| 89 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 90 |
+
bos_token_id=tokenizer.bos_token_id,
|
| 91 |
+
eos_token_id=tokenizer.eos_token_id
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
# Decode and print the output
|
| 95 |
+
output = tokenizer.decode(output_ids.tolist()[0])
|
| 96 |
+
print(output)
|
| 97 |
+
```
|