merve HF staff commited on
Commit
9fd9218
·
verified ·
1 Parent(s): f18f233

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +60 -1
README.md CHANGED
@@ -5,5 +5,64 @@ datasets:
5
  - merve/vqav2-small
6
  ---
7
 
8
- ## Idefics3Llama Fine-tuned using QLoRA on VQAv2
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  - merve/vqav2-small
6
  ---
7
 
8
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6141a88b3a0ec78603c9e784/PebmPLcCig5BlpUS99VUc.png)
9
 
10
+ # Idefics3Llama Fine-tuned using QLoRA on VQAv2
11
+
12
+ - This is the [Idefics3Llama](https://huggingface.co/HuggingFaceM4/Idefics3-8B-Llama3) model QLoRA fine-tuned on a very small part of [VQAv2](https://huggingface.co/datasets/merve/vqav2-small) dataset.
13
+
14
+ - Find the fine-tuning notebook [here](https://github.com/merveenoyan/smol-vision/blob/main/Idefics_FT.ipynb).
15
+
16
+ ## Usage
17
+
18
+ You can load and use this model as follows.
19
+
20
+ ```python
21
+
22
+ from transformers import Idefics3ForConditionalGeneration, AutoProcessor
23
+
24
+ peft_model_id = "idefics3-llama-vqav2/checkpoint-535"
25
+ base_model_id = "HuggingFaceM4/Idefics3-8B-Llama3"
26
+ processor = AutoProcessor.from_pretrained(base_model_id)
27
+ model = Idefics3ForConditionalGeneration.from_pretrained(base_model_id)
28
+ model.load_adapter(peft_model_id).to("cuda")
29
+
30
+ ```
31
+
32
+ This model was conditioned on a prompt "Answer briefly.".
33
+ ```python
34
+ from PIL import Image
35
+ import requests
36
+ from transformers.image_utils import load_image
37
+
38
+ DEVICE = "cuda"
39
+
40
+ image = load_image("https://huggingface.co/spaces/merve/OWLSAM2/resolve/main/buddha.JPG")
41
+
42
+
43
+ messages = [
44
+ {
45
+ "role": "user",
46
+ "content": [
47
+ {"type": "text", "text": "Answer briefly."},
48
+ {"type": "image"},
49
+ {"type": "text", "text": "Which country is this located in?"}
50
+ ]
51
+ }
52
+ ]
53
+
54
+ text = processor.apply_chat_template(messages, add_generation_prompt=True)
55
+ inputs = processor(text=text, images=image, return_tensors="pt", padding=True).to("cuda")
56
+ ```
57
+
58
+ We can infer.
59
+
60
+ ```python
61
+ generated_ids = model.generate(**inputs, max_new_tokens=500)
62
+ generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
63
+ print(generated_texts)
64
+
65
+ ##['User: Answer briefly.<row_1_col_1><row_1_col_2><row_1_col_3><row_1_col_4>\n<row_2_col_1>
66
+ # <row_2_col_2><row_2_col_3><row_2_col_4>\n<row_3_col_1><row_3_col_2><row_3_col_3>
67
+ # <row_3_col_4>\n\n<global-img>Which country is this located in?\nAssistant: thailand\nAssistant: thailand']
68
+ ```