Upload models/model_manager.py with huggingface_hub
Browse files- models/model_manager.py +12 -3
models/model_manager.py
CHANGED
|
@@ -2,13 +2,19 @@
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
import gc
|
| 5 |
-
import torch
|
| 6 |
from typing import Dict, List, Tuple, Optional, Any
|
| 7 |
from functools import lru_cache
|
| 8 |
from pathlib import Path
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
from .model_registry import get_model_info, get_all_models, BASE_MODELS
|
| 14 |
|
|
@@ -23,6 +29,9 @@ class ModelManager:
|
|
| 23 |
use_4bit: bool = True,
|
| 24 |
device_map: str = "auto",
|
| 25 |
):
|
|
|
|
|
|
|
|
|
|
| 26 |
self.base_path = Path(base_path) if base_path else Path(__file__).parent.parent.parent
|
| 27 |
self.max_cached_models = max_cached_models
|
| 28 |
self.use_4bit = use_4bit
|
|
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
import gc
|
|
|
|
| 5 |
from typing import Dict, List, Tuple, Optional, Any
|
| 6 |
from functools import lru_cache
|
| 7 |
from pathlib import Path
|
| 8 |
|
| 9 |
+
# Optional imports for when running with actual models
|
| 10 |
+
try:
|
| 11 |
+
import torch
|
| 12 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 13 |
+
from peft import PeftModel
|
| 14 |
+
TORCH_AVAILABLE = True
|
| 15 |
+
except ImportError:
|
| 16 |
+
TORCH_AVAILABLE = False
|
| 17 |
+
torch = None
|
| 18 |
|
| 19 |
from .model_registry import get_model_info, get_all_models, BASE_MODELS
|
| 20 |
|
|
|
|
| 29 |
use_4bit: bool = True,
|
| 30 |
device_map: str = "auto",
|
| 31 |
):
|
| 32 |
+
if not TORCH_AVAILABLE:
|
| 33 |
+
raise ImportError("torch, transformers, peft are required for ModelManager. Install with: pip install torch transformers peft")
|
| 34 |
+
|
| 35 |
self.base_path = Path(base_path) if base_path else Path(__file__).parent.parent.parent
|
| 36 |
self.max_cached_models = max_cached_models
|
| 37 |
self.use_4bit = use_4bit
|