Update README.md
Browse files
README.md
CHANGED
|
@@ -49,7 +49,7 @@ from processing_emu3 import Emu3Processor
|
|
| 49 |
|
| 50 |
# model path
|
| 51 |
EMU_HUB = "BAAI/Emu3-Chat"
|
| 52 |
-
VQ_HUB = "BAAI/Emu3-
|
| 53 |
|
| 54 |
# prepare model and processor
|
| 55 |
model = AutoModelForCausalLM.from_pretrained(
|
|
@@ -60,7 +60,7 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 60 |
trust_remote_code=True,
|
| 61 |
)
|
| 62 |
|
| 63 |
-
tokenizer = AutoTokenizer.from_pretrained(EMU_HUB, trust_remote_code=True)
|
| 64 |
image_processor = AutoImageProcessor.from_pretrained(VQ_HUB, trust_remote_code=True)
|
| 65 |
image_tokenizer = AutoModel.from_pretrained(VQ_HUB, device_map="cuda:0", trust_remote_code=True).eval()
|
| 66 |
processor = Emu3Processor(image_processor, image_tokenizer, tokenizer)
|
|
@@ -73,19 +73,23 @@ inputs = processor(
|
|
| 73 |
text=text,
|
| 74 |
image=image,
|
| 75 |
mode='U',
|
| 76 |
-
padding_side="left",
|
| 77 |
-
padding="longest",
|
| 78 |
return_tensors="pt",
|
|
|
|
| 79 |
)
|
| 80 |
|
| 81 |
# prepare hyper parameters
|
| 82 |
-
GENERATION_CONFIG = GenerationConfig(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# generate
|
| 85 |
outputs = model.generate(
|
| 86 |
inputs.input_ids.to("cuda:0"),
|
| 87 |
GENERATION_CONFIG,
|
| 88 |
-
|
| 89 |
)
|
| 90 |
|
| 91 |
outputs = outputs[:, inputs.input_ids.shape[-1]:]
|
|
|
|
| 49 |
|
| 50 |
# model path
|
| 51 |
EMU_HUB = "BAAI/Emu3-Chat"
|
| 52 |
+
VQ_HUB = "BAAI/Emu3-VisionTokenier"
|
| 53 |
|
| 54 |
# prepare model and processor
|
| 55 |
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
| 60 |
trust_remote_code=True,
|
| 61 |
)
|
| 62 |
|
| 63 |
+
tokenizer = AutoTokenizer.from_pretrained(EMU_HUB, trust_remote_code=True, padding_side="left")
|
| 64 |
image_processor = AutoImageProcessor.from_pretrained(VQ_HUB, trust_remote_code=True)
|
| 65 |
image_tokenizer = AutoModel.from_pretrained(VQ_HUB, device_map="cuda:0", trust_remote_code=True).eval()
|
| 66 |
processor = Emu3Processor(image_processor, image_tokenizer, tokenizer)
|
|
|
|
| 73 |
text=text,
|
| 74 |
image=image,
|
| 75 |
mode='U',
|
|
|
|
|
|
|
| 76 |
return_tensors="pt",
|
| 77 |
+
padding="longest",
|
| 78 |
)
|
| 79 |
|
| 80 |
# prepare hyper parameters
|
| 81 |
+
GENERATION_CONFIG = GenerationConfig(
|
| 82 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 83 |
+
bos_token_id=tokenizer.bos_token_id,
|
| 84 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 85 |
+
max_new_tokens=1024,
|
| 86 |
+
)
|
| 87 |
|
| 88 |
# generate
|
| 89 |
outputs = model.generate(
|
| 90 |
inputs.input_ids.to("cuda:0"),
|
| 91 |
GENERATION_CONFIG,
|
| 92 |
+
attention_mask=pos_inputs.attention_mask.to("cuda:0"),
|
| 93 |
)
|
| 94 |
|
| 95 |
outputs = outputs[:, inputs.input_ids.shape[-1]:]
|