Instructions to use BAAI/Emu2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use BAAI/Emu2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="BAAI/Emu2", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("BAAI/Emu2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use BAAI/Emu2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "BAAI/Emu2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BAAI/Emu2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/BAAI/Emu2
- SGLang
How to use BAAI/Emu2 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 "BAAI/Emu2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BAAI/Emu2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "BAAI/Emu2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BAAI/Emu2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use BAAI/Emu2 with Docker Model Runner:
docker model run hf.co/BAAI/Emu2
| EVA_IMAGE_SIZE = 448 | |
| OPENAI_DATASET_MEAN = (0.48145466, 0.4578275, 0.40821073) | |
| OPENAI_DATASET_STD = (0.26862954, 0.26130258, 0.27577711) | |
| DEFAULT_IMAGE_FILE_SUFFIX = ['jpg', '0.png', 'png', 'jpeg', 'webp'] | |
| DEFAULT_TEXT_FILE_SUFFIX = ['txt', '0.txt'] | |
| IGNORE_INDEX = -100 | |
| # special tokens | |
| # START | |
| DEFAULT_PAD_TOKEN = "[PAD]" | |
| DEFAULT_BOS_TOKEN = '<s>' | |
| DEFAULT_EOS_TOKEN = '</s>' | |
| DEFAULT_UNK_TOKEN = "<unk>" | |
| DEFAULT_IMG_TOKEN = "[IMG]" | |
| DEFAULT_IMG_END_TOKEN = "[/IMG]" | |
| DEFAULT_IMAGE_TOKEN = "<image>" | |
| DEFAULT_gIMG_TOKEN = "[gIMG]" | |
| DEFAULT_gIMG_END_TOKEN = "[/gIMG]" | |
| DEFAULT_EOC_TOKEN = "[EOC]" | |
| DEFAULT_VIDEO_TOKEN = "[VIDEO]" | |
| GRD_SYMBOL = "<grounding>" | |
| BOP_SYMBOL = "<phrase>" | |
| EOP_SYMBOL = "</phrase>" | |
| BOO_SYMBOL = "<object>" | |
| EOO_SYMBOL = "</object>" | |
| DOM_SYMBOL = "</delimiter_of_multi_objects/>" | |
| REC_SYMBOL = "<REC>" | |
| USER_TOKEN = "[USER]" | |
| ASSISTANT_TOKEN = "[ASSISTANT]" | |
| # END | |
| # special token id | |
| # START | |
| IMAGE = 32003 | |
| BOI = 32001 | |
| # END | |
| DEFAULT_IMG_PLACEHOLDER = "[<IMG_PLH>]" | |
| DEFAULT_VID_PLACEHOLDER = "[<VID_PLH>]" | |
| FAKE_VIDEO_END_TOKEN = "[/VIDEO]" |