LayerBoost: Layer-Aware Attention Reduction for Efficient LLMs
Paper • 2604.22050 • Published
How to use openchip-sw/Qwen3-4B-LayerBoost with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="openchip-sw/Qwen3-4B-LayerBoost", trust_remote_code=True)
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("openchip-sw/Qwen3-4B-LayerBoost", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("openchip-sw/Qwen3-4B-LayerBoost", trust_remote_code=True)
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 openchip-sw/Qwen3-4B-LayerBoost with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "openchip-sw/Qwen3-4B-LayerBoost"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "openchip-sw/Qwen3-4B-LayerBoost",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/openchip-sw/Qwen3-4B-LayerBoost
How to use openchip-sw/Qwen3-4B-LayerBoost with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "openchip-sw/Qwen3-4B-LayerBoost" \
--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": "openchip-sw/Qwen3-4B-LayerBoost",
"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 "openchip-sw/Qwen3-4B-LayerBoost" \
--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": "openchip-sw/Qwen3-4B-LayerBoost",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use openchip-sw/Qwen3-4B-LayerBoost with Docker Model Runner:
docker model run hf.co/openchip-sw/Qwen3-4B-LayerBoost
A hybrid model developed by Openchip by applying proprietary linearization approach LayerBoost to the Qwen3-4B, reducing latency and increasing token throughtput by 68%.
Details about LayerBoost approach are available on arXiv: https://arxiv.org/pdf/2604.22050v2
Before using this model, install the following system dependencies:
apt-get update
apt-get install -y --no-install-recommends \
build-essential
After that, install the requirements
transformers==4.56.2
accelerate==1.11.0
peft==0.18.0
torch==2.10
flash-attn @ https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.12/flash_attn-2.8.3+cu128torch2.10-cp312-cp312-linux_x86_64.whl
hf auth login
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig
import torch
model_id = "openchip-sw/Qwen3-4B-LayerBoost"
device = "cuda" if torch.cuda.is_available() else "cpu"
config = AutoConfig.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
trust_remote_code=True,
)
model.eval()
model.to(device)
prompt = "give me the list of European countrie accompanied with the capitals"
eval_inputs = tokenizer(prompt, return_tensors="pt")
eval_inputs = {k: v.to(device) for k, v in eval_inputs.items()}
eval_tokens = model.generate(
**eval_inputs,
max_new_tokens=512,
do_sample=False,
use_cache=True,
return_dict_in_generate=True,
)
out_text = tokenizer.decode(eval_tokens.sequences[0], skip_special_tokens=True)
print("Generated text:", out_text)