Instructions to use j-llm/Qwen3.5-2B-Longbook2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use j-llm/Qwen3.5-2B-Longbook2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="j-llm/Qwen3.5-2B-Longbook2") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("j-llm/Qwen3.5-2B-Longbook2") model = AutoModelForMultimodalLM.from_pretrained("j-llm/Qwen3.5-2B-Longbook2", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use j-llm/Qwen3.5-2B-Longbook2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "j-llm/Qwen3.5-2B-Longbook2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "j-llm/Qwen3.5-2B-Longbook2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/j-llm/Qwen3.5-2B-Longbook2
- SGLang
How to use j-llm/Qwen3.5-2B-Longbook2 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 "j-llm/Qwen3.5-2B-Longbook2" \ --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": "j-llm/Qwen3.5-2B-Longbook2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "j-llm/Qwen3.5-2B-Longbook2" \ --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": "j-llm/Qwen3.5-2B-Longbook2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use j-llm/Qwen3.5-2B-Longbook2 with Docker Model Runner:
docker model run hf.co/j-llm/Qwen3.5-2B-Longbook2
Qwen3.5-2B-Longbook2 (accuracy-recovered)
ๅคๆๅ
ใขใใซ ใฏ Qwen3.5-2B ใฎๅ
จ full-attention ๅฑคใ
Gated DeltaNet (GDN) ใซ็ฝฎใๆใใ all-GDN ใขใใซใงใใ็ฝฎๆใง่ฝใกใ็ฒพๅบฆใใ
ๅ
ใขใใซ Qwen/Qwen3.5-2B ใๆๅธซใจใใ่ธ็ใงๅๅพฉใใใใฎใใใฎใชใใธใใชใงใใ
่ฟฝๅ ใฎ็ฅ่ญใใผใฟใงใฎ SFT ใฏ่กใฃใฆใใพใใ(ๅพฉๅ
ใฎใฟ)ใ
- ๅ จๅฑคใ็ทๅฝขใขใใณใทใงใณ โ KV ใญใฃใใทใฅใๅขใใใ้ทๆใงใใกใขใชใป้ๅบฆใไธๅฎ
- ๆจๆบใฎ
transformersใงใใฎใพใพ่ชญใฟ่พผใใพใ(trust_remote_codeไธ่ฆ) flash-linear-attentionใๅ ฅใใใจ้ซ้ใซใผใใซใไฝฟใใใพใ
ๅพฉๅ ๆนๆณ
- Stage 1 (ๅฑคใใจใฎ่ธ็): ็ฝฎๆใใๅ GDN ๅฑคใฎๅบๅใๅ ใฎ full-attention ๅฑคใฎๅบๅใซๅใใใ (็ธๅฏพ MSE + ใณใตใคใณ)ใๅฑค้ใฎๅ ฅๅใฏ detach ใใๅ จๅฑคใไธฆๅใซๅญฆ็ฟใ
- Stage 2 (end-to-end): ๆๅธซ logits ใธใฎ KL + ้ ใ็ถๆ ๆๅคฑใงๅ จไฝใๅพฎ่ชฟๆดใ
- ๅญฆ็ฟใใ้ใฟใๅ ใฎ safetensors ใทใฃใผใใฎ่ฉฒๅฝใใณใฝใซใ ใๅทฎใๆฟใใฆๅบๅใ
fp32 ใในใฟใผ้ใฟ + bf16 autocastใfused AdamWใ
็ตๆ
(่ฉไพกๅคใฏๆช่จๅ ฅ)
(ๅไธใฎ่ฉไพกใใญในใใปๅไธๆกไปถใงๆธฌๅฎใๆๅธซใฏ Qwen/Qwen3.5-2B)
ไฝฟใๆน
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "j-llm/Qwen3.5-2B-Longbook2"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, dtype=torch.bfloat16, device_map="cuda").eval()
ids = tok.apply_chat_template([{"role": "user", "content": "ๆฅๆฌใฎ้ฆ้ฝใฏใฉใ๏ผ"}],
add_generation_prompt=True, return_tensors="pt", return_dict=True, enable_thinking=False).to(model.device)
out = model.generate(**ids, max_new_tokens=128, use_cache=False) # ไธใฎๆณจๆๅ็
ง
print(tok.decode(out[0, ids["input_ids"].shape[1]:], skip_special_tokens=True))
ๆณจๆ
- ๅ
จๅฑคใ็ทๅฝขใขใใณใทใงใณใฎใใใ็พ่ก
transformersใฎๆจๆบCacheใฏget_seq_lengthใงValueErrorใๅบใใใจใใใใพใใใใฎๅ ดๅใฏuse_cache=False(้ ใใ็ขบๅฎ)ใซใใใใget_seq_lengthใไพๅคๆใซ่ชๅใซใฆใณใฟใธใใฉใผใซใใใฏใใใใใใใๅฝใฆใฆใใ ใใใ - ่ธ็ใฏๆๅธซใฎๆๅใธใฎ่ฟไผผใงใใใๅ ใขใใซใจๅฎๅ จใซใฏไธ่ดใใพใใใ็นใซๆจ่ซใปๆฐๅญฆใปใณใผใใฏๅ ใขใใซใใๅฃใๅฏ่ฝๆงใใใใพใใ
- ใฉใคใปใณในใฏๅ ใขใใซ(Qwen/Qwen3.5-2B)ใซๅพใใพใใ
่ฌ่พ
ๅคๆใขใใซ: summerMC / ๅ ใขใใซ: Qwen Team
- Downloads last month
- 306