PearlIsa commited on
Commit
dc409a3
·
verified ·
1 Parent(s): 98d76bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -11,6 +11,7 @@ from pathlib import Path
11
  from datetime import datetime
12
  from typing import List, Dict, Union, Tuple, Optional, Any
13
  from dataclasses import dataclass, field
 
14
 
15
  # Machine Learning and Deep Learning Libraries
16
  import torch
@@ -81,6 +82,24 @@ os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
81
  logging.basicConfig(level=logging.INFO)
82
  logger = logging.getLogger(__name__)
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  class ModelManager:
85
  """Handles model loading and resource management"""
86
 
 
11
  from datetime import datetime
12
  from typing import List, Dict, Union, Tuple, Optional, Any
13
  from dataclasses import dataclass, field
14
+ import zipfile
15
 
16
  # Machine Learning and Deep Learning Libraries
17
  import torch
 
82
  logging.basicConfig(level=logging.INFO)
83
  logger = logging.getLogger(__name__)
84
 
85
+ # Define the path for the zipped model
86
+ model_zip_path = "./checkpoint-500.zip"
87
+ extracted_model_dir = "./checkpoint-500"
88
+
89
+ # Unzip the file if it’s not already extracted
90
+ if not os.path.exists(extracted_model_dir):
91
+ with zipfile.ZipFile(model_zip_path, 'r') as zip_ref:
92
+ zip_ref.extractall(extracted_model_dir)
93
+
94
+ # Load the model from the extracted directory
95
+ self.model = AutoModelForCausalLM.from_pretrained(
96
+ extracted_model_dir,
97
+ device_map="auto",
98
+ load_in_8bit=True,
99
+ torch_dtype=torch.float16,
100
+ low_cpu_mem_usage=True
101
+ )
102
+
103
  class ModelManager:
104
  """Handles model loading and resource management"""
105