Views
No views yet
llama.cpp -ncmoe).upcycle.py)state_dict, so loading needs the surgery code:1# pip install torch transformers ; git clone https://github.com/outlast85/moe-upcycle
2import torch
3from transformers import AutoModelForCausalLM, AutoTokenizer
4from upcycle import upcycle_model # from the moe-upcycle repo
5
6tok = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B")
7m = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B", dtype=torch.bfloat16)
8upcycle_model(m, num_experts=4, top_k=1, drop_fraction=0.3, num_shared=1)
9for l in m.model.layers: l.mlp.router.float()
10m.load_state_dict(torch.load("mode_b_domain_experts.pt"))
11m.eval()
12# expert map: 0=code, 1=conversation, 2=explanation, 3=web