Text Generation
Transformers
Safetensors
Chinese
English
qwen3_5_text
draft-chain
mlp
qwen3.5
merged-model
Instructions to use LinkRur/Qwen3.5_4B_MLP with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LinkRur/Qwen3.5_4B_MLP with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="LinkRur/Qwen3.5_4B_MLP")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("LinkRur/Qwen3.5_4B_MLP") model = AutoModelForCausalLM.from_pretrained("LinkRur/Qwen3.5_4B_MLP", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use LinkRur/Qwen3.5_4B_MLP with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LinkRur/Qwen3.5_4B_MLP" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LinkRur/Qwen3.5_4B_MLP", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/LinkRur/Qwen3.5_4B_MLP
- SGLang
How to use LinkRur/Qwen3.5_4B_MLP with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "LinkRur/Qwen3.5_4B_MLP" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LinkRur/Qwen3.5_4B_MLP", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
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 "LinkRur/Qwen3.5_4B_MLP" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LinkRur/Qwen3.5_4B_MLP", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use LinkRur/Qwen3.5_4B_MLP with Docker Model Runner:
docker model run hf.co/LinkRur/Qwen3.5_4B_MLP
Download draft_chain.py from LinkRur/Qwen3.5_4B_MLP: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/LinkRur/Qwen3.5_4B_MLP/resolve/main/draft_chain.py
- Command line
-
hf download hf://LinkRur/Qwen3.5_4B_MLP/draft_chain.py
-
curl -L -o draft_chain.py https://huggingface.co/LinkRur/Qwen3.5_4B_MLP/resolve/main/draft_chain.py
1.6 kB
| import math | |
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class DraftBlock(nn.Module): | |
| def __init__(self, D, H): | |
| super().__init__() | |
| self.fc1 = nn.Linear(D, H, bias=False) | |
| self.fc2 = nn.Linear(H, D, bias=False) | |
| self.alpha = nn.Parameter(torch.zeros(())) | |
| self.sqrtD = math.sqrt(D) | |
| def forward(self, s): | |
| ns = s * (self.sqrtD / (s.norm(dim=-1, keepdim=True) + 1e-12)) | |
| return ns + self.fc2(F.silu(self.fc1(ns))) * self.alpha | |
| class DraftDecoderLayer(nn.Module): | |
| def __init__(self, D, H): | |
| super().__init__() | |
| self.block = DraftBlock(D, H) | |
| def forward(self, hidden_states, *a, **k): | |
| return self.block(hidden_states) | |
| def load_merged(model_dir, dtype=torch.bfloat16, device="cuda", chain_hidden=2048): | |
| from transformers import AutoConfig, AutoModelForCausalLM | |
| from safetensors.torch import load_file | |
| cfg = AutoConfig.from_pretrained(model_dir) | |
| m = AutoModelForCausalLM.from_config(cfg).to(device).to(dtype).eval() | |
| n = cfg.num_hidden_layers | |
| for j in range(4): | |
| m.model.layers[n - 4 + j] = DraftDecoderLayer(cfg.hidden_size, chain_hidden).to(device, dtype=dtype) | |
| m.model.norm = nn.Identity() | |
| sd = load_file(f"{model_dir}/model.safetensors", device=device) | |
| sd = {k.replace("model.language_model.", "model.", 1) if k.startswith("model.language_model.") else k: v | |
| for k, v in sd.items()} | |
| if "lm_head.weight" not in sd: | |
| sd["lm_head.weight"] = sd["model.embed_tokens.weight"] | |
| m.load_state_dict(sd, strict=True) | |
| return m | |