mirror of
https://github.com/abetlen/llama-cpp-python.git
synced 2023-09-07 17:34:22 +03:00
Update settings fields and defaults
This commit is contained in:
@@ -13,18 +13,41 @@ from sse_starlette.sse import EventSourceResponse
|
|||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
model: str
|
model: str = Field(
|
||||||
n_ctx: int = 2048
|
description="The path to the model to use for generating completions."
|
||||||
n_batch: int = 512
|
)
|
||||||
n_threads: int = max((os.cpu_count() or 2) // 2, 1)
|
n_ctx: int = Field(default=2048, ge=1, description="The context size.")
|
||||||
f16_kv: bool = True
|
n_batch: int = Field(
|
||||||
use_mlock: bool = False # This causes a silent failure on platforms that don't support mlock (e.g. Windows) took forever to figure out...
|
default=512, ge=1, description="The batch size to use per eval."
|
||||||
use_mmap: bool = True
|
)
|
||||||
embedding: bool = True
|
n_threads: int = Field(
|
||||||
last_n_tokens_size: int = 64
|
default=max((os.cpu_count() or 2) // 2, 1),
|
||||||
logits_all: bool = False
|
ge=1,
|
||||||
cache: bool = False # WARNING: This is an experimental feature
|
description="The number of threads to use.",
|
||||||
vocab_only: bool = False
|
)
|
||||||
|
f16_kv: bool = Field(default=True, description="Whether to use f16 key/value.")
|
||||||
|
use_mlock: bool = Field(
|
||||||
|
default=bool(llama_cpp.llama_mlock_supported().value),
|
||||||
|
description="Use mlock.",
|
||||||
|
)
|
||||||
|
use_mmap: bool = Field(
|
||||||
|
default=bool(llama_cpp.llama_mmap_supported().value),
|
||||||
|
description="Use mmap.",
|
||||||
|
)
|
||||||
|
embedding: bool = Field(default=True, description="Whether to use embeddings.")
|
||||||
|
last_n_tokens_size: int = Field(
|
||||||
|
default=64,
|
||||||
|
ge=0,
|
||||||
|
description="Last n tokens to keep for repeat penalty calculation.",
|
||||||
|
)
|
||||||
|
logits_all: bool = Field(default=True, description="Whether to return logits.")
|
||||||
|
cache: bool = Field(
|
||||||
|
default=False,
|
||||||
|
description="Use a cache to reduce processing times for evaluated prompts.",
|
||||||
|
)
|
||||||
|
vocab_only: bool = Field(
|
||||||
|
default=False, description="Whether to only return the vocabulary."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@@ -74,79 +97,75 @@ def get_llama():
|
|||||||
with llama_lock:
|
with llama_lock:
|
||||||
yield llama
|
yield llama
|
||||||
|
|
||||||
model_field = Field(
|
|
||||||
description="The model to use for generating completions."
|
model_field = Field(description="The model to use for generating completions.")
|
||||||
)
|
|
||||||
|
|
||||||
max_tokens_field = Field(
|
max_tokens_field = Field(
|
||||||
default=16,
|
default=16, ge=1, le=2048, description="The maximum number of tokens to generate."
|
||||||
ge=1,
|
|
||||||
le=2048,
|
|
||||||
description="The maximum number of tokens to generate."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
temperature_field = Field(
|
temperature_field = Field(
|
||||||
default=0.8,
|
default=0.8,
|
||||||
ge=0.0,
|
ge=0.0,
|
||||||
le=2.0,
|
le=2.0,
|
||||||
description="Adjust the randomness of the generated text.\n\n" +
|
description="Adjust the randomness of the generated text.\n\n"
|
||||||
"Temperature is a hyperparameter that controls the randomness of the generated text. It affects the probability distribution of the model's output tokens. A higher temperature (e.g., 1.5) makes the output more random and creative, while a lower temperature (e.g., 0.5) makes the output more focused, deterministic, and conservative. The default value is 0.8, which provides a balance between randomness and determinism. At the extreme, a temperature of 0 will always pick the most likely next token, leading to identical outputs in each run."
|
+ "Temperature is a hyperparameter that controls the randomness of the generated text. It affects the probability distribution of the model's output tokens. A higher temperature (e.g., 1.5) makes the output more random and creative, while a lower temperature (e.g., 0.5) makes the output more focused, deterministic, and conservative. The default value is 0.8, which provides a balance between randomness and determinism. At the extreme, a temperature of 0 will always pick the most likely next token, leading to identical outputs in each run.",
|
||||||
)
|
)
|
||||||
|
|
||||||
top_p_field = Field(
|
top_p_field = Field(
|
||||||
default=0.95,
|
default=0.95,
|
||||||
ge=0.0,
|
ge=0.0,
|
||||||
le=1.0,
|
le=1.0,
|
||||||
description="Limit the next token selection to a subset of tokens with a cumulative probability above a threshold P.\n\n" +
|
description="Limit the next token selection to a subset of tokens with a cumulative probability above a threshold P.\n\n"
|
||||||
"Top-p sampling, also known as nucleus sampling, is another text generation method that selects the next token from a subset of tokens that together have a cumulative probability of at least p. This method provides a balance between diversity and quality by considering both the probabilities of tokens and the number of tokens to sample from. A higher value for top_p (e.g., 0.95) will lead to more diverse text, while a lower value (e.g., 0.5) will generate more focused and conservative text."
|
+ "Top-p sampling, also known as nucleus sampling, is another text generation method that selects the next token from a subset of tokens that together have a cumulative probability of at least p. This method provides a balance between diversity and quality by considering both the probabilities of tokens and the number of tokens to sample from. A higher value for top_p (e.g., 0.95) will lead to more diverse text, while a lower value (e.g., 0.5) will generate more focused and conservative text.",
|
||||||
)
|
)
|
||||||
|
|
||||||
stop_field = Field(
|
stop_field = Field(
|
||||||
default=None,
|
default=None,
|
||||||
description="A list of tokens at which to stop generation. If None, no stop tokens are used."
|
description="A list of tokens at which to stop generation. If None, no stop tokens are used.",
|
||||||
)
|
)
|
||||||
|
|
||||||
stream_field = Field(
|
stream_field = Field(
|
||||||
default=False,
|
default=False,
|
||||||
description="Whether to stream the results as they are generated. Useful for chatbots."
|
description="Whether to stream the results as they are generated. Useful for chatbots.",
|
||||||
)
|
)
|
||||||
|
|
||||||
top_k_field = Field(
|
top_k_field = Field(
|
||||||
default=40,
|
default=40,
|
||||||
ge=0,
|
ge=0,
|
||||||
description="Limit the next token selection to the K most probable tokens.\n\n" +
|
description="Limit the next token selection to the K most probable tokens.\n\n"
|
||||||
"Top-k sampling is a text generation method that selects the next token only from the top k most likely tokens predicted by the model. It helps reduce the risk of generating low-probability or nonsensical tokens, but it may also limit the diversity of the output. A higher value for top_k (e.g., 100) will consider more tokens and lead to more diverse text, while a lower value (e.g., 10) will focus on the most probable tokens and generate more conservative text."
|
+ "Top-k sampling is a text generation method that selects the next token only from the top k most likely tokens predicted by the model. It helps reduce the risk of generating low-probability or nonsensical tokens, but it may also limit the diversity of the output. A higher value for top_k (e.g., 100) will consider more tokens and lead to more diverse text, while a lower value (e.g., 10) will focus on the most probable tokens and generate more conservative text.",
|
||||||
)
|
)
|
||||||
|
|
||||||
repeat_penalty_field = Field(
|
repeat_penalty_field = Field(
|
||||||
default=1.0,
|
default=1.0,
|
||||||
ge=0.0,
|
ge=0.0,
|
||||||
description="A penalty applied to each token that is already generated. This helps prevent the model from repeating itself.\n\n" +
|
description="A penalty applied to each token that is already generated. This helps prevent the model from repeating itself.\n\n"
|
||||||
"Repeat penalty is a hyperparameter used to penalize the repetition of token sequences during text generation. It helps prevent the model from generating repetitive or monotonous text. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient."
|
+ "Repeat penalty is a hyperparameter used to penalize the repetition of token sequences during text generation. It helps prevent the model from generating repetitive or monotonous text. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CreateCompletionRequest(BaseModel):
|
class CreateCompletionRequest(BaseModel):
|
||||||
prompt: Optional[str] = Field(
|
prompt: Optional[str] = Field(
|
||||||
default="",
|
default="", description="The prompt to generate completions for."
|
||||||
description="The prompt to generate completions for."
|
|
||||||
)
|
)
|
||||||
suffix: Optional[str] = Field(
|
suffix: Optional[str] = Field(
|
||||||
default=None,
|
default=None,
|
||||||
description="A suffix to append to the generated text. If None, no suffix is appended. Useful for chatbots."
|
description="A suffix to append to the generated text. If None, no suffix is appended. Useful for chatbots.",
|
||||||
)
|
)
|
||||||
max_tokens: int = max_tokens_field
|
max_tokens: int = max_tokens_field
|
||||||
temperature: float = temperature_field
|
temperature: float = temperature_field
|
||||||
top_p: float = top_p_field
|
top_p: float = top_p_field
|
||||||
echo: bool = Field(
|
echo: bool = Field(
|
||||||
default=False,
|
default=False,
|
||||||
description="Whether to echo the prompt in the generated text. Useful for chatbots."
|
description="Whether to echo the prompt in the generated text. Useful for chatbots.",
|
||||||
)
|
)
|
||||||
stop: Optional[List[str]] = stop_field
|
stop: Optional[List[str]] = stop_field
|
||||||
stream: bool = stream_field
|
stream: bool = stream_field
|
||||||
logprobs: Optional[int] = Field(
|
logprobs: Optional[int] = Field(
|
||||||
default=None,
|
default=None,
|
||||||
ge=0,
|
ge=0,
|
||||||
description="The number of logprobs to generate. If None, no logprobs are generated."
|
description="The number of logprobs to generate. If None, no logprobs are generated.",
|
||||||
)
|
)
|
||||||
|
|
||||||
# ignored or currently unsupported
|
# ignored or currently unsupported
|
||||||
@@ -204,9 +223,7 @@ def create_completion(
|
|||||||
|
|
||||||
class CreateEmbeddingRequest(BaseModel):
|
class CreateEmbeddingRequest(BaseModel):
|
||||||
model: Optional[str] = model_field
|
model: Optional[str] = model_field
|
||||||
input: str = Field(
|
input: str = Field(description="The input to embed.")
|
||||||
description="The input to embed."
|
|
||||||
)
|
|
||||||
user: Optional[str]
|
user: Optional[str]
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@@ -239,8 +256,7 @@ class ChatCompletionRequestMessage(BaseModel):
|
|||||||
|
|
||||||
class CreateChatCompletionRequest(BaseModel):
|
class CreateChatCompletionRequest(BaseModel):
|
||||||
messages: List[ChatCompletionRequestMessage] = Field(
|
messages: List[ChatCompletionRequestMessage] = Field(
|
||||||
default=[],
|
default=[], description="A list of messages to generate completions for."
|
||||||
description="A list of messages to generate completions for."
|
|
||||||
)
|
)
|
||||||
max_tokens: int = max_tokens_field
|
max_tokens: int = max_tokens_field
|
||||||
temperature: float = temperature_field
|
temperature: float = temperature_field
|
||||||
|
|||||||
Reference in New Issue
Block a user