Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deepseek can't support n > 1 #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
34 changes: 23 additions & 11 deletions optillm/bon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,30 @@ def best_of_n_sampling(system_prompt: str, initial_query: str, client, model: st
{"role": "user", "content": initial_query}]

completions = []

response = client.chat.completions.create(
model=model,
messages=messages,
max_tokens=4096,
n=n,
temperature=1
)
completions = [choice.message.content for choice in response.choices]

try:
response = client.chat.completions.create(
model=model,
messages=messages,
max_tokens=4096,
n=n,
temperature=1
)
completions = [choice.message.content for choice in response.choices]
bon_completion_tokens += response.usage.completion_tokens
except:
for _ in range(n):
response = client.chat.completions.create(
model=model,
messages=messages,
max_tokens=4096,
n=1,
temperature=1
)
completions.extend([choice.message.content for choice in response.choices])
bon_completion_tokens += response.usage.completion_tokens
logger.info(f"Generated {len(completions)} initial completions. Tokens used: {response.usage.completion_tokens}")
bon_completion_tokens += response.usage.completion_tokens


# Rate the completions
rating_messages = messages.copy()
rating_messages.append({"role": "system", "content": "Rate the following responses on a scale from 0 to 10, where 0 is poor and 10 is excellent. Consider factors such as relevance, coherence, and helpfulness. Respond with only a number."})
Expand Down