Skip to content

Commit

Permalink
remove echo parameter in OpenAI completions API (EleutherAI#1779)
Browse files Browse the repository at this point in the history
* remove echo parameter in OpenAI completions API

* remove context length parameter doc string
  • Loading branch information
djstrong authored and notrichardren committed May 31, 2024
1 parent 5b3b60d commit 376ad1e
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lm_eval/models/openai_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
from lm_eval.utils import eval_logger


def get_result(response, ctxlen: int) -> Tuple[float, bool]:
def get_result(response) -> Tuple[float, bool]:
"""Process results from OpenAI API response.
:param response: dict
OpenAI API Response
:param ctxlen: int
Length of context (so we can slice them away and only keep the predictions)
:return:
continuation_logprobs: np.array
Log probabilities of continuation tokens
Expand All @@ -29,9 +27,9 @@ def get_result(response, ctxlen: int) -> Tuple[float, bool]:
"""
is_greedy = True
logprobs = response.logprobs.token_logprobs
continuation_logprobs = sum(logprobs[ctxlen:])
continuation_logprobs = sum(logprobs)

for i in range(ctxlen, len(response.logprobs.token_logprobs)):
for i in range(len(response.logprobs.token_logprobs)):
token = response.logprobs.token_logprobs[i]
top_tokens = response.logprobs.top_logprobs[i]
top_token = max(top_tokens.keys(), key=lambda x: top_tokens[x])
Expand Down Expand Up @@ -212,7 +210,6 @@ def _collate(x):
client=self.client,
model=self.model,
prompt=inps,
echo=True,
max_tokens=0,
temperature=0.0,
logprobs=10,
Expand All @@ -222,7 +219,7 @@ def _collate(x):
for resp, ctxlen, (cache_key, context_enc, continuation_enc) in zip(
response.choices, ctxlens, chunk
):
answer = get_result(resp, ctxlen)
answer = get_result(resp)

res.append(answer)

Expand Down

0 comments on commit 376ad1e

Please sign in to comment.