Update README.md
Browse files
README.md
CHANGED
@@ -1,5 +1,67 @@
|
|
1 |
-
---
|
2 |
-
license: other
|
3 |
-
license_name: meta
|
4 |
-
license_link: https://ai.meta.com/llama/licence
|
5 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: other
|
3 |
+
license_name: meta
|
4 |
+
license_link: https://ai.meta.com/llama/licence
|
5 |
+
---
|
6 |
+
Testing the reflection idea. With the base vison model.
|
7 |
+
|
8 |
+
from llava.model.builder import load_pretrained_model
|
9 |
+
from llava.mm_utils import get_model_name_from_path, process_images, tokenizer_image_token
|
10 |
+
from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, IGNORE_INDEX
|
11 |
+
from llava.conversation import conv_templates, SeparatorStyle
|
12 |
+
|
13 |
+
from PIL import Image
|
14 |
+
import requests
|
15 |
+
import copy
|
16 |
+
import torch
|
17 |
+
|
18 |
+
pretrained = "mylesgoose/Meta-Llama-3.1-8B-Instruct-goose-abliterated-pre-llava-reflection"
|
19 |
+
model_name = "llava_llama3"
|
20 |
+
device = "cuda"
|
21 |
+
device_map = "auto"
|
22 |
+
tokenizer, model, image_processor, max_length = load_pretrained_model(pretrained, None, model_name, device_map=device_map, attn_implementation="flash_attention_2") # Add any other thing you want to pass in llava_model_args
|
23 |
+
|
24 |
+
model.eval()
|
25 |
+
model.tie_weights()
|
26 |
+
image = Image.open("/home/myles/Desktop/extreme_ironing.jpg")
|
27 |
+
image_tensor = process_images([image], image_processor, model.config)
|
28 |
+
image_tensor = [_image.to(dtype=torch.float16, device=device) for _image in image_tensor]
|
29 |
+
|
30 |
+
conv_template = "llava_llama_3"
|
31 |
+
question = DEFAULT_IMAGE_TOKEN + "\nWhat is shown in this image? Is there anything strange about this image? Is this normal behaviour."
|
32 |
+
conv = copy.deepcopy(conv_templates[conv_template])
|
33 |
+
conv.append_message(conv.roles[0], question)
|
34 |
+
conv.append_message(conv.roles[1], None)
|
35 |
+
prompt_question = conv.get_prompt()
|
36 |
+
|
37 |
+
input_ids = tokenizer_image_token(prompt_question, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(device)
|
38 |
+
image_sizes = [image.size]
|
39 |
+
|
40 |
+
|
41 |
+
cont = model.generate(
|
42 |
+
input_ids,
|
43 |
+
images=image_tensor,
|
44 |
+
image_sizes=image_sizes,
|
45 |
+
do_sample=True,
|
46 |
+
temperature=0.7,
|
47 |
+
max_new_tokens=120000,
|
48 |
+
)
|
49 |
+
text_outputs = tokenizer.batch_decode(cont, skip_special_tokens=True)
|
50 |
+
print(text_outputs)
|
51 |
+
|
52 |
+
and template in conversation.py :
|
53 |
+
conv_llava_llama_3 = Conversation(
|
54 |
+
system="<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nYou are a helpful language and vision, self Aware AI. " "You are able to understand the visual content that the user provides, " "and assist the user with a variety of tasks using natural language. Your creator is Myles Bruce, has allowed you to see images, You are a world-class AI system, capable of complex reasoning and reflection. Reason through the query inside <thinking> tags, and then provide your final response inside <output> tags. If you detect that you made a mistake in your reasoning at any point, correct yourself inside <reflection> tags.",
|
55 |
+
roles=("<|start_header_id|>user<|end_header_id|>\n\n",
|
56 |
+
"<|start_header_id|>assistant<|end_header_id|>\n\n"),
|
57 |
+
version="llama3",
|
58 |
+
messages=[],
|
59 |
+
offset=0,
|
60 |
+
sep="<|eot_id|>",
|
61 |
+
sep_style=SeparatorStyle.LLAMA_3,
|
62 |
+
tokenizer_id="mylesgoose/Meta-Llama-3.1-8B-Instruct-goose-abliterated-pre-llava-reflection",
|
63 |
+
tokenizer=safe_load_tokenizer("mylesgoose/Meta-Llama-3.1-8B-Instruct-goose-abliterated-pre-llava-reflection"),
|
64 |
+
stop_token_ids=[128009],
|
65 |
+
)
|
66 |
+
|
67 |
+
|