Image-Text-to-Text
Transformers
Safetensors
English
ad_copilot
anomaly-detection
vision-language-model
qwen2.5-vl
conversational
custom_code
Instructions to use jiang-cc/AD-Copilot with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jiang-cc/AD-Copilot with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="jiang-cc/AD-Copilot", trust_remote_code=True) 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 AutoModelForImageTextToText model = AutoModelForImageTextToText.from_pretrained("jiang-cc/AD-Copilot", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use jiang-cc/AD-Copilot with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "jiang-cc/AD-Copilot" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "jiang-cc/AD-Copilot", "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/jiang-cc/AD-Copilot
- SGLang
How to use jiang-cc/AD-Copilot 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 "jiang-cc/AD-Copilot" \ --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": "jiang-cc/AD-Copilot", "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 "jiang-cc/AD-Copilot" \ --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": "jiang-cc/AD-Copilot", "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 jiang-cc/AD-Copilot with Docker Model Runner:
docker model run hf.co/jiang-cc/AD-Copilot
Use diagonal spatial positions for comparison tokens
Browse filesReplace repeated h/w position indices with the evaluated diagonal layout. Keep checkpoint tensors unchanged and document the previous revision for reproducibility.
- README.md +7 -0
- modeling_ad_copilot.py +11 -4
README.md
CHANGED
|
@@ -82,3 +82,10 @@ print(processor.batch_decode(trimmed, skip_special_tokens=True)[0])
|
|
| 82 |
year={2025}
|
| 83 |
}
|
| 84 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
year={2025}
|
| 83 |
}
|
| 84 |
```
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
## Comparison-token positional encoding update
|
| 88 |
+
|
| 89 |
+
The inference code uses diagonal spatial positions for comparison tokens: their height and width indices advance from 0 to `compare_token_size - 1`, while their temporal coordinate remains fixed. This update changes position indices, including downstream position offsets; checkpoint tensors are unchanged.
|
| 90 |
+
|
| 91 |
+
To reproduce the previous shared-position inference behavior, pin `revision="3ddf3a219e5c95223b8c13da18c7b8e53479c5a0"` when loading the model and processor.
|
modeling_ad_copilot.py
CHANGED
|
@@ -712,10 +712,17 @@ class ADCopilotVLModel(Qwen2_5_VLModel):
|
|
| 712 |
if ed_image < ed_video:
|
| 713 |
# 如果当前是图片,则需要插入 compare_token_size 个图像对比的token的position
|
| 714 |
compare_t_index = t_index[-1].repeat(self.compare_token_size)
|
| 715 |
-
#
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 719 |
llm_pos_ids_list.append(torch.stack([compare_t_index, compare_h_index, compare_w_index]) + text_len + st_idx)
|
| 720 |
st = st + self.compare_token_size
|
| 721 |
|
|
|
|
| 712 |
if ed_image < ed_video:
|
| 713 |
# 如果当前是图片,则需要插入 compare_token_size 个图像对比的token的position
|
| 714 |
compare_t_index = t_index[-1].repeat(self.compare_token_size)
|
| 715 |
+
# Comparison tokens use diagonal spatial positions.
|
| 716 |
+
compare_h_index = torch.arange(
|
| 717 |
+
self.compare_token_size,
|
| 718 |
+
device=t_index.device,
|
| 719 |
+
dtype=t_index.dtype,
|
| 720 |
+
)
|
| 721 |
+
compare_w_index = torch.arange(
|
| 722 |
+
self.compare_token_size,
|
| 723 |
+
device=t_index.device,
|
| 724 |
+
dtype=t_index.dtype,
|
| 725 |
+
)
|
| 726 |
llm_pos_ids_list.append(torch.stack([compare_t_index, compare_h_index, compare_w_index]) + text_len + st_idx)
|
| 727 |
st = st + self.compare_token_size
|
| 728 |
|