import random import gradio as gr import openai import os openai.api_key = os.environ.get("open_ai_key") prompt = [''' You are a ''', ''' machine learning developer, trying to debug this code: StackTrace: Traceback (most recent call last): File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/process.py”, line 258, in _bootstrap self.run() File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/process.py”, line 93, in run self._target(*self._args, **self._kwargs) File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 61, in _worker_loop data_queue.put((idx, samples)) File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/queues.py”, line 341, in put File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/reduction.py”, line 51, in dumps File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/site-packages/torch/multiprocessing/reductions.py”, line 121, in reduce_storage RuntimeError: unable to open shared memory object in read-write mode at /opt/conda/conda-bld/pytorch_1525909934016/work/aten/src/TH/THAllocator.c:342 During handling of the above exception, another exception occurred: Traceback (most recent call last): File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/util.py”, line 262, in _run_finalizers File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/util.py”, line 186, in call File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/shutil.py”, line 476, in rmtree File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/shutil.py”, line 474, in rmtree OSError: [Errno 24] Too many open files: ‘/tmp/pymp-sgew4xdn’ Process Process-1: Traceback (most recent call last): File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/process.py”, line 258, in _bootstrap self.run() File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/process.py”, line 93, in run self._target(*self._args, **self._kwargs) File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 61, in _worker_loop data_queue.put((idx, samples)) File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/queues.py”, line 341, in put File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/reduction.py”, line 51, in dumps File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/site-packages/torch/multiprocessing/reductions.py”, line 121, in reduce_storage RuntimeError: unable to open shared memory object in read-write mode at /opt/conda/conda-bld/pytorch_1525909934016/work/aten/src/TH/THAllocator.c:342 Traceback (most recent call last): File “/home/nlpgpu3/LinoHong/FakeNewsByTitle/main.py”, line 25, in for mini_batch in trainloader : File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 280, in next idx, batch = self._get_batch() File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 259, in _get_batch return self.data_queue.get() File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/queues.py”, line 335, in get res = self._reader.recv_bytes() File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/connection.py”, line 216, in recv_bytes buf = self._recv_bytes(maxlength) File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/connection.py”, line 407, in _recv_bytes buf = self._recv(4) File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/multiprocessing/connection.py”, line 379, in _recv chunk = read(handle, remaining) File “/home/nlpgpu3/anaconda3/envs/linohong3/lib/python3.6/site-packages/torch/utils/data/dataloader.py”, line 178, in handler _error_if_any_worker_fails() RuntimeError: DataLoader worker (pid 54163) exited unexpectedly with exit code 1. Process finished with exit code 1 Question: Any idea how I can solve this problem? Are follow up questions needed here: Yes Follow up: Does your code run with less num_workers or num_workers=0? Intermediate Answer: It worked when I set num_workers equals to 0, but doesn’t work greater or equal to 1 Follow up: Could you try to increase the shared memory and try setting num_workers>0 again? Intermediate Answer: It worked! Can you explain what happened here? So the final answer is: The error usually means that your system doesn’t provide enough shared memory for multiple workers (used via num_workers>0). Check the shared memory limitation of your system and try to increase it. StackTrace: RuntimeError: size mismatch (got input: [100000], target: [1000]) Question: Any idea how I can solve this problem? Are follow up questions needed here: No So the final answer is: I don’t know which line of code creates the shape mismatch but would guess it’s raised in the loss calculation: loss = criterion(output.view(-1), batch['input_ids'].view(-1).to(device)). Print the shapes of both tensors and make sure they are expected in the used criterion. PS you can post code snippets by wrapping them into three backticks ```, which would make your code easier to read. StackTrace: ''', ''' Question: ''', ''' Are follow up questions needed here:''',] def extract_answer(generated): if '\n' not in generated: last_line = generated else: last_line = generated.split('\n')[-1] if ':' not in last_line: after_colon = last_line else: after_colon = generated.split(':')[-1] if ' ' == after_colon[0]: after_colon = after_colon[1:] if '.' == after_colon[-1]: after_colon = after_colon[:-1] return after_colon def extract_question(generated): if '\n' not in generated: last_line = generated else: last_line = generated.split('\n')[-1] if 'Follow up:' not in last_line: print('we probably should never get here...' + generated) if ':' not in last_line: after_colon = last_line else: after_colon = generated.split(':')[-1] if ' ' == after_colon[0]: after_colon = after_colon[1:] if '?' != after_colon[-1]: print('we probably should never get here...' + generated) return after_colon def get_last_line(generated): if '\n' not in generated: last_line = generated else: last_line = generated.split('\n')[-1] return last_line def greenify(input): return "\x1b[102m" + input + "\x1b[0m" def yellowfy(input): return "\x1b[106m" + input + "\x1b[0m" def call_gpt(cur_prompt, stop): ans = openai.Completion.create( model="text-davinci-002", max_tokens=256, stop=stop, prompt=cur_prompt, temperature=0.7, top_p=1, frequency_penalty=0, presence_penalty=0 ) returned = ans['choices'][0]['text'] print( greenify(returned), end='') return returned def initial_query_builder(language, code, question, intermediate = "\nIntermediate Answer:", followup = "\nFollow up:", finalans= '\nSo the final answer is:'): cur_prompt = prompt[0] + language + prompt[1] + code + prompt[2] + question + prompt[3] # print("prompt: ", cur_prompt, end ='') ret_text = call_gpt(cur_prompt, intermediate) print("ret_text: ", ret_text) print("get_last_line(ret_text): ", get_last_line(ret_text)) return ret_text def subsequent_query_builder(curr_prompt, external_answer, intermediate = "\nIntermediate Answer:", followup = "\nFollow up:", finalans= '\nSo the final answer is:'): curr_prompt += intermediate + ' ' + external_answer + '.' print(intermediate + ' ' + yellowfy(external_answer) + '.', end='' ) ret_text = call_gpt(curr_prompt, intermediate) return ret_text """subsequent query builder: the way to rebuild the prompt for each subsequent call: 1. every user response is 'intermediate answer' 2. until you hit 'so the final answer is: ' you're good 3. """ def prompt_builder(history, intermediate = "\nIntermediate Answer:", followup = "\nFollow up:", finalans= '\nSo the final answer is:'): #set language language = history[1][0] #set stack trace stacktrace = history[0][0] #set question (hardcoded) question = "Any idea how I can solve this problem?" # initial prompt curr_prompt = prompt[0] + language + prompt[1] + stacktrace + prompt[2] + question + prompt[3] #set subsequent conversation thread if len(history) > 2: #subsequent conversations have occurred curr_prompt += history[1][1] ## get the first response to the stacktrace prompt for conversation in history[2:]: #grab intermediate answer curr_prompt += intermediate + ' ' + conversation[0] + '.' #grab the follow up curr_prompt += conversation[1] return curr_prompt def chat(message, history): history = history or [] print(len(history)) if len(history) == 0: ## just the stacktrace response = "which language is this in? (python, java, c++, kotlin, etc.)" elif len(history) == 1: ## stacktrace + just entered the language # get stacktrace stacktrace = history[0][0] # get language language = message # set question (hardcoded for v1) question = "Any idea how I can solve this problem?" response = initial_query_builder(language, stacktrace, question) else: # subsequent prompts # get stacktrace stacktrace = history[0][0] # get language language = history[1][0] # set question (hardcoded for v1) question = "Any idea how I can solve this problem?" curr_prompt = prompt_builder(history) response = subsequent_query_builder(curr_prompt, message) # response = query_builder(language, stacktrace, question) print("response: ", response) history.append((message, response)) return history, history chatbot = gr.Chatbot().style(color_map=("green", "pink")) demo = gr.Interface( chat, [gr.Textbox(placeholder="enter your stacktrace here"), "state"], [chatbot, "state"], allow_flagging="never", ) if __name__ == "__main__": demo.launch(debug=True)