Instructions to use NaughtyDog97/DiagramFormalizer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NaughtyDog97/DiagramFormalizer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="NaughtyDog97/DiagramFormalizer", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("NaughtyDog97/DiagramFormalizer", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use NaughtyDog97/DiagramFormalizer with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "NaughtyDog97/DiagramFormalizer" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NaughtyDog97/DiagramFormalizer", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/NaughtyDog97/DiagramFormalizer
- SGLang
How to use NaughtyDog97/DiagramFormalizer 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 "NaughtyDog97/DiagramFormalizer" \ --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": "NaughtyDog97/DiagramFormalizer", "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 "NaughtyDog97/DiagramFormalizer" \ --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": "NaughtyDog97/DiagramFormalizer", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use NaughtyDog97/DiagramFormalizer with Docker Model Runner:
docker model run hf.co/NaughtyDog97/DiagramFormalizer
Upload README.md
Browse files
README.md
CHANGED
|
@@ -7,13 +7,7 @@ license: apache-2.0
|
|
| 7 |
在运行脚本之前,首先安装如下必要的依赖。
|
| 8 |
|
| 9 |
```shell
|
| 10 |
-
pip install
|
| 11 |
-
pip install torch transformers==4.40.0
|
| 12 |
-
pip install sentencepiece protobuf
|
| 13 |
-
pip install accelerate pillow
|
| 14 |
-
pip install ninja
|
| 15 |
-
pip install packaging
|
| 16 |
-
pip install flash-attn --no-build-isolation
|
| 17 |
```
|
| 18 |
|
| 19 |
```python
|
|
@@ -24,27 +18,6 @@ from PIL import Image
|
|
| 24 |
import warnings
|
| 25 |
import numpy as np
|
| 26 |
|
| 27 |
-
def tokenizer_image_token(prompt, tokenizer, image_token_index, return_tensors=None):
|
| 28 |
-
prompt_chunks = [tokenizer(chunk).input_ids for chunk in prompt.split('<image>')]
|
| 29 |
-
|
| 30 |
-
def insert_separator(X, sep):
|
| 31 |
-
return [ele for sublist in zip(X, [sep] * len(X)) for ele in sublist][:-1]
|
| 32 |
-
|
| 33 |
-
input_ids = []
|
| 34 |
-
offset = 0
|
| 35 |
-
if len(prompt_chunks) > 0 and len(prompt_chunks[0]) > 0 and prompt_chunks[0][0] == tokenizer.bos_token_id:
|
| 36 |
-
offset = 1
|
| 37 |
-
input_ids.append(prompt_chunks[0][0])
|
| 38 |
-
|
| 39 |
-
for x in insert_separator(prompt_chunks, [image_token_index] * (offset + 1)):
|
| 40 |
-
input_ids.extend(x[offset:])
|
| 41 |
-
|
| 42 |
-
if return_tensors is not None:
|
| 43 |
-
if return_tensors == 'pt':
|
| 44 |
-
return torch.tensor(input_ids, dtype=torch.long)
|
| 45 |
-
raise ValueError(f'Unsupported tensor type: {return_tensors}')
|
| 46 |
-
return input_ids
|
| 47 |
-
|
| 48 |
# set device
|
| 49 |
device = 'cuda' # or cpu
|
| 50 |
torch.set_default_device(device)
|
|
@@ -65,6 +38,28 @@ tokenizer = AutoTokenizer.from_pretrained(
|
|
| 65 |
img_path = 'sample/4927.png'
|
| 66 |
prompt = 'Based on the image, first describe what you see in the figure, then predict the construction_cdl and image_cdl and calibrate it.'
|
| 67 |
text = f"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<image>\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
input_ids = tokenizer_image_token(text, tokenizer, -200, return_tensors='pt').unsqueeze(0).cuda()
|
| 69 |
|
| 70 |
# image, sample images can be found in images folder
|
|
|
|
| 7 |
在运行脚本之前,首先安装如下必要的依赖。
|
| 8 |
|
| 9 |
```shell
|
| 10 |
+
pip install torch transformers==4.40.0 accelerate pillow sentencepiece
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
```
|
| 12 |
|
| 13 |
```python
|
|
|
|
| 18 |
import warnings
|
| 19 |
import numpy as np
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# set device
|
| 22 |
device = 'cuda' # or cpu
|
| 23 |
torch.set_default_device(device)
|
|
|
|
| 38 |
img_path = 'sample/4927.png'
|
| 39 |
prompt = 'Based on the image, first describe what you see in the figure, then predict the construction_cdl and image_cdl and calibrate it.'
|
| 40 |
text = f"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<image>\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
|
| 41 |
+
|
| 42 |
+
def tokenizer_image_token(prompt, tokenizer, image_token_index, return_tensors=None):
|
| 43 |
+
prompt_chunks = [tokenizer(chunk).input_ids for chunk in prompt.split('<image>')]
|
| 44 |
+
|
| 45 |
+
def insert_separator(X, sep):
|
| 46 |
+
return [ele for sublist in zip(X, [sep] * len(X)) for ele in sublist][:-1]
|
| 47 |
+
|
| 48 |
+
input_ids = []
|
| 49 |
+
offset = 0
|
| 50 |
+
if len(prompt_chunks) > 0 and len(prompt_chunks[0]) > 0 and prompt_chunks[0][0] == tokenizer.bos_token_id:
|
| 51 |
+
offset = 1
|
| 52 |
+
input_ids.append(prompt_chunks[0][0])
|
| 53 |
+
|
| 54 |
+
for x in insert_separator(prompt_chunks, [image_token_index] * (offset + 1)):
|
| 55 |
+
input_ids.extend(x[offset:])
|
| 56 |
+
|
| 57 |
+
if return_tensors is not None:
|
| 58 |
+
if return_tensors == 'pt':
|
| 59 |
+
return torch.tensor(input_ids, dtype=torch.long)
|
| 60 |
+
raise ValueError(f'Unsupported tensor type: {return_tensors}')
|
| 61 |
+
return input_ids
|
| 62 |
+
|
| 63 |
input_ids = tokenizer_image_token(text, tokenizer, -200, return_tensors='pt').unsqueeze(0).cuda()
|
| 64 |
|
| 65 |
# image, sample images can be found in images folder
|