arjunanand13 commited on
Commit
e2629d8
·
verified ·
1 Parent(s): 073252a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -27
app.py CHANGED
@@ -11,34 +11,35 @@ USE_LORA = False
11
  USE_QLORA = True
12
 
13
  processor = AutoProcessor.from_pretrained("HuggingFaceM4/idefics2-8b", do_image_splitting=False)
 
14
 
15
- if USE_QLORA or USE_LORA:
16
- lora_config = LoraConfig(
17
- r=8,
18
- lora_alpha=8,
19
- lora_dropout=0.1,
20
- target_modules='.*(text_model|modality_projection|perceiver_resampler).*(down_proj|gate_proj|up_proj|k_proj|q_proj|v_proj|o_proj).*',
21
- use_dora=False if USE_QLORA else True,
22
- init_lora_weights="gaussian"
23
- )
24
- bnb_config = BitsAndBytesConfig(
25
- load_in_4bit=True,
26
- bnb_4bit_quant_type="nf4",
27
- bnb_4bit_compute_dtype=torch.float16
28
- ) if USE_QLORA else None
29
- model = Idefics2ForConditionalGeneration.from_pretrained(
30
- "HuggingFaceM4/idefics2-8b",
31
- torch_dtype=torch.float16,
32
- quantization_config=bnb_config,
33
- )
34
- model.add_adapter(lora_config)
35
- model.enable_adapters()
36
- else:
37
- model = Idefics2ForConditionalGeneration.from_pretrained(
38
- "HuggingFaceM4/idefics2-8b",
39
- torch_dtype=torch.float16,
40
- _attn_implementation="flash_attention_2"
41
- ).to(DEVICE)
42
 
43
  def model_inference(image, text):
44
  resulting_messages = [{"role": "user", "content": [{"type": "image"}] + [{"type": "text", "text": text}]}]
 
11
  USE_QLORA = True
12
 
13
  processor = AutoProcessor.from_pretrained("HuggingFaceM4/idefics2-8b", do_image_splitting=False)
14
+ model = AutoModelForPreTraining.from_pretrained("HuggingFaceM4/idefics2-8b")
15
 
16
+ # if USE_QLORA or USE_LORA:
17
+ # lora_config = LoraConfig(
18
+ # r=8,
19
+ # lora_alpha=8,
20
+ # lora_dropout=0.1,
21
+ # target_modules='.*(text_model|modality_projection|perceiver_resampler).*(down_proj|gate_proj|up_proj|k_proj|q_proj|v_proj|o_proj).*',
22
+ # use_dora=False if USE_QLORA else True,
23
+ # init_lora_weights="gaussian"
24
+ # )
25
+ # bnb_config = BitsAndBytesConfig(
26
+ # load_in_4bit=True,
27
+ # bnb_4bit_quant_type="nf4",
28
+ # bnb_4bit_compute_dtype=torch.float16
29
+ # ) if USE_QLORA else None
30
+ # model = Idefics2ForConditionalGeneration.from_pretrained(
31
+ # "HuggingFaceM4/idefics2-8b",
32
+ # torch_dtype=torch.float16,
33
+ # quantization_config=bnb_config,
34
+ # )
35
+ # model.add_adapter(lora_config)
36
+ # model.enable_adapters()
37
+ # else:
38
+ # model = Idefics2ForConditionalGeneration.from_pretrained(
39
+ # "HuggingFaceM4/idefics2-8b",
40
+ # torch_dtype=torch.float16,
41
+ # _attn_implementation="flash_attention_2"
42
+ # ).to(DEVICE)
43
 
44
  def model_inference(image, text):
45
  resulting_messages = [{"role": "user", "content": [{"type": "image"}] + [{"type": "text", "text": text}]}]