Skip to content

Commit

Permalink
extra logs
Browse files Browse the repository at this point in the history
  • Loading branch information
andreea-popescu-reef committed Jan 7, 2025
1 parent 02dfede commit 2970223
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/compute_horde_prompt_solver/prompt_solver.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import abc
import time
import hashlib
import json
import multiprocessing as mp
import pathlib
import queue
import random
import string
import logging
from typing import List, Dict

import torch
Expand All @@ -18,7 +20,9 @@

from .config import Config

TIMEOUT = 5 * 60
logger = logging.getLogger(__name__)

TIMEOUT = 20 * 60


class BaseLLMProvider(abc.ABC):
Expand Down Expand Up @@ -98,10 +102,18 @@ def execute_job():
try:
from flask import request

seed_raw = request.json.get("seed")
logger.info(f"Triggered executr job with: {request.json=}")
if request.json is None:
return ({"error": "No json data provided"},)
seed_raw = request.json.get("seed", None)
if seed_raw is None:
return ({"error": "No seed provided"},)
seed = int(seed_raw)
logger.debug(f"put seed {seed} in seed_queue")
seed_queue.put(seed)
result = result_queue.get(timeout=TIMEOUT)
logger.debug("fetched result from result_queue")

return jsonify(result)
finally:
# The seed_queue.put(seed) can fail (request not having int seed etc.),
Expand Down Expand Up @@ -196,7 +208,9 @@ def run(self):
self.start_server_event.set()

try:
logger.debug("waiting to fetch from seed_queue")
seed = self.seed_queue.get(block=True, timeout=TIMEOUT)
logger.debug(f"fetched seed {seed}")
except queue.Empty:
seed = None

Expand All @@ -206,9 +220,12 @@ def run(self):
sampling_params = self.get_sampling_params(seed)

try:
logger.debug("running inference")
for input_file in self.config.input_files:
self.process_file(input_file, sampling_params)
logger.debug("put result in result_queue")
self.result_queue.put(self.response_hashes)
self.ready_to_terminate_event.wait(timeout=TIMEOUT)
time.sleep(2)
finally:
process.terminate()

0 comments on commit 2970223

Please sign in to comment.