
# AdaptLLM-4x7B-MoE

AdaptLLM-4x7B-MoE is a Mixure of Experts (MoE) made with the following models using [LazyMergekit](https://colab.research.google.com/drive/1obulZ1ROXHjYLn6PPZJwRR6GzgQogxxb?usp=sharing):
* [mlabonne/NeuralBeagle14-7B](https://huggingface.co/mlabonne/NeuralBeagle14-7B)
* [AdaptLLM/finance-chat](https://huggingface.co/AdaptLLM/finance-chat)
* [AdaptLLM/medicine-chat](https://huggingface.co/AdaptLLM/medicine-chat)
* [AdaptLLM/law-chat](https://huggingface.co/AdaptLLM/law-chat)

## 💻 Usage
```python
Prompt Template:

<s>[INST] <<SYS>>
{{ system_prompt }}
<</SYS>>

{{ user_message }} [/INST]
```

```python
!pip install -qU transformers bitsandbytes accelerate

from transformers import AutoTokenizer
import transformers
import torch

model = "Isotonic/AdaptLLM-4x7B-MoE"

tokenizer = AutoTokenizer.from_pretrained(model)
pipeline = transformers.pipeline(
    "text-generation",
    model=model,
    model_kwargs={
    "torch_dtype": torch.float16,
    "low_cpu_mem_usage": True,
    "use_cache" : False,
    "gradient_checkpointing" : True,
    "device_map" : 'auto',
    "load_in_8bit" : True
    },
)

messages = [{"role": "user", "content": "Explain what a Mixture of Experts is in less than 100 words."}]
prompt = pipeline.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
outputs = pipeline(prompt, max_new_tokens=512, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
print(outputs[0]["generated_text"])
```

## 🧩 Configuration

```yaml
base_model: mlabonne/NeuralBeagle14-7B
experts:
  - source_model: mlabonne/NeuralBeagle14-7B
    positive_prompts:
    - "chat"
    - "assistant"
    - "tell me"
    - "explain"
    - "storywriting"
    - "write"
    - "scene"
    - "story"
    - "character"
    - "instruct"
    - "summarize"
    - "count"

  - source_model: AdaptLLM/finance-chat
    positive_prompts:
    - "personal finance"
    - "budgeting"
    - "investing"
    - "retirement planning"
    - "debt management"
    - "financial education"
    - "consumer protection"
    - "financial"
    - "money"
    - "investment"
    - "banking"
    - "stock"
    - "bond"
    - "portfolio"
    - "risk"
    - "return"

  - source_model: AdaptLLM/medicine-chat
    positive_prompts:
    - "diagnose"
    - "treat"
    - "disease"
    - "symptom"
    - "medication"
    - "anatomy"
    - "physiology"
    - "pharmacology"
    - "clinical trial"
    - "medical research"

  - source_model: AdaptLLM/law-chat
    positive_prompts:
    - "law"
    - "legal"
    - "attorney"
    - "lawyer"
    - "court"
    - "contract"
    - "criminal"
    - "evidence"
    - "procedure"
    - "contracts"
    - "mergers & acquisitions"
    - "corporate governance"
    - "intellectual property"
    - "employment law"
    - "international trade"
    - "competition law"
    - "antitrust"
    - "litigation"
    - "arbitration"
    - "mediation"
```
{"license": "apache-2.0", "tags": ["moe", "merge", "mergekit", "lazymergekit", "mlabonne/NeuralBeagle14-7B", "AdaptLLM/finance-chat", "AdaptLLM/medicine-chat", "AdaptLLM/law-chat"], "datasets": ["Open-Orca/OpenOrca", "WizardLM/WizardLM_evol_instruct_V2_196k", "EleutherAI/pile", "GAIR/lima"], "pipeline_tag": "text-generation"}
transformers safetensors mixtral text-generation moe merge mergekit lazymergekit mlabonne/NeuralBeagle14-7B AdaptLLM/finance-chat AdaptLLM/medicine-chat AdaptLLM/law-chat conversational dataset:Open-Orca/OpenOrca dataset:WizardLM/WizardLM_evol_instruct_V2_196k dataset:EleutherAI/pile dataset:GAIR/lima license:apache-2.0 autotrain_compatible endpoints_compatible has_space text-generation-inference region:us