简体   繁体   English

什么是 OpenAI API 警告:为避免 invalid_request_error,best_of 设置为等于 n。 什么是“最佳”?

[英]What is the OpenAI API warning: To avoid an invalid_request_error, best_of was set to equal n. What is "best of"?

This "best of" warning results from using the OpenAI API on a PC running Win10.这个“最佳”警告是在运行 Win10 的 PC 上使用 OpenAI API 的结果。

The Context:上下文:

Using the OpenAI API in Jupyter Lab with the ir kernel, with having only the rgpt3 library installed in this Notebook.在 Jupyter Lab 中使用 OpenAI API 和 ir kernel,在此笔记本中仅安装了 rgpt3 库。

The API successfully performs a test code completion. API 成功执行测试代码完成。 And it does not matter whether the API is making a single or multiple API request, both return the same warning.并且无论 API 是发出单个还是多个 API 请求,都返回相同的警告。

The following results when using 3 queries:使用 3 个查询时的结果如下:

[1] "Request: 1/3" To avoid an invalid_request_error , best_of was set to equal n [1] "Request: 1/3" 为了避免invalid_request_errorbest_of被设置为等于n

[1] "Request: 2/3" To avoid an invalid_request_error , best_of was set to equal n [1] "Request: 2/3" 为了避免invalid_request_errorbest_of被设置为等于n

[1] "Request: 3/3" To avoid an invalid_request_error , best_of was set to equal n [1] "Request: 3/3" 为了避免invalid_request_errorbest_of被设置为等于n

After performing multiple unsuccessful web searches - including a search at Stack Overflow for information about these warnings, I found there exists almost no information about this warning anywhere.在执行多次不成功的 web 搜索后——包括在 Stack Overflow 上搜索有关这些警告的信息,我发现几乎没有任何关于此警告的信息。 It's probably too early in the process because the OpenAI API is relatively new to most people.这个过程可能还为时过早,因为 OpenAI API 对大多数人来说都是相对较新的。

Therefore, it was decided to post both the question and the answer regarding this warning because otherwise finding such information is very difficult and time consuming.因此,决定发布有关此警告的问题和答案,否则查找此类信息非常困难且耗时。 And for those users who are boldly going where few have gone before, errors and warning messages do not inspire confidence.对于那些大胆前往以前很少有人去过的地方的用户来说,错误和警告信息不会激发信心。

What the error following warning message is all about:警告消息后的错误是关于什么的:

To avoid an invalid_request_error , best_of was set to equal `n为了避免invalid_request_errorbest_of被设置为等于 `n

The Best Practices guide at OpenAi website provides the source which describes what "best_of" means. OpenAi 网站上的最佳实践指南提供了描述“best_of”含义的来源。 This information is currently available at the following website:此信息目前可在以下网站获得:

https://beta.openai.com/docs/guides/production-best-practices/improving-latencies https://beta.openai.com/docs/guides/production-best-practices/improving-latencies

In a nutshell, "best_of" is one of the parameters used to define what we want from the OpenAI website when using the API. Using the OpenAI API involves "tokens" - which is something akin to the metering of a user's usage and rate limits at the OpenAI website.简而言之, “best_of”是用于定义我们在使用 API 时希望从 OpenAI 网站获得什么的参数之一。使用 OpenAI API 涉及“令牌” ——类似于用户使用和速率限制的计量在 OpenAI 网站上。 In addition, there are also limitations for most of the models at OpenAI based on the context length - with most models having 2048 max context size.此外,基于上下文长度,OpenAI 的大多数模型也有限制——大多数模型的最大上下文大小为 2048。

The Best Practices guide at the OpenAI website suggests the following: OpenAI 网站上的最佳实践指南建议如下:

Generate fewer completions: lower the values of n and best_of when possible where n refers to how many completions to generate for each prompt and best_of is used to represent the result with the highest log probability per token.生成更少的完成:尽可能降低 n 和 best_of 的值,其中 n 指的是为每个提示生成多少个完成,best_of 用于表示每个标记具有最高对数概率的结果。

If n and best_of both equal 1 (which is the default), the number of generated tokens will be at most, equal to max_tokens.如果 n 和 best_of 都等于 1(这是默认值),则生成的令牌数量最多等于 max_tokens。

If n (the number of completions returned) or best_of (the number of completions generated for consideration) are set to > 1, each request will create multiple outputs.如果 n(返回的完成数)或 best_of(为考虑而生成的完成数)设置为 > 1,则每个请求将创建多个输出。 Here, you can consider the number of generated tokens as [ max_tokens * max (n, best_of) ]在这里,您可以将生成的令牌数视为 [ max_tokens * max (n, best_of) ]

The function used for Requests at the OpenAI website in the Jupyter Notebook has a R wrapper which sends Requests with the range of parameters - including the parameter called best_of.在 Jupyter Notebook 的 OpenAI 网站上用于请求的 function 有一个 R 包装器,它发送带有参数范围的请求 - 包括名为 best_of 的参数。 The best_of parameter in the function is already defaulted to equal to 1 and is only changed manually. function中的best_of参数已经默认等于1,只能手动更改。 Copy and paste of this parameter from the function follows:从 function 复制并粘贴此参数如下:

best_of = 1 

Therefore, it can only be presumed that the OpenAI website auto-generates the "best_of" warning for each "Prompt" for every API Request as a friendly reminder.因此,只能推测OpenAI网站对每一个API Request自动生成了每个“Prompt”的“best_of”警告作为友情提醒。 This warning message can be programmatically ignored and removed if so desired如果需要,可以通过编程忽略和删除此警告消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM