huggingface.co
Total runs: 102
24-hour runs: -2
7-day runs: 8
30-day runs: 38
Model's Last Updated: December 21 2023
text-generation

Introduction of Emu2

Model Details of Emu2

The human ability to easily solve multimodal tasks in context (i.e., with only a few demonstrations or simple instructions), is what current multimodal systems have largely struggled to imitate. In this work, we demonstrate that the task-agnostic in-context learning capabilities of large multimodal models can be significantly enhanced by effective scaling-up. We introduce Emu2 , a generative multimodal model with 37 billion parameters, trained on large-scale multimodal sequences with a unified autoregressive objective. Emu2 exhibits strong multimodal in-context learning abilities, even emerging to solve tasks that require on-the-fly reasoning, such as visual prompting and object-grounded generation. The model sets a new record on multiple multimodal understanding tasks in few-shot settings. When instruction-tuned to follow specific instructions, Emu2 further achieves new state-of-the-art on challenging tasks such as question answering benchmarks for large multimodal models and open-ended subject-driven generation. These achievements demonstrate that Emu2 can serve as a base model and general-purpose interface for a wide range of multimodal tasks. Code and models are publicly available to facilitate future research.

Model Weights
Model name Weight
Emu2 🤗 HF link
Emu2-Chat 🤗 HF link
Emu2-Gen 🤗 HF link
Inference (Huggingface Version)
Single GPU
from PIL import Image
import requests
import torch 
from transformers import AutoModelForCausalLM, AutoTokenizer


tokenizer = AutoTokenizer.from_pretrained("BAAI/Emu2")

model = AutoModelForCausalLM.from_pretrained(
    "BAAI/Emu2",
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
    trust_remote_code=True).to('cuda').eval()


# `[<IMG_PLH>]` is the image placeholder which will be replaced by image embeddings. 
# the number of `[<IMG_PLH>]` should be equal to the number of input images

query = '[<IMG_PLH>]Describe the image in details:' 
image = Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/blue_black_1_top_left.jpg?raw=true',stream=True).raw).convert('RGB')


inputs = model.build_input_ids(
    text=[query],
    tokenizer=tokenizer,
    image=[image]
)

with torch.no_grad():
     outputs = model.generate(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        image=inputs["image"].to(torch.bfloat16),
        max_new_tokens=64,
        length_penalty=-1)

output_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)

Interleaved image and text

from PIL import Image
import requests
import torch 
from transformers import AutoModelForCausalLM, AutoTokenizer


tokenizer = AutoTokenizer.from_pretrained("BAAI/Emu2")

model = AutoModelForCausalLM.from_pretrained(
    "BAAI/Emu2",
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
    trust_remote_code=True).to('cuda').eval()

# `[<IMG_PLH>]` is the image placeholder which will be replaced by image embeddings. 
# the number of `[<IMG_PLH>]` should be equal to the number of input images

query = "[<IMG_PLH>][red, white, 3, bottom left].[<IMG_PLH>][yellow, white, 2, top left].[<IMG_PLH>][green, black, 4, bottom right][<IMG_PLH>]"

images = [
    Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/red_white_3_bottom_left.jpg?raw=true',stream=True).raw).convert('RGB'),
    Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/yellow_white_2_top_right.jpg?raw=true',stream=True).raw).convert('RGB'),
    Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/green_black_4_bottom_right.jpg?raw=true',stream=True).raw).convert('RGB'),
    Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/blue_black_1_top_left.jpg?raw=true',stream=True).raw).convert('RGB'),
]

inputs = model.build_input_ids(
    text=[query],
    tokenizer=tokenizer,
    image=images

)

with torch.no_grad():
     outputs = model.generate(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        image=inputs["image"].to(torch.bfloat16),
        max_new_tokens=64,
        length_penalty=-1)

output_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
Multi GPU
from PIL import Image 
import requests
import torch 
from transformers import AutoModelForCausalLM, AutoTokenizer
from accelerate import init_empty_weights, infer_auto_device_map, load_checkpoint_and_dispatch

tokenizer = AutoTokenizer.from_pretrained("BAAI/Emu2")

with init_empty_weights():
     model = AutoModelForCausalLM.from_pretrained(
        "BAAI/Emu2",
        torch_dtype=torch.bfloat16,
        low_cpu_mem_usage=True,
        trust_remote_code=True)  

