Image-Text-to-Text
Transformers
Safetensors
qwen3_5_moe
qwen
qwen3
vlm
Mixture of Experts
dpo
uncensored
abliterated
refusal-ablation
fp16
vision
conversational
Instructions to use lxz8798/qwen3.6-35b-moe-kuato-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lxz8798/qwen3.6-35b-moe-kuato-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="lxz8798/qwen3.6-35b-moe-kuato-base") 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)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("lxz8798/qwen3.6-35b-moe-kuato-base") model = AutoModelForMultimodalLM.from_pretrained("lxz8798/qwen3.6-35b-moe-kuato-base", 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lxz8798/qwen3.6-35b-moe-kuato-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lxz8798/qwen3.6-35b-moe-kuato-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lxz8798/qwen3.6-35b-moe-kuato-base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/lxz8798/qwen3.6-35b-moe-kuato-base
- SGLang
How to use lxz8798/qwen3.6-35b-moe-kuato-base 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 "lxz8798/qwen3.6-35b-moe-kuato-base" \ --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": "lxz8798/qwen3.6-35b-moe-kuato-base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "lxz8798/qwen3.6-35b-moe-kuato-base" \ --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": "lxz8798/qwen3.6-35b-moe-kuato-base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use lxz8798/qwen3.6-35b-moe-kuato-base with Docker Model Runner:
docker model run hf.co/lxz8798/qwen3.6-35b-moe-kuato-base
Update handler.py
Browse files- handler.py +17 -56
handler.py
CHANGED
|
@@ -1,68 +1,29 @@
|
|
| 1 |
import subprocess
|
| 2 |
import sys
|
|
|
|
| 3 |
|
| 4 |
-
# 🚀 强制
|
| 5 |
try:
|
| 6 |
-
print("Starting hot-upgrade of transformers and accelerate...")
|
| 7 |
subprocess.run(
|
| 8 |
[sys.executable, "-m", "pip", "install", "--upgrade", "transformers", "accelerate", "--user"],
|
| 9 |
check=True
|
| 10 |
)
|
| 11 |
-
print("Hot-upgrade completed successfully!")
|
| 12 |
except Exception as e:
|
| 13 |
-
print(f"Warning during hot-upgrade: {e}")
|
| 14 |
|
| 15 |
-
# -
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def __init__(self, path=""):
|
| 21 |
-
# 1. 使用 trust_remote_code=True 加载 Tokenizer 和 Model
|
| 22 |
-
self.tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
|
| 23 |
-
self.model = AutoModelForCausalLM.from_pretrained(
|
| 24 |
-
path,
|
| 25 |
-
torch_dtype=torch.bfloat16,
|
| 26 |
-
device_map="auto",
|
| 27 |
-
trust_remote_code=True
|
| 28 |
-
)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
parameters = data.get("parameters", {})
|
| 35 |
-
|
| 36 |
-
# 3. 兼容 OpenAI 格式的 Chat completion
|
| 37 |
-
if messages is not None:
|
| 38 |
-
formatted_input = self.tokenizer.apply_chat_template(
|
| 39 |
-
messages, tokenize=False, add_generation_prompt=True
|
| 40 |
-
)
|
| 41 |
-
else:
|
| 42 |
-
formatted_input = inputs
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# 5. 解析参数
|
| 48 |
-
max_new_tokens = parameters.get("max_new_tokens", parameters.get("max_tokens", 128))
|
| 49 |
-
temperature = parameters.get("temperature", 0.7)
|
| 50 |
-
top_p = parameters.get("top_p", 0.9)
|
| 51 |
-
do_sample = parameters.get("do_sample", True)
|
| 52 |
-
|
| 53 |
-
# 6. 进行推理
|
| 54 |
-
with torch.no_grad():
|
| 55 |
-
outputs = self.model.generate(
|
| 56 |
-
**inputs_tokenized,
|
| 57 |
-
max_new_tokens=max_new_tokens,
|
| 58 |
-
temperature=temperature,
|
| 59 |
-
top_p=top_p,
|
| 60 |
-
do_sample=do_sample
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
# 7. 只解码新生成的回复部分
|
| 64 |
-
input_length = inputs_tokenized.input_ids.shape[1]
|
| 65 |
-
reply = self.tokenizer.decode(outputs[0][input_length:], skip_special_tokens=True)
|
| 66 |
-
|
| 67 |
-
# 返回符合 Hugging Face 规范的格式
|
| 68 |
-
return [{"generated_text": reply}]
|
|
|
|
| 1 |
import subprocess
|
| 2 |
import sys
|
| 3 |
+
import site
|
| 4 |
|
| 5 |
+
# 🚀 1. 强制从 PyPI 热升级 transformers 和 accelerate 到最新版本
|
| 6 |
try:
|
| 7 |
+
print("Starting hot-upgrade of transformers and accelerate...", flush=True)
|
| 8 |
subprocess.run(
|
| 9 |
[sys.executable, "-m", "pip", "install", "--upgrade", "transformers", "accelerate", "--user"],
|
| 10 |
check=True
|
| 11 |
)
|
| 12 |
+
print("Hot-upgrade completed successfully!", flush=True)
|
| 13 |
except Exception as e:
|
| 14 |
+
print(f"Warning during hot-upgrade: {e}", flush=True)
|
| 15 |
|
| 16 |
+
# 🚀 2. 强制将 user site-packages 插入到 sys.path 的最前面,覆盖系统自带的旧版库
|
| 17 |
+
user_site = site.getusersitepackages()
|
| 18 |
+
if user_site in sys.path:
|
| 19 |
+
sys.path.remove(user_site)
|
| 20 |
+
sys.path.insert(0, user_site)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# 🚀 3. 清理内存中已加载的旧版模块,强制 Python 重新从新路径导入
|
| 23 |
+
for mod in list(sys.modules.keys()):
|
| 24 |
+
if mod.startswith("transformers") or mod.startswith("accelerate"):
|
| 25 |
+
del sys.modules[mod]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# ----------------- 路径重排和模块清理完成后,导入新版库 -----------------
|
| 28 |
+
import torch
|
| 29 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|