Instructions to use starvector/starvector-8b-im2svg with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use starvector/starvector-8b-im2svg with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="starvector/starvector-8b-im2svg", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("starvector/starvector-8b-im2svg", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use starvector/starvector-8b-im2svg with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "starvector/starvector-8b-im2svg" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "starvector/starvector-8b-im2svg", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/starvector/starvector-8b-im2svg
- SGLang
How to use starvector/starvector-8b-im2svg 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 "starvector/starvector-8b-im2svg" \ --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": "starvector/starvector-8b-im2svg", "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 "starvector/starvector-8b-im2svg" \ --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": "starvector/starvector-8b-im2svg", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use starvector/starvector-8b-im2svg with Docker Model Runner:
docker model run hf.co/starvector/starvector-8b-im2svg
why echo "couldn't find them in the cached files." when run local starvector model
import os
import sys
from PIL import Image
from starvector.model.starvector_arch import StarVectorForCausalLM
from starvector.data.util import process_and_rasterize_svg
#from transformers import set_offline_mode
#set_offline_mode(True)
import os
os.environ["TRANSFORMERS_OFFLINE"] = "1" # 启用离线模式
os.environ["HF_DATASETS_OFFLINE"] = "1" # 如果用到datasets库也设置离线
import os
os.environ['TRITON_CACHE_DIR'] = os.path.expanduser('S:\cache')
===== 核心修复:彻底禁用DeepSpeed的Triton自动调优 =====
1. 设置环境变量禁用自动调优
os.environ["DEEPSPEED_DISABLE_TRITON_AUTOTUNE"] = "1"
2. 动态修改DeepSpeed的is_nfs_path函数(防止残留调用)
if sys.platform == "win32":
import deepspeed.ops.transformer.inference.triton.matmul_ext as matmul_ext
def _dummy_nfs_check(path):
return False
matmul_ext.is_nfs_path = _dummy_nfs_check
3. 禁用Triton相关模块加载(可选)
if "deepspeed.ops.transformer.inference.triton" in sys.modules:
del sys.modules["deepspeed.ops.transformer.inference.triton"]
========================================================
本地模型路径
#model_name = "s:\forstarvector\starvector"
model_name = "starvector-8b-im2svg"
#model_name = "./for_starvector"
#model_name = "ServiceNow/starvector-8b-im2svg"
#model_name = "starvector-8b-im2svg"
加载模型(若仍报错,可尝试添加device_map='auto')
starvector = StarVectorForCausalLM.from_pretrained(
model_name,
device_map="auto", # 自动分配设备,避免CUDA问题
local_files_only=True
)
starvector.eval()
print(starvector.config) # 打印配置信息
print(starvector.image_encoder) # 确认图像编码器加载
处理图片(注意:可能需要调整设备分配)
image_pil = Image.open('./assets/examples/sample-0.png')
image = starvector.process_images([image_pil])[0]
if torch.cuda.is_available():
image = image.cuda()
batch = {"image": image}
生成SVG
raw_svg = starvector.generate_im2svg(batch, max_length=1000)[0]
svg, raster_image = process_and_rasterize_svg(raw_svg)
保存结果
with open("generated_svg.svg", "w", encoding="utf-8") as f:
f.write(svg)