lodrick-the-lafted
commited on
Commit
•
c4b3afb
1
Parent(s):
541bd3e
Update README.md
Browse files
README.md
CHANGED
@@ -1,124 +1,12 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
|
|
|
|
3 |
library_name: transformers
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
<h3></h3>
|
9 |
|
10 |
-
[Emu3 Team, BAAI](https://www.baai.ac.cn/english.html)
|
11 |
-
|
12 |
-
| [Project Page](https://emu.baai.ac.cn) | [Paper](https://baai-solution.ks3-cn-beijing.ksyuncs.com/emu3/Emu3-tech-report.pdf?KSSAccessKeyId=AKLTgew6Kdg6RsK92QSfB2KLA&Expires=2591406552&Signature=6BvwfLVqvfww26Bhwvk3mG0FrL8%3D) | [🤗HF Models](https://huggingface.co/collections/BAAI/emu3-66f4e64f70850ff358a2e60f) | [github](https://github.com/baaivision/Emu3)
|
13 |
-
|
|
14 |
-
|
15 |
-
|
16 |
-
</div>
|
17 |
-
|
18 |
-
<div align='center'>
|
19 |
-
<img src="https://github.com/baaivision/Emu3/blob/main/assets/arch.png?raw=True" class="interpolation-image" alt="arch." height="80%" width="70%" />
|
20 |
-
</div>
|
21 |
-
|
22 |
-
We introduce **Emu3**, a new suite of state-of-the-art multimodal models trained solely with **<i>next-token prediction</i>**! By tokenizing images, text, and videos into a discrete space, we train a single transformer from scratch on a mixture of multimodal sequences.
|
23 |
-
|
24 |
-
### Emu3 excels in both generation and perception
|
25 |
-
**Emu3** outperforms several well-established task-specific models in both generation and perception tasks, surpassing flagship open models such as SDXL, LLaVA-1.6 and OpenSora-1.2, while eliminating the need for diffusion or compositional architectures.
|
26 |
-
|
27 |
-
<div align='center'>
|
28 |
-
<img src="https://github.com/baaivision/Emu3/blob/main/assets/comparison.png?raw=True" class="interpolation-image" alt="comparison." height="80%" width="80%" />
|
29 |
-
</div>
|
30 |
-
|
31 |
-
### Highlights
|
32 |
-
|
33 |
-
- **Emu3** is capable of generating high-quality images following the text input, by simply predicting the next vision token. The model naturally supports flexible resolutions and styles.
|
34 |
-
- **Emu3** shows strong vision-language understanding capabilities to see the physical world and provides coherent text responses. Notably, this capability is achieved without depending on a CLIP and a pretrained LLM.
|
35 |
-
- **Emu3** simply generates a video causally by predicting the next token in a video sequence, unlike the video diffusion model as in Sora. With a video in context, Emu3 can also naturally extend the video and predict what will happen next.
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
#### Quickstart
|
40 |
-
|
41 |
-
```python
|
42 |
-
from PIL import Image
|
43 |
-
from transformers import AutoTokenizer, AutoModel, AutoImageProcessor, AutoModelForCausalLM
|
44 |
-
from transformers.generation.configuration_utils import GenerationConfig
|
45 |
-
from transformers.generation import LogitsProcessorList, PrefixConstrainedLogitsProcessor, UnbatchedClassifierFreeGuidanceLogitsProcessor
|
46 |
-
import torch
|
47 |
-
|
48 |
-
import sys
|
49 |
-
sys.path.append(PATH_TO_BAAI_Emu3-Gen_MODEL)
|
50 |
-
from processing_emu3 import Emu3Processor
|
51 |
-
|
52 |
-
# model path
|
53 |
-
EMU_HUB = "BAAI/Emu3-Gen"
|
54 |
-
VQ_HUB = "BAAI/Emu3-VisionTokenizer"
|
55 |
-
|
56 |
-
# prepare model and processor
|
57 |
-
model = AutoModelForCausalLM.from_pretrained(
|
58 |
-
EMU_HUB,
|
59 |
-
device_map="cuda:0",
|
60 |
-
torch_dtype=torch.bfloat16,
|
61 |
-
attn_implementation="flash_attention_2",
|
62 |
-
trust_remote_code=True,
|
63 |
-
)
|
64 |
-
|
65 |
-
tokenizer = AutoTokenizer.from_pretrained(EMU_HUB, trust_remote_code=True)
|
66 |
-
image_processor = AutoImageProcessor.from_pretrained(VQ_HUB, trust_remote_code=True)
|
67 |
-
image_tokenizer = AutoModel.from_pretrained(VQ_HUB, device_map="cuda:0", trust_remote_code=True).eval()
|
68 |
-
processor = Emu3Processor(image_processor, image_tokenizer, tokenizer)
|
69 |
-
|
70 |
-
# prepare input
|
71 |
-
POSITIVE_PROMPT = " masterpiece, film grained, best quality."
|
72 |
-
NEGATIVE_PROMPT = "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry."
|
73 |
-
|
74 |
-
classifier_free_guidance = 3.0
|
75 |
-
prompt = "a portrait of young girl."
|
76 |
-
prompt += POSITIVE_PROMPT
|
77 |
-
|
78 |
-
kwargs = dict(
|
79 |
-
mode='G',
|
80 |
-
ratio="1:1",
|
81 |
-
image_area=model.config.image_area,
|
82 |
-
return_tensors="pt",
|
83 |
-
)
|
84 |
-
pos_inputs = processor(text=prompt, **kwargs)
|
85 |
-
neg_inputs = processor(text=NEGATIVE_PROMPT, **kwargs)
|
86 |
-
|
87 |
-
# prepare hyper parameters
|
88 |
-
GENERATION_CONFIG = GenerationConfig(
|
89 |
-
use_cache=True,
|
90 |
-
eos_token_id=model.config.eos_token_id,
|
91 |
-
pad_token_id=model.config.pad_token_id,
|
92 |
-
max_new_tokens=40960,
|
93 |
-
do_sample=True,
|
94 |
-
top_k=2048,
|
95 |
-
)
|
96 |
-
|
97 |
-
h, w = pos_inputs.image_size[0]
|
98 |
-
constrained_fn = processor.build_prefix_constrained_fn(h, w)
|
99 |
-
logits_processor = LogitsProcessorList([
|
100 |
-
UnbatchedClassifierFreeGuidanceLogitsProcessor(
|
101 |
-
classifier_free_guidance,
|
102 |
-
model,
|
103 |
-
unconditional_ids=neg_inputs.input_ids.to("cuda:0"),
|
104 |
-
),
|
105 |
-
PrefixConstrainedLogitsProcessor(
|
106 |
-
constrained_fn ,
|
107 |
-
num_beams=1,
|
108 |
-
),
|
109 |
-
])
|
110 |
-
|
111 |
-
# generate
|
112 |
-
outputs = model.generate(
|
113 |
-
pos_inputs.input_ids.to("cuda:0"),
|
114 |
-
GENERATION_CONFIG,
|
115 |
-
logits_processor=logits_processor
|
116 |
-
)
|
117 |
-
|
118 |
-
mm_list = processor.decode(outputs[0])
|
119 |
-
for idx, im in enumerate(mm_list):
|
120 |
-
if not isinstance(im, Image.Image):
|
121 |
-
continue
|
122 |
-
im.save(f"result_{idx}.png")
|
123 |
-
|
124 |
-
```
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
base_model:
|
4 |
+
- BAAI/Emu3-Gen
|
5 |
library_name: transformers
|
6 |
+
tags:
|
7 |
+
- merge
|
8 |
---
|
9 |
|
10 |
+
This is an interpolated upscale of [BAAI/Emu3-Gen](https://huggingface.co/BAAI/Emu3-Gen) from 8B to 11.5B.
|
11 |
+
For each layer in [7,8,9,10,11,12,13,14,15,16,22,23,24], the weights were lerp'd between the previous layer and the current and inserted between the two.
|
|
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|