Spaces:
Sleeping
Sleeping
| import torch | |
| from unsloth import FastVisionModel | |
| from transformers import AutoProcessor | |
| import config | |
| def load_vision_model(): | |
| """ | |
| Loads the FastVisionModel and its adapter for inference. | |
| Returns: | |
| A tuple containing the loaded model and processor, or (None, None) on error. | |
| """ | |
| try: | |
| model, processor = FastVisionModel.from_pretrained( | |
| model_name=config.VISION_MODEL_NAME, | |
| max_seq_length=config.MAX_SEQ_LENGTH, | |
| load_in_4bit=True, | |
| dtype=None, | |
| ) | |
| FastVisionModel.for_inference(model) | |
| model.load_adapter(config.ADAPTER_PATH) | |
| print(f"β Vision model and adapter '{config.ADAPTER_PATH}' loaded successfully!") | |
| return model, processor | |
| except Exception as e: | |
| print(f"β CRITICAL ERROR during vision model loading: {e}") | |
| return None, None | |