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 draftMerge.py from LinkRur/Qwen3.5_4B_MLP: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/LinkRur/Qwen3.5_4B_MLP/resolve/main/draftMerge.py
- Command line
-
hf download hf://LinkRur/Qwen3.5_4B_MLP/draftMerge.py
-
curl -L -o draftMerge.py https://huggingface.co/LinkRur/Qwen3.5_4B_MLP/resolve/main/draftMerge.py
1.51 kB
| import torch | |
| import torch.nn as nn | |
| from trainDraft import DraftChain | |
| class DraftDecoderLayer(nn.Module): | |
| def __init__(self, block): | |
| super().__init__() | |
| self.block = block | |
| def forward(self, hidden_states, position_embeddings=None, attention_mask=None, | |
| position_ids=None, past_key_values=None, use_cache=None, **kwargs): | |
| return self.block(hidden_states) | |
| class _Identity(nn.Module): | |
| def forward(self, x): | |
| return x | |
| def freeze_chain(chain): | |
| for b in chain.blocks: | |
| for name in ("fc1", "fc2"): | |
| wn = getattr(b, name) | |
| w = wn.weight().detach() | |
| lin = nn.Linear(w.shape[1], w.shape[0], bias=False, dtype=w.dtype) | |
| lin.weight.data.copy_(w) | |
| setattr(b, name, lin) | |
| return chain | |
| def load_chain(path, dtype=None): | |
| ckpt = torch.load(path, weights_only=True) | |
| chain = DraftChain(ckpt["D"], ckpt["hidden"], ckpt["k"]) | |
| chain.load_state_dict(ckpt["chain"]) | |
| if dtype is not None: | |
| chain = chain.to(dtype) | |
| chain.eval() | |
| return freeze_chain(chain) | |
| def apply_merge(model, chain): | |
| n = model.config.num_hidden_layers | |
| k = len(chain.blocks) | |
| for _ in range(k): | |
| del model.model.layers[-1] | |
| for j in range(k): | |
| layer = DraftDecoderLayer(chain.blocks[j]) | |
| layer.to(model.device) | |
| model.model.layers.append(layer) | |
| model.model.norm = _Identity() | |
| return model | |