device_map = infer_auto_device_map(model, max_memory={0:'38GiB',1:'38GiB',}, no_split_module_classes=['Block','LlamaDecoderLayer'])  
# input and output logits should be on same device
device_map["model.decoder.lm.lm_head"] = 0

model = load_checkpoint_and_dispatch(
    model, 
    'local/path/to/hf/version/Emu2/model',
    device_map=device_map).eval()

# `[<IMG_PLH>]` is the image placeholder which will be replaced by image embeddings. 
# the number of `[<IMG_PLH>]` should be equal to the number of input images

query = '[<IMG_PLH>]Describe the image in details:' 
image = Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/blue_black_1_top_left.jpg?raw=true',stream=True).raw).convert('RGB')

inputs = model.build_input_ids(
    text=[query],
    tokenizer=tokenizer,
    image=[image]

)

with torch.no_grad():
     outputs = model.generate(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        image=inputs["image"].to(torch.bfloat16),
        max_new_tokens=64,
        length_penalty=-1)

output_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)

Interleaved image and text

from PIL import Image 
import requests
import torch 
from transformers import AutoModelForCausalLM, AutoTokenizer
from accelerate import init_empty_weights, infer_auto_device_map, load_checkpoint_and_dispatch

tokenizer = AutoTokenizer.from_pretrained("BAAI/Emu2")

with init_empty_weights():
     model = AutoModelForCausalLM.from_pretrained(
        "BAAI/Emu2",
        torch_dtype=torch.bfloat16,
        low_cpu_mem_usage=True,
        trust_remote_code=True)  

device_map = infer_auto_device_map(model, max_memory={0:'38GiB',1:'38GiB',}, no_split_module_classes=['Block','LlamaDecoderLayer'])  
# input and output logits should be on same device
device_map["model.decoder.lm.lm_head"] = 0

model = load_checkpoint_and_dispatch(
    model, 
    'local/path/to/hf/version/Emu2/model',
    device_map=device_map).eval()

# `[<IMG_PLH>]` is the image placeholder which will be replaced by image embeddings. 
# the number of `[<IMG_PLH>]` should be equal to the number of input images
query = "[<IMG_PLH>][red, white, 3, bottom left].[<IMG_PLH>][yellow, white, 2, top left].[<IMG_PLH>][green, black, 4, bottom right][<IMG_PLH>]"

images = [
    Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/red_white_3_bottom_left.jpg?raw=true',stream=True).raw).convert('RGB'),
    Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/yellow_white_2_top_right.jpg?raw=true',stream=True).raw).convert('RGB'),
    Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/green_black_4_bottom_right.jpg?raw=true',stream=True).raw).convert('RGB'),
    Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/blue_black_1_top_left.jpg?raw=true',stream=True).raw).convert('RGB'),
]

inputs = model.build_input_ids(
    text=[query],
    tokenizer=tokenizer,
    image=images

)

with torch.no_grad():
     outputs = model.generate(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        image=inputs["image"].to(torch.bfloat16),
        max_new_tokens=64,
        length_penalty=-1)

output_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
Quantization

Check quantization guidance at transformers

from PIL import Image 
import requests
import torch 
from transformers import AutoModelForCausalLM, AutoTokenizer


tokenizer = AutoTokenizer.from_pretrained("BAAI/Emu2")

model = AutoModelForCausalLM.from_pretrained(
    "BAAI/Emu2",
    load_in_4bit=True,
    trust_remote_code=True, 
    bnb_4bit_compute_dtype=torch.float16).eval()

query = '[<IMG_PLH>]Describe the image in details:' 
image = Image.open(requests.get('https://github.com/baaivision/Emu/Emu2/examples/blue_black_1_top_left.jpg?raw=true',stream=True).raw).convert('RGB')

inputs = model.build_input_ids(
    text=[query],
    tokenizer=tokenizer,
    image=[image]

)

with torch.no_grad():
     outputs = model.generate(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        image=inputs["image"].to(torch.float16), # should be torch.float16
        max_new_tokens=64,
        length_penalty=-1)

output_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
Citation

If you find Emu2 useful for your research and applications, please consider starring this repository and citing:

