Upload 15 files
Browse files- README.md +2 -0
- handler.py +82 -16
- requirements.txt +3 -2
README.md
CHANGED
|
@@ -23,6 +23,8 @@ This repository provides a custom handler for deploying the **PULSE-7B** ECG ana
|
|
| 23 |
|
| 24 |
**๐ Enhanced with DeepSeek Integration**: This handler automatically translates PULSE-7B's English medical analysis into patient-friendly Turkish commentary using DeepSeek AI, providing bilingual ECG interpretation for Turkish healthcare professionals and patients.
|
| 25 |
|
|
|
|
|
|
|
| 26 |
## ๐ Quick Start
|
| 27 |
|
| 28 |
### Prerequisites
|
|
|
|
| 23 |
|
| 24 |
**๐ Enhanced with DeepSeek Integration**: This handler automatically translates PULSE-7B's English medical analysis into patient-friendly Turkish commentary using DeepSeek AI, providing bilingual ECG interpretation for Turkish healthcare professionals and patients.
|
| 25 |
|
| 26 |
+
**โ ๏ธ Important**: PULSE-7B uses `llava_llama` architecture which requires development version of transformers. This is automatically handled in requirements.txt.
|
| 27 |
+
|
| 28 |
## ๐ Quick Start
|
| 29 |
|
| 30 |
### Prerequisites
|
handler.py
CHANGED
|
@@ -43,6 +43,20 @@ class EndpointHandler:
|
|
| 43 |
import sys
|
| 44 |
print(f"๐ง Python version: {sys.version}")
|
| 45 |
print(f"๐ง PyTorch version: {torch.__version__}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
print(f"๐ง CUDA available: {torch.cuda.is_available()}")
|
| 47 |
if torch.cuda.is_available():
|
| 48 |
print(f"๐ง CUDA device: {torch.cuda.get_device_name(0)}")
|
|
@@ -179,23 +193,75 @@ class EndpointHandler:
|
|
| 179 |
print("โ
Model loaded with custom architecture support!")
|
| 180 |
|
| 181 |
except Exception as e5:
|
| 182 |
-
print(f"
|
| 183 |
-
print(f"Error 1 (AutoModel): {e1}")
|
| 184 |
-
print(f"Error 2 (LLaVA): {e2}")
|
| 185 |
-
print(f"Error 3 (Pipeline): {e3}")
|
| 186 |
-
print(f"Error 4 (Manual): {e4}")
|
| 187 |
-
print(f"Error 5 (Custom): {e5}")
|
| 188 |
-
|
| 189 |
-
print("\n๐ก SOLUTION: Update transformers to latest version:")
|
| 190 |
-
print(" pip install --upgrade transformers")
|
| 191 |
-
print(" OR: pip install git+https://github.com/huggingface/transformers.git")
|
| 192 |
|
| 193 |
-
#
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
# Final status report
|
| 201 |
print("\n๐ Model Loading Status Report:")
|
|
|
|
| 43 |
import sys
|
| 44 |
print(f"๐ง Python version: {sys.version}")
|
| 45 |
print(f"๐ง PyTorch version: {torch.__version__}")
|
| 46 |
+
|
| 47 |
+
# Check transformers version
|
| 48 |
+
try:
|
| 49 |
+
import transformers
|
| 50 |
+
print(f"๐ง Transformers version: {transformers.__version__}")
|
| 51 |
+
|
| 52 |
+
# Check if it's a development version
|
| 53 |
+
if "dev" in transformers.__version__ or "git" in str(transformers.__version__):
|
| 54 |
+
print("โ
Using development version - llava_llama support expected")
|
| 55 |
+
else:
|
| 56 |
+
print("โ ๏ธ Using stable version - llava_llama support may not be available")
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"โ Error checking transformers version: {e}")
|
| 59 |
+
|
| 60 |
print(f"๐ง CUDA available: {torch.cuda.is_available()}")
|
| 61 |
if torch.cuda.is_available():
|
| 62 |
print(f"๐ง CUDA device: {torch.cuda.get_device_name(0)}")
|
|
|
|
| 193 |
print("โ
Model loaded with custom architecture support!")
|
| 194 |
|
| 195 |
except Exception as e5:
|
| 196 |
+
print(f"โ ๏ธ Custom approach also failed: {e5}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
+
# Ultra-final attempt: Try to use the model's own files
|
| 199 |
+
try:
|
| 200 |
+
print("๐ฆ Ultra-final attempt: Using model's custom implementation...")
|
| 201 |
+
|
| 202 |
+
# Force download and use model's own implementation
|
| 203 |
+
from transformers.utils import cached_file
|
| 204 |
+
import importlib.util
|
| 205 |
+
import os
|
| 206 |
+
|
| 207 |
+
# Try to get the modeling file from the model repo
|
| 208 |
+
modeling_file = cached_file("PULSE-ECG/PULSE-7B", "modeling_llava.py", _raise_exceptions_for_missing_entries=False)
|
| 209 |
+
|
| 210 |
+
if modeling_file and os.path.exists(modeling_file):
|
| 211 |
+
print(f"๐ง Found custom modeling file: {modeling_file}")
|
| 212 |
+
|
| 213 |
+
# Load the module
|
| 214 |
+
spec = importlib.util.spec_from_file_location("modeling_llava", modeling_file)
|
| 215 |
+
modeling_module = importlib.util.module_from_spec(spec)
|
| 216 |
+
spec.loader.exec_module(modeling_module)
|
| 217 |
+
|
| 218 |
+
# Try to find the main model class
|
| 219 |
+
if hasattr(modeling_module, 'LlavaLlamaForCausalLM'):
|
| 220 |
+
print("๐ง Using LlavaLlamaForCausalLM from custom implementation")
|
| 221 |
+
|
| 222 |
+
from transformers import AutoTokenizer
|
| 223 |
+
self.tokenizer = AutoTokenizer.from_pretrained("PULSE-ECG/PULSE-7B", trust_remote_code=True)
|
| 224 |
+
self.model = modeling_module.LlavaLlamaForCausalLM.from_pretrained(
|
| 225 |
+
"PULSE-ECG/PULSE-7B",
|
| 226 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 227 |
+
device_map="auto",
|
| 228 |
+
low_cpu_mem_usage=True,
|
| 229 |
+
trust_remote_code=True
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
# Fix padding token if missing
|
| 233 |
+
if self.tokenizer.pad_token is None:
|
| 234 |
+
self.tokenizer.pad_token = self.tokenizer.eos_token
|
| 235 |
+
self.tokenizer.pad_token_id = self.tokenizer.eos_token_id
|
| 236 |
+
|
| 237 |
+
self.model.eval()
|
| 238 |
+
self.use_pipeline = False
|
| 239 |
+
print("โ
Model loaded with custom implementation!")
|
| 240 |
+
else:
|
| 241 |
+
raise Exception("LlavaLlamaForCausalLM not found in custom modeling file")
|
| 242 |
+
else:
|
| 243 |
+
raise Exception("Custom modeling file not found")
|
| 244 |
+
|
| 245 |
+
except Exception as e6:
|
| 246 |
+
print(f"๐ All loading approaches failed!")
|
| 247 |
+
print(f"Error 1 (AutoModel): {e1}")
|
| 248 |
+
print(f"Error 2 (LLaVA): {e2}")
|
| 249 |
+
print(f"Error 3 (Pipeline): {e3}")
|
| 250 |
+
print(f"Error 4 (Manual): {e4}")
|
| 251 |
+
print(f"Error 5 (Custom): {e5}")
|
| 252 |
+
print(f"Error 6 (Ultra-Custom): {e6}")
|
| 253 |
+
|
| 254 |
+
print("\n๐ก SOLUTION: This model requires development transformers:")
|
| 255 |
+
print(" Requirements.txt should contain:")
|
| 256 |
+
print(" git+https://github.com/huggingface/transformers.git")
|
| 257 |
+
print("\n๐ Current status: Using fallback text-only mode")
|
| 258 |
+
|
| 259 |
+
# Complete failure - set everything to None
|
| 260 |
+
self.model = None
|
| 261 |
+
self.processor = None
|
| 262 |
+
self.tokenizer = None
|
| 263 |
+
self.pipe = None
|
| 264 |
+
self.use_pipeline = None
|
| 265 |
|
| 266 |
# Final status report
|
| 267 |
print("\n๐ Model Loading Status Report:")
|
requirements.txt
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
-
# Core ML dependencies - PULSE-7B requires
|
| 2 |
-
transformers
|
|
|
|
| 3 |
torch>=2.1.0
|
| 4 |
accelerate>=0.25.0
|
| 5 |
sentencepiece
|
|
|
|
| 1 |
+
# Core ML dependencies - PULSE-7B requires development transformers for llava_llama architecture
|
| 2 |
+
# Note: Stable transformers doesn't support llava_llama yet, using development version
|
| 3 |
+
git+https://github.com/huggingface/transformers.git
|
| 4 |
torch>=2.1.0
|
| 5 |
accelerate>=0.25.0
|
| 6 |
sentencepiece
|