Image-Text-to-Text
Transformers
Safetensors
English
locateanything
feature-extraction
nvidia
eagle
vision
object-detection
grounding
conversational
custom_code
Instructions to use Akfmsk/LocateAnything-3B-custom with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Akfmsk/LocateAnything-3B-custom with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Akfmsk/LocateAnything-3B-custom", 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 AutoModel model = AutoModel.from_pretrained("Akfmsk/LocateAnything-3B-custom", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Akfmsk/LocateAnything-3B-custom with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Akfmsk/LocateAnything-3B-custom" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Akfmsk/LocateAnything-3B-custom", "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/Akfmsk/LocateAnything-3B-custom
- SGLang
How to use Akfmsk/LocateAnything-3B-custom 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 "Akfmsk/LocateAnything-3B-custom" \ --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": "Akfmsk/LocateAnything-3B-custom", "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 "Akfmsk/LocateAnything-3B-custom" \ --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": "Akfmsk/LocateAnything-3B-custom", "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 Akfmsk/LocateAnything-3B-custom with Docker Model Runner:
docker model run hf.co/Akfmsk/LocateAnything-3B-custom
Move 16416-sized StaticCache and padded_input_ids allocations after the chunked prefill loop to prevent XLA dynamic shape padding from blowing up the Math SDPA matrix to 17GB
Browse files- modeling_locateanything.py +14 -14
modeling_locateanything.py
CHANGED
|
@@ -381,20 +381,6 @@ class LocateAnythingForConditionalGeneration(LocateAnythingPreTrainedModel, Gene
|
|
| 381 |
def get_max_length(self):
|
| 382 |
return self._max_cache_len_val
|
| 383 |
|
| 384 |
-
past_key_values = LocateAnythingStaticCache(
|
| 385 |
-
config=self.language_model.config,
|
| 386 |
-
batch_size=batch_size,
|
| 387 |
-
max_cache_len=total_gen_length,
|
| 388 |
-
device=self.device,
|
| 389 |
-
dtype=self.language_model.dtype
|
| 390 |
-
)
|
| 391 |
-
|
| 392 |
-
padded_input_ids = torch.zeros((batch_size, total_gen_length), dtype=torch.long, device=self.device)
|
| 393 |
-
padded_input_ids[:, :seq_len] = input_ids
|
| 394 |
-
|
| 395 |
-
current_idx = seq_len
|
| 396 |
-
cache_position = torch.arange(seq_len, device=self.device)
|
| 397 |
-
|
| 398 |
# Initial forward pass (prefill) using chunks to avoid XLA memory allocation OOM!
|
| 399 |
inputs_embeds = self.language_model.model.image_processing(
|
| 400 |
input_ids, vit_embeds, self.config.image_token_index
|
|
@@ -417,6 +403,20 @@ class LocateAnythingForConditionalGeneration(LocateAnythingPreTrainedModel, Gene
|
|
| 417 |
)
|
| 418 |
dynamic_cache = outputs.past_key_values
|
| 419 |
xm.mark_step() # Compile and execute chunk immediately to reclaim memory!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
|
| 421 |
# Populate our StaticCache from the DynamicCache returned by prefill
|
| 422 |
dynamic_cache_list = list(outputs.past_key_values)
|
|
|
|
| 381 |
def get_max_length(self):
|
| 382 |
return self._max_cache_len_val
|
| 383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
# Initial forward pass (prefill) using chunks to avoid XLA memory allocation OOM!
|
| 385 |
inputs_embeds = self.language_model.model.image_processing(
|
| 386 |
input_ids, vit_embeds, self.config.image_token_index
|
|
|
|
| 403 |
)
|
| 404 |
dynamic_cache = outputs.past_key_values
|
| 405 |
xm.mark_step() # Compile and execute chunk immediately to reclaim memory!
|
| 406 |
+
|
| 407 |
+
# Initialize StaticCache and padded_input_ids AFTER the chunk loop to avoid XLA tracking max shapes!
|
| 408 |
+
past_key_values = LocateAnythingStaticCache(
|
| 409 |
+
config=self.language_model.config,
|
| 410 |
+
batch_size=batch_size,
|
| 411 |
+
max_cache_len=total_gen_length,
|
| 412 |
+
device=self.device,
|
| 413 |
+
dtype=self.language_model.dtype
|
| 414 |
+
)
|
| 415 |
+
|
| 416 |
+
padded_input_ids = torch.zeros((batch_size, total_gen_length), dtype=torch.long, device=self.device)
|
| 417 |
+
padded_input_ids[:, :seq_len] = input_ids
|
| 418 |
+
|
| 419 |
+
current_idx = seq_len
|
| 420 |
|
| 421 |
# Populate our StaticCache from the DynamicCache returned by prefill
|
| 422 |
dynamic_cache_list = list(outputs.past_key_values)
|