Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
else:
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 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}]}]
|