Text Generation
Transformers
Safetensors
llava-qwen2
Generated from Trainer
axolotl
conversational
custom_code
Instructions to use dphn/dolphin-vision-72b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dphn/dolphin-vision-72b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="dphn/dolphin-vision-72b", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("dphn/dolphin-vision-72b", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use dphn/dolphin-vision-72b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "dphn/dolphin-vision-72b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dphn/dolphin-vision-72b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/dphn/dolphin-vision-72b
- SGLang
How to use dphn/dolphin-vision-72b 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 "dphn/dolphin-vision-72b" \ --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": "dphn/dolphin-vision-72b", "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 "dphn/dolphin-vision-72b" \ --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": "dphn/dolphin-vision-72b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use dphn/dolphin-vision-72b with Docker Model Runner:
docker model run hf.co/dphn/dolphin-vision-72b
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```
|
| 2 |
+
import torch
|
| 3 |
+
import transformers
|
| 4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import warnings
|
| 7 |
+
|
| 8 |
+
# disable some warnings
|
| 9 |
+
transformers.logging.set_verbosity_error()
|
| 10 |
+
transformers.logging.disable_progress_bar()
|
| 11 |
+
warnings.filterwarnings('ignore')
|
| 12 |
+
|
| 13 |
+
# set device
|
| 14 |
+
torch.set_default_device('cuda') # or 'cpu'
|
| 15 |
+
|
| 16 |
+
model_name = 'fne/dolphin-llava-72b'
|
| 17 |
+
|
| 18 |
+
# create model
|
| 19 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 20 |
+
model_name,
|
| 21 |
+
torch_dtype=torch.float16,
|
| 22 |
+
device_map='auto',
|
| 23 |
+
trust_remote_code=True)
|
| 24 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 25 |
+
model_name,
|
| 26 |
+
trust_remote_code=True)
|
| 27 |
+
|
| 28 |
+
# text prompt
|
| 29 |
+
prompt = 'Describe this image in detail'
|
| 30 |
+
|
| 31 |
+
messages = [
|
| 32 |
+
{"role": "user", "content": f'<image>\n{prompt}'}
|
| 33 |
+
]
|
| 34 |
+
text = tokenizer.apply_chat_template(
|
| 35 |
+
messages,
|
| 36 |
+
tokenize=False,
|
| 37 |
+
add_generation_prompt=True
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
print(text)
|
| 41 |
+
|
| 42 |
+
text_chunks = [tokenizer(chunk).input_ids for chunk in text.split('<image>')]
|
| 43 |
+
input_ids = torch.tensor(text_chunks[0] + [-200] + text_chunks[1], dtype=torch.long).unsqueeze(0)
|
| 44 |
+
|
| 45 |
+
# image, sample images can be found in images folder
|
| 46 |
+
image = Image.open('/path/to/image.png')
|
| 47 |
+
image_tensor = model.process_images([image], model.config).to(dtype=model.dtype)
|
| 48 |
+
|
| 49 |
+
# generate
|
| 50 |
+
output_ids = model.generate(
|
| 51 |
+
input_ids,
|
| 52 |
+
images=image_tensor,
|
| 53 |
+
max_new_tokens=2048,
|
| 54 |
+
use_cache=True)[0]
|
| 55 |
+
|
| 56 |
+
print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())
|
| 57 |
+
```
|