Oleg Shulyakov commited on
Commit
eb0c0ed
·
1 Parent(s): c6c7289

Extract timeouts

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -76,6 +76,12 @@ class HuggingFaceModelProcessor:
76
  OUTPUT_FOLDER = "./outputs"
77
  CALIBRATION_FILE = "calibration_data_v5_rc.txt"
78
 
 
 
 
 
 
 
79
  def __init__(self):
80
  self.SPACE_ID = os.environ.get("SPACE_ID", "")
81
  self.SPACE_URL = f"https://{self.SPACE_ID.replace('/', '-')}.hf.space/" if self.SPACE_ID else "http://localhost:7860/"
@@ -161,12 +167,12 @@ class HuggingFaceModelProcessor:
161
 
162
  process = subprocess.Popen(imatrix_command, shell=False, stderr=subprocess.STDOUT)
163
  try:
164
- process.wait(timeout=600)
165
  except subprocess.TimeoutExpired:
166
  print("Imatrix computation timed out. Sending SIGINT to allow graceful termination...")
167
  process.send_signal(signal.SIGINT)
168
  try:
169
- process.wait(timeout=5)
170
  except subprocess.TimeoutExpired:
171
  print("Imatrix proc still didn't term. Forcefully terminating process...")
172
  process.kill()
@@ -198,12 +204,12 @@ class HuggingFaceModelProcessor:
198
  print(f"Split command: {split_cmd}")
199
  process = subprocess.Popen(split_cmd, shell=False, stderr=subprocess.STDOUT)
200
  try:
201
- process.wait(timeout=300)
202
  except subprocess.TimeoutExpired:
203
  print("Splitting timed out. Sending SIGINT to allow graceful termination...")
204
  process.send_signal(signal.SIGINT)
205
  try:
206
- process.wait(timeout=5)
207
  except subprocess.TimeoutExpired:
208
  print("Splitting timed out. Killing process...")
209
  process.kill()
@@ -290,12 +296,12 @@ class HuggingFaceModelProcessor:
290
  ]
291
  process = subprocess.Popen(convert_command, shell=False, stderr=subprocess.STDOUT)
292
  try:
293
- process.wait(timeout=600)
294
  except subprocess.TimeoutExpired:
295
  print("Conversion timed out. Sending SIGINT to allow graceful termination...")
296
  process.send_signal(signal.SIGINT)
297
  try:
298
- process.wait(timeout=5)
299
  except subprocess.TimeoutExpired:
300
  print("Conversion timed out. Killing process...")
301
  process.kill()
@@ -341,12 +347,12 @@ class HuggingFaceModelProcessor:
341
  # Use Popen for quantization
342
  process = subprocess.Popen(quantize_cmd, shell=False, stderr=subprocess.STDOUT)
343
  try:
344
- process.wait(timeout=3600)
345
  except subprocess.TimeoutExpired:
346
  print("Quantization timed out. Sending SIGINT to allow graceful termination...")
347
  process.send_signal(signal.SIGINT)
348
  try:
349
- process.wait(timeout=5)
350
  except subprocess.TimeoutExpired:
351
  print("Quantization timed out. Killing process...")
352
  process.kill()
 
76
  OUTPUT_FOLDER = "./outputs"
77
  CALIBRATION_FILE = "calibration_data_v5_rc.txt"
78
 
79
+ QUANTIZE_TIMEOUT=86400
80
+ HF_TO_GGUF_TIMEOUT=3600
81
+ IMATRIX_TIMEOUT=86400
82
+ SPLIT_TIMEOUT=3600
83
+ KILL_TIMEOUT=5
84
+
85
  def __init__(self):
86
  self.SPACE_ID = os.environ.get("SPACE_ID", "")
87
  self.SPACE_URL = f"https://{self.SPACE_ID.replace('/', '-')}.hf.space/" if self.SPACE_ID else "http://localhost:7860/"
 
167
 
168
  process = subprocess.Popen(imatrix_command, shell=False, stderr=subprocess.STDOUT)
169
  try:
170
+ process.wait(timeout=self.IMATRIX_TIMEOUT)
171
  except subprocess.TimeoutExpired:
172
  print("Imatrix computation timed out. Sending SIGINT to allow graceful termination...")
173
  process.send_signal(signal.SIGINT)
174
  try:
175
+ process.wait(timeout=self.KILL_TIMEOUT)
176
  except subprocess.TimeoutExpired:
177
  print("Imatrix proc still didn't term. Forcefully terminating process...")
178
  process.kill()
 
204
  print(f"Split command: {split_cmd}")
205
  process = subprocess.Popen(split_cmd, shell=False, stderr=subprocess.STDOUT)
206
  try:
207
+ process.wait(timeout=self.SPLIT_TIMEOUT)
208
  except subprocess.TimeoutExpired:
209
  print("Splitting timed out. Sending SIGINT to allow graceful termination...")
210
  process.send_signal(signal.SIGINT)
211
  try:
212
+ process.wait(timeout=self.KILL_TIMEOUT)
213
  except subprocess.TimeoutExpired:
214
  print("Splitting timed out. Killing process...")
215
  process.kill()
 
296
  ]
297
  process = subprocess.Popen(convert_command, shell=False, stderr=subprocess.STDOUT)
298
  try:
299
+ process.wait(timeout=self.HF_TO_GGUF_TIMEOUT)
300
  except subprocess.TimeoutExpired:
301
  print("Conversion timed out. Sending SIGINT to allow graceful termination...")
302
  process.send_signal(signal.SIGINT)
303
  try:
304
+ process.wait(timeout=self.KILL_TIMEOUT)
305
  except subprocess.TimeoutExpired:
306
  print("Conversion timed out. Killing process...")
307
  process.kill()
 
347
  # Use Popen for quantization
348
  process = subprocess.Popen(quantize_cmd, shell=False, stderr=subprocess.STDOUT)
349
  try:
350
+ process.wait(timeout=self.QUANTIZE_TIMEOUT)
351
  except subprocess.TimeoutExpired:
352
  print("Quantization timed out. Sending SIGINT to allow graceful termination...")
353
  process.send_signal(signal.SIGINT)
354
  try:
355
+ process.wait(timeout=self.KILL_TIMEOUT)
356
  except subprocess.TimeoutExpired:
357
  print("Quantization timed out. Killing process...")
358
  process.kill()