Instructions to use starvector/starvector-1b-im2svg with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use starvector/starvector-1b-im2svg with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="starvector/starvector-1b-im2svg", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("starvector/starvector-1b-im2svg", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use starvector/starvector-1b-im2svg with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "starvector/starvector-1b-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-1b-im2svg", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/starvector/starvector-1b-im2svg
- SGLang
How to use starvector/starvector-1b-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-1b-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-1b-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-1b-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-1b-im2svg", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use starvector/starvector-1b-im2svg with Docker Model Runner:
docker model run hf.co/starvector/starvector-1b-im2svg
RecursionError: maximum recursion depth exceeded while calling a Python object
运行代码:
from PIL import Image
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoProcessor
from starvector.data.util import process_and_rasterize_svg
import torch
starvector = AutoModelForCausalLM.from_pretrained("/local/path/", torch_dtype=torch.float16, trust_remote_code=True, local_files_only=False)
processor = starvector.model.processor
tokenizer = starvector.model.svg_transformer.tokenizer
starvector.cuda()
starvector.eval()
image_pil = Image.open('/assets/examples/sample-18.png')
image = processor(image_pil, return_tensors="pt")['pixel_values'].cuda()
if not image.shape[0] == 1:
image = image.squeeze(0)
batch = {"image": image}
raw_svg = starvector.generate_im2svg(batch, max_length=4000)[0]
svg, raster_image = process_and_rasterize_svg(raw_svg)
报错:
RecursionError Traceback (most recent call last)
File ~/anaconda3/envs/starvector/lib/python3.11/site-packages/transformers/tokenization_utils_base.py:2292, in PreTrainedTokenizerBase._from_pretrained(cls, resolved_vocab_files, pretrained_model_name_or_path, init_configuration, token, cache_dir, local_files_only, _commit_hash, _is_local, trust_remote_code, *init_inputs, **kwargs)
2291 try:
-> 2292 tokenizer = cls(*init_inputs, **init_kwargs)
2293 except import_protobuf_decode_error():
File ~/anaconda3/envs/starvector/lib/python3.11/site-packages/transformers/models/gpt2/tokenization_gpt2.py:169, in GPT2Tokenizer.init(self, vocab_file, merges_file, errors, unk_token, bos_token, eos_token, pad_token, add_prefix_space, add_bos_token, **kwargs)
167 self.pat = re.compile(r"""'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+""")
--> 169 super().init(
170 errors=errors,
171 unk_token=unk_token,
172 bos_token=bos_token,
173 eos_token=eos_token,
174 pad_token=pad_token,
175 add_prefix_space=add_prefix_space,
176 add_bos_token=add_bos_token,
177 **kwargs,
178 )
File ~/anaconda3/envs/starvector/lib/python3.11/site-packages/transformers/tokenization_utils.py:435, in PreTrainedTokenizer.init(self, **kwargs)
434 # 4 init the parent class
--> 435 super().init(**kwargs)
437 # 4. If some of the special tokens are not part of the vocab, we add them, at the end.
438 # the order of addition is the same as self.SPECIAL_TOKENS_ATTRIBUTES following tokenizers
...
File :1294, in _get_parent_path(self)
File :1285, in _find_parent_path_names(self)
RecursionError: maximum recursion depth exceeded while calling a Python object