File size: 2,386 Bytes
f38e7bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b44560
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66a2e59
5b44560
66a2e59
f38e7bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
base_model:
- Qwen/Qwen2-1.5B
- Replete-AI/Replete-Coder-Qwen2-1.5b
license: apache-2.0
tags:
- moe
- frankenmoe
- merge
- mergekit
- lazymergekit
- Qwen/Qwen2-1.5B
- Replete-AI/Replete-Coder-Qwen2-1.5b
---

# QwenMoEAriel

QwenMoEAriel is a Mixture of Experts (MoE) made with the following models using [LazyMergekit](https://colab.research.google.com/drive/1obulZ1ROXHjYLn6PPZJwRR6GzgQogxxb?usp=sharing):
* [Qwen/Qwen2-1.5B](https://huggingface.co/Qwen/Qwen2-1.5B)
* [Replete-AI/Replete-Coder-Qwen2-1.5b](https://huggingface.co/Replete-AI/Replete-Coder-Qwen2-1.5b)

## 🧩 Configuration
base_model : Qwen/Qwen2-1.5B 
architecture: qwen 
experts: 
  - source_model: Qwen/Qwen2-1.5B 
    positive_prompts: 
    - "chat" 
    - "assistant" 
    - "tell me" 
    - "explain" 
    - "I want" 
  - source_model: Replete-AI/Replete-Coder-Qwen2-1.5b 
    positive_prompts: 
    - "code" 
    - "python" 
    - "javascript" 
    - "programming" 
    - "algorithm" 
shared_experts: 
  - source_model: Qwen/Qwen2-1.5B 
    positive_prompts: # required by Qwen MoE for "hidden" gate mode, otherwise not allowed 
    - "chat" 
    # (optional, but recommended:) 
     residual_scale: 0.1 # downweight output from shared expert to prevent overcooking the model 

## 💻 Usage

```python
!pip install -qU transformers bitsandbytes accelerate einops
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print(device)
model = AutoModelForCausalLM.from_pretrained(
    "femiari/Qwen2-1.5Moe",
    torch_dtype=torch.float16,
    ignore_mismatched_sizes=True
).to(device)
tokenizer = AutoTokenizer.from_pretrained("femiari/Qwen2-1.5Moe")

prompt = "Give me a short introduction to large language model."
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]

print(response)

```