@article{Emu2,
    title={Generative Multimodal Models are In-Context Learners}, 
    author={Quan Sun and Yufeng Cui and Xiaosong Zhang and Fan Zhang and Qiying Yu and Zhengxiong Luo and Yueze Wang and Yongming Rao and Jingjing Liu and Tiejun Huang and Xinlong Wang},
    publisher={arXiv preprint arXiv:2312.13286},
    year={2023},
}

Runs of BAAI Emu2 on huggingface.co

102
Total runs
-2
24-hour runs
-25
3-day runs
8
7-day runs
38
30-day runs

More Information About Emu2 huggingface.co Model

Emu2 huggingface.co

Emu2 huggingface.co is an AI model on huggingface.co that provides Emu2's model effect (), which can be used instantly with this BAAI Emu2 model. huggingface.co supports a free trial of the Emu2 model, and also provides paid use of the Emu2. Support call Emu2 model through api, including Node.js, Python, http.

Emu2 huggingface.co Url

https://huggingface.co/BAAI/Emu2

BAAI Emu2 online free

Emu2 huggingface.co is an online trial and call api platform, which integrates Emu2's modeling effects, including api services, and provides a free online trial of Emu2, you can try Emu2 online for free by clicking the link below.

BAAI Emu2 online free url in huggingface.co:

https://huggingface.co/BAAI/Emu2

Emu2 install

Emu2 is an open source model from GitHub that offers a free installation service, and any user can find Emu2 on GitHub to install. At the same time, huggingface.co provides the effect of Emu2 install, users can directly use Emu2 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

Emu2 install url in huggingface.co:

https://huggingface.co/BAAI/Emu2

Url of Emu2

Emu2 huggingface.co Url

Provider of Emu2 huggingface.co

BAAI
ORGANIZATIONS

Other API from BAAI

huggingface.co

Total runs: 5.9M
Run Growth: 628.0K
Growth Rate: 10.69%
Updated: February 22 2024
huggingface.co

Total runs: 2.3M
Run Growth: -1.8M
Growth Rate: -75.18%
Updated: February 21 2024
huggingface.co

Total runs: 2.2M
Run Growth: -79.5K
Growth Rate: -3.66%
Updated: July 03 2024
huggingface.co

Total runs: 1.6M
Run Growth: -512.9K
Growth Rate: -31.42%
Updated: February 21 2024
huggingface.co

Total runs: 983.7K
Run Growth: 160.9K
Growth Rate: 16.95%
Updated: April 02 2024
huggingface.co

Total runs: 798.7K
Run Growth: 153.9K
Growth Rate: 19.41%
Updated: December 13 2023
huggingface.co

Total runs: 449.0K
Run Growth: -4.2K
Growth Rate: -0.94%
Updated: October 12 2023
huggingface.co

Total runs: 197.8K
Run Growth: 21.7K
Growth Rate: 10.99%
Updated: November 14 2023
huggingface.co

Total runs: 138.8K
Run Growth: 74.2K
Growth Rate: 53.10%
Updated: October 12 2023
huggingface.co

Total runs: 41.3K
Run Growth: -38.0K
Growth Rate: -106.96%
Updated: April 17 2024
huggingface.co

Total runs: 33.6K
Run Growth: 32.3K
Growth Rate: 96.05%
Updated: October 12 2023
huggingface.co

Total runs: 28.4K
Run Growth: 11.5K
Growth Rate: 40.34%
Updated: October 12 2023
huggingface.co

Total runs: 19.9K
Run Growth: -15.4K
Growth Rate: -74.67%
Updated: January 15 2025
huggingface.co

Total runs: 6.0K
Run Growth: 2.4K
Growth Rate: 37.66%
Updated: December 26 2022
huggingface.co

Total runs: 5.0K
Run Growth: 899
Growth Rate: 18.62%
Updated: September 21 2023
huggingface.co

Total runs: 4.9K
Run Growth: 148
Growth Rate: 3.08%
Updated: August 15 2024
huggingface.co

Total runs: 4.0K
Run Growth: -12.2K
Growth Rate: -313.51%
Updated: February 22 2024
huggingface.co

Total runs: 2.9K
Run Growth: -305
Growth Rate: -10.51%
Updated: October 12 2023
huggingface.co

