Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -72,17 +72,70 @@ def download_and_load_model():
|
|
| 72 |
}
|
| 73 |
|
| 74 |
try:
|
| 75 |
-
#
|
| 76 |
model = MultimodalGemmaLightning.load_from_checkpoint(
|
| 77 |
checkpoint_path,
|
| 78 |
config=config,
|
| 79 |
strict=False,
|
| 80 |
map_location="cuda" if torch.cuda.is_available() else "cpu"
|
| 81 |
)
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
model.eval()
|
| 87 |
|
| 88 |
# Move to appropriate device
|
|
|
|
| 72 |
}
|
| 73 |
|
| 74 |
try:
|
| 75 |
+
# First try: Use the checkpoint's config if available
|
| 76 |
model = MultimodalGemmaLightning.load_from_checkpoint(
|
| 77 |
checkpoint_path,
|
| 78 |
config=config,
|
| 79 |
strict=False,
|
| 80 |
map_location="cuda" if torch.cuda.is_available() else "cpu"
|
| 81 |
)
|
| 82 |
+
print("✅ Loaded with checkpoint config")
|
| 83 |
+
except Exception as e1:
|
| 84 |
+
print(f"Failed with checkpoint config: {e1}")
|
| 85 |
+
try:
|
| 86 |
+
# Second try: Minimal config with no quantization
|
| 87 |
+
minimal_config = {
|
| 88 |
+
"model": {
|
| 89 |
+
"gemma_model_name": "microsoft/DialoGPT-small", # Even smaller model
|
| 90 |
+
"vision_model_name": "openai/clip-vit-base-patch32", # Smaller CLIP
|
| 91 |
+
"use_4bit": False, # No quantization
|
| 92 |
+
"projector_hidden_dim": 512,
|
| 93 |
+
"lora": {"r": 8, "alpha": 16, "dropout": 0.1, "target_modules": ["q_proj", "v_proj"]}
|
| 94 |
+
},
|
| 95 |
+
"special_tokens": {"image_token": "<image>"},
|
| 96 |
+
"training": {"projector_lr": 1e-3, "lora_lr": 1e-4}
|
| 97 |
+
}
|
| 98 |
+
model = MultimodalGemmaLightning.load_from_checkpoint(
|
| 99 |
+
checkpoint_path,
|
| 100 |
+
config=minimal_config,
|
| 101 |
+
strict=False,
|
| 102 |
+
map_location="cuda" if torch.cuda.is_available() else "cpu"
|
| 103 |
+
)
|
| 104 |
+
print("✅ Loaded with minimal config")
|
| 105 |
+
except Exception as e2:
|
| 106 |
+
print(f"Failed with minimal config: {e2}")
|
| 107 |
+
try:
|
| 108 |
+
# Third try: Direct state dict loading
|
| 109 |
+
print("Attempting direct state dict loading...")
|
| 110 |
+
# Create a dummy model just to get the structure
|
| 111 |
+
dummy_config = {
|
| 112 |
+
"model": {
|
| 113 |
+
"gemma_model_name": "microsoft/DialoGPT-small",
|
| 114 |
+
"vision_model_name": "openai/clip-vit-base-patch32",
|
| 115 |
+
"use_4bit": False,
|
| 116 |
+
"projector_hidden_dim": 512,
|
| 117 |
+
},
|
| 118 |
+
"special_tokens": {"image_token": "<image>"},
|
| 119 |
+
"training": {"projector_lr": 1e-3, "lora_lr": 1e-4}
|
| 120 |
+
}
|
| 121 |
+
model = MultimodalGemmaLightning(dummy_config)
|
| 122 |
+
|
| 123 |
+
# Load only compatible weights
|
| 124 |
+
checkpoint_state = checkpoint['state_dict']
|
| 125 |
+
model_state = model.state_dict()
|
| 126 |
+
|
| 127 |
+
# Filter and load compatible weights
|
| 128 |
+
compatible_weights = {}
|
| 129 |
+
for key, value in checkpoint_state.items():
|
| 130 |
+
if key in model_state and model_state[key].shape == value.shape:
|
| 131 |
+
compatible_weights[key] = value
|
| 132 |
+
|
| 133 |
+
model.load_state_dict(compatible_weights, strict=False)
|
| 134 |
+
print(f"✅ Loaded {len(compatible_weights)} compatible weights")
|
| 135 |
+
|
| 136 |
+
except Exception as e3:
|
| 137 |
+
print(f"All loading methods failed: {e3}")
|
| 138 |
+
return f"❌ Model loading failed - checkpoint incompatible. Last error: {str(e3)}"
|
| 139 |
model.eval()
|
| 140 |
|
| 141 |
# Move to appropriate device
|