evals icon indicating copy to clipboard operation
evals copied to clipboard

Deepcopy in recorder

Open johny-b opened this issue 1 year ago • 1 comments

Recorder doesn't write the record file immediately when record_sampling is called, but does this once there are enough entries to be written. To be able to write the logs later, recorder saves the prompt object passed to record_sampling. If someone alters the prompt object after a call to record_sampling, but before data is dumped to a file, recorder writes incorrect data.

This is fixed with deepcopy. Note: common copy() would help for cases when we add/remove stuff from the prompt, but not if we modify elements of it.

Example. There should be no difference between this:

messages = [{"role": "system", "content": "hello there!"}]
response = self.completion_fns[0](prompt=messages).get_completions()[0]
messages = messages + [{"role": "assistant", "content": response}]
messages += [{"role": "system", "content": "tell me a joke"}]
response = self.completion_fns[0](prompt=messages).get_completions()[0]

and

messages = [{"role": "system", "content": "hello there!"}]
response = self.completion_fns[0](prompt=messages).get_completions()[0]
messages.append({"role": "assistant", "content": response})
messages += [{"role": "system", "content": "tell me a joke"}]
response = self.completion_fns[0](prompt=messages).get_completions()[0]

but now the second code snipped creates weird logs.

johny-b avatar Oct 12 '23 17:10 johny-b

Would it be better to implement the copy further down the chain in record_event so that other recorder logs also receive this fix? (e.g. record_match, record_embedding, etc are also affected by this)

JunShern avatar Dec 03 '23 16:12 JunShern