Total runs: 2.7K
Run Growth: -11.8K
Growth Rate: -272.27%
Updated: October 23 2024
huggingface.co

Total runs: 2.6K
Run Growth: 1.9K
Growth Rate: 73.04%
Updated: September 18 2023
huggingface.co

Total runs: 2.4K
Run Growth: 520
Growth Rate: 22.33%
Updated: August 15 2024
huggingface.co

Total runs: 2.4K
Run Growth: 380
Growth Rate: 17.87%
Updated: February 07 2024
huggingface.co

Total runs: 2.0K
Run Growth: -188
Growth Rate: -9.21%
Updated: November 28 2024
huggingface.co

Total runs: 1.5K
Run Growth: -3.5K
Growth Rate: -136.57%
Updated: October 23 2024
huggingface.co

Total runs: 1.4K
Run Growth: -3.0K
Growth Rate: -174.67%
Updated: October 24 2024
huggingface.co

Total runs: 824
Run Growth: 260
Growth Rate: 30.48%
Updated: June 07 2024
huggingface.co

Total runs: 656
Run Growth: -9.9K
Growth Rate: -1869.68%
Updated: March 07 2024
huggingface.co

Total runs: 586
Run Growth: 14
Growth Rate: 2.48%
Updated: October 27 2023
huggingface.co

Total runs: 502
Run Growth: 0
Growth Rate: 0.00%
Updated: January 15 2025
huggingface.co

Total runs: 462
Run Growth: 129
Growth Rate: 29.05%
Updated: April 02 2024
huggingface.co

Total runs: 426
Run Growth: 0
Growth Rate: 0.00%
Updated: January 14 2025
huggingface.co

Total runs: 296
Run Growth: 288
Growth Rate: 97.30%
Updated: April 18 2023
huggingface.co

Total runs: 217
Run Growth: -48
Growth Rate: -22.43%
Updated: October 29 2023
huggingface.co

Total runs: 194
Run Growth: 75
Growth Rate: 36.23%
Updated: June 24 2024
huggingface.co

Total runs: 143
Run Growth: -239
Growth Rate: -147.53%
Updated: August 15 2024
huggingface.co

Total runs: 114
Run Growth: 0
Growth Rate: 0.00%
Updated: January 20 2025
huggingface.co

Total runs: 94
Run Growth: 50
Growth Rate: 53.19%
Updated: August 23 2023
huggingface.co

Total runs: 91
Run Growth: 58
Growth Rate: 63.74%
Updated: August 15 2024
huggingface.co

Total runs: 68
Run Growth: -276
Growth Rate: -394.29%
Updated: June 21 2024
huggingface.co

Total runs: 65
Run Growth: 0
Growth Rate: 0.00%
Updated: January 01 2025
huggingface.co

Total runs: 49
Run Growth: -22
Growth Rate: -44.90%
Updated: October 27 2023
huggingface.co

Total runs: 49
Run Growth: -57
Growth Rate: -114.00%
Updated: December 21 2023
huggingface.co

Total runs: 47
Run Growth: -10.2K
Growth Rate: -21691.49%
Updated: February 07 2024
huggingface.co

Total runs: 42
Run Growth: -10
Growth Rate: -23.81%
Updated: August 15 2024
huggingface.co

Total runs: 41
Run Growth: 9
Growth Rate: 21.95%
Updated: August 28 2024
huggingface.co

Total runs: 40
Run Growth: -261
Growth Rate: -606.98%
Updated: June 24 2024
huggingface.co

Total runs: 31
Run Growth: -171
Growth Rate: -551.61%
Updated: April 19 2024
huggingface.co

Total runs: 27
Run Growth: 15
Growth Rate: 53.57%
Updated: July 24 2023
huggingface.co

Total runs: 20
Run Growth: -57
Growth Rate: -271.43%
Updated: December 31 2022
huggingface.co

Total runs: 19
Run Growth: -103
Growth Rate: -490.48%
Updated: May 13 2024
huggingface.co

Total runs: 17
Run Growth: -20
Growth Rate: -111.11%
Updated: July 02 2024
huggingface.co

Total runs: 16
Run Growth: -15
Growth Rate: -88.24%
Updated: December 25 2023