DELLA-Merging: Reducing Interference in Model Merging through Magnitude-Based Sampling
Paper • 2406.11617 • Published • 10
How to use Cran-May/PCB-NRSheared-2 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="Cran-May/PCB-NRSheared-2")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Cran-May/PCB-NRSheared-2")
model = AutoModelForCausalLM.from_pretrained("Cran-May/PCB-NRSheared-2")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use Cran-May/PCB-NRSheared-2 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "Cran-May/PCB-NRSheared-2"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Cran-May/PCB-NRSheared-2",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/Cran-May/PCB-NRSheared-2
How to use Cran-May/PCB-NRSheared-2 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "Cran-May/PCB-NRSheared-2" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Cran-May/PCB-NRSheared-2",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "Cran-May/PCB-NRSheared-2" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Cran-May/PCB-NRSheared-2",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use Cran-May/PCB-NRSheared-2 with Docker Model Runner:
docker model run hf.co/Cran-May/PCB-NRSheared-2
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Cran-May/PCB-NRSheared-2")
model = AutoModelForCausalLM.from_pretrained("Cran-May/PCB-NRSheared-2")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))This is a merge of pre-trained language models created using mergekit.
This model was merged using the DELLA merge method using huihui-ai/Mistral-Small-24B-Instruct-2501-abliterated as a base.
The following models were included in the merge:
The following YAML configuration was used to produce this model:
# 文件名: pcb_della_merge_12b.yaml
merge_method: della # 仍然使用 DELLA,因为它是一个强大的自适应剪裁方法
base_model: huihui-ai/Mistral-Small-24B-Instruct-2501-abliterated
models:
- model: trashpanda-org/MS-24B-Instruct-Mullein-v0
parameters:
weight: 1.0
# PCB策略:限制层影响范围 + 动态竞争平衡
layers:
- layers: "8-16"
parameter_name: density
value: 0.4
- layers: "8-16"
parameter_name: epsilon
value: 0.15
- layers: "8-16"
parameter_name: lambda
value: 1.5
- layers: "17-24"
parameter_name: density
value: 0.2
variance_threshold: 0.3
- model: AlSamCur123/Mistral-Small3-24B-InstructContinuedFine
parameters:
weight: 1.0
# 强化指令理解层
layers:
- layers: "0-12"
parameter_name: density
value: 0.7
- layers: "0-12"
parameter_name: epsilon
value: 0.05
- layers: "0-12"
parameter_name: lambda
value: 2.0
variance_threshold: 0.25
- model: huihui-ai/Mistral-Small-24B-Instruct-2501-abliterated
parameters:
weight: 1.0
# 基模型参数保护策略
density: 0.9
layers:
- layers: "12-24"
parameter_name: density
value: 1.0
parameters:
global_density: 0.55 # 全局剪裁密度(PCB平衡点)
intra_balance: true
variance_threshold: 0.2
epsilon_range: [0.1, 0.2]
tokenizer:
source: base
generation_config:
eos_token_id: 2
pad_token_id: 2
repetition_penalty: 1.15
top_k: 40
temperature: 0.8
# 参数压缩设置 (目标 12-13B 模型)
architecture:
hidden_size: 3072 # 显著降低 hidden_size (原始 5120 -> 4096 -> 3072)
intermediate_size: 8256 # 相应调整 intermediate_size (比例保持不变)
num_attention_heads: 24 # 相应减少 attention heads (比例保持不变)
num_hidden_layers: 30 # 层数保持 30 层 (适度压缩)
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Cran-May/PCB-NRSheared-2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)