Image-Text-to-Text
Transformers
Safetensors
English
pdmllm
image-feature-extraction
multimodal
diffusion-language-model
dllm
region-captioning
dense-captioning
parallel-decoding
conversational
custom_code
Instructions to use MSALab/PerceptionDLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MSALab/PerceptionDLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="MSALab/PerceptionDLM", 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)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("MSALab/PerceptionDLM", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use MSALab/PerceptionDLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "MSALab/PerceptionDLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "MSALab/PerceptionDLM", "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/MSALab/PerceptionDLM
- SGLang
How to use MSALab/PerceptionDLM 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 "MSALab/PerceptionDLM" \ --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": "MSALab/PerceptionDLM", "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 "MSALab/PerceptionDLM" \ --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": "MSALab/PerceptionDLM", "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 MSALab/PerceptionDLM with Docker Model Runner:
docker model run hf.co/MSALab/PerceptionDLM
File size: 2,860 Bytes
cadf670 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | from dataclasses import dataclass
@dataclass
class dLLMCacheConfig:
prompt_interval_steps: int = 1
gen_interval_steps: int = 1
transfer_ratio: float = 0.0
cfg_interval_steps: int = 1
import torch
from collections import defaultdict
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
class dLLMCache(metaclass=Singleton):
gen_interval_steps: int
prompt_interval_steps: int
cfg_interval_steps: int
prompt_length: int
transfer_ratio: float
__cache: defaultdict
__step_counter: defaultdict
@classmethod
def new_instance(
cls,
prompt_interval_steps: int = 1,
gen_interval_steps: int = 1,
cfg_interval_steps: int = 1,
transfer_ratio: float = 0.0,
) -> "dLLMCache":
ins = cls()
setattr(ins, "prompt_interval_steps", prompt_interval_steps)
setattr(ins, "gen_interval_steps", gen_interval_steps)
setattr(ins, "cfg_interval_steps", cfg_interval_steps)
setattr(ins, "transfer_ratio", transfer_ratio)
ins.init()
return ins
def init(self) -> None:
self.__cache = defaultdict(
lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(dict)))
)
self.__step_counter = defaultdict(lambda: defaultdict(lambda: 0))
def reset_cache(self, prompt_length: int = 0) -> None:
self.init()
torch.cuda.empty_cache()
self.prompt_length = prompt_length
self.cache_type = "no_cfg"
def set_cache(
self, layer_id: int, feature_name: str, features: torch.Tensor, cache_type: str
) -> None:
self.__cache[self.cache_type][cache_type][layer_id][feature_name] = {
0: features
}
def get_cache(
self, layer_id: int, feature_name: str, cache_type: str
) -> torch.Tensor:
output = self.__cache[self.cache_type][cache_type][layer_id][feature_name][0]
return output
def update_step(self, layer_id: int) -> None:
self.__step_counter[self.cache_type][layer_id] += 1
def refresh_gen(self, layer_id: int = 0) -> bool:
return (self.current_step - 1) % self.gen_interval_steps == 0
def refresh_prompt(self, layer_id: int = 0) -> bool:
return (self.current_step - 1) % self.prompt_interval_steps == 0
def refresh_cfg(self, layer_id: int = 0) -> bool:
return (
self.current_step - 1
) % self.cfg_interval_steps == 0 or self.current_step <= 5
@property
def current_step(self) -> int:
return max(list(self.__step_counter[self.cache_type].values()), default=1)
def __repr__(self):
return f"USE dLLMCache"
|