Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions MultiLLM.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,21 @@


def task(model_name,prompt,taskid = None, convid = None):
model = MultiLLM.model_registry[model_name]
model = model_registry[model_name]
if not model:
return
response, is_code = model.get_response(prompt,taskid, convid)
return model_name, response, is_code


# initialize worker processes
def init_worker(data):
# declare scope of a new global variable
global model_registry
# store argument in the global variable for this process
model_registry = data


# MultiLLM class
class MultiLLM(object):

Expand All @@ -72,7 +81,7 @@ def run(self, prompt, action_chain, rank_chain, taskid=None, convid = None):
responses = {}
args = [(model_name,prompt,taskid, convid) for model_name in self.model_names]
is_code_list = []
with multiprocessing.Pool() as pool:
with multiprocessing.Pool(initializer=init_worker, initargs=(MultiLLM.model_registry,)) as pool:
for model_name,response, is_code in pool.starmap(task,args):
responses[model_name] = response
is_code_list.append(is_code)
Expand Down