base
AsyncLM
Bases: ABC
Abstract base class for asynchronous language models.
This class provides an interface for language models that can generate token probabilities asynchronously. It handles tokenization and vocabulary management.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokenizer
|
A Hugging Face tokenizer instance compatible with the language model |
required |
Source code in genlm/backend/llm/base.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
next_token_logprobs(token_ids)
abstractmethod
async
Request log probabilities of next token asynchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token_ids
|
list[int]
|
A list of token IDs representing the prompt. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Normalized log probability tensor. |
Source code in genlm/backend/llm/base.py
next_token_logprobs_sync(token_ids)
abstractmethod
Request log probabilities of next token synchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token_ids
|
list[int]
|
A list of token IDs representing the prompt. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Normalized log probability tensor. |
Source code in genlm/backend/llm/base.py
batch_next_token_logprobs(token_ids_list)
async
Batch request log probabilities for multiple token sequences asynchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token_ids_list
|
list[list[int]]
|
A list of token ID lists. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A tensor of log probability tensors. |
Source code in genlm/backend/llm/base.py
batch_next_token_logprobs_sync(token_ids_list)
Batch request log probabilities for multiple token sequences synchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token_ids_list
|
list[list[int]]
|
A list of token ID lists. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A tensor of log probability tensors. |
Source code in genlm/backend/llm/base.py
clear_cache()
sample(prompt_token_ids, max_tokens, eos_token_ids, temperature=1.0, seed=None)
async
Sample from the language model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt_token_ids
|
list[int]
|
The token IDs of the prompt. |
required |
eos_token_ids
|
list[int]
|
The token IDs of the end-of-sequence tokens. |
required |
temperature
|
float
|
The temperature to use to rescale the logits. Defaults to 1.0. |
1.0
|
max_tokens
|
int
|
The maximum number of tokens to generate. |
required |
seed
|
int
|
The seed for the random number generator. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
list[int]
|
The sampled token IDs. |
Source code in genlm/backend/llm/base.py
batch_sample(prompt_token_ids_list, max_tokens, eos_token_ids, temperature=1.0, seed=None)
async
Batch sample from the language model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt_token_ids_list
|
list[list[int]]
|
The token IDs of the prompts. |
required |
max_tokens
|
int
|
The maximum number of tokens to generate. |
required |
eos_token_ids
|
list[int]
|
The token IDs of the end-of-sequence token. |
required |
temperature
|
float
|
The temperature to use for the logits. |
1.0
|
seed
|
int
|
The seed for the random number generator. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
list[list[int]]
|
The sampled token IDs. |
Source code in genlm/backend/llm/base.py
MockAsyncLM
Bases: AsyncLM
Mock implementation of AsyncLM used for testing.
Source code in genlm/backend/llm/base.py
__init__(tokenizer)
Initialize a MockAsyncLM
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokenizer
|
Hugging Face tokenizer instance |
required |
from_name(model_name, **kwargs)
classmethod
Create a MockAsyncLM instance over the vocabulary of the model's tokenizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name
|
str
|
Name of pretrained model to load tokenizer from |
required |
**kwargs
|
Additional arguments passed to |
{}
|
Returns:
Type | Description |
---|---|
MockAsyncLM
|
|
Source code in genlm/backend/llm/base.py
next_token_logprobs(token_ids)
async
Get next token log probabilities asynchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token_ids
|
list[int]
|
Input token IDs. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Normalized log probability tensor. |
Source code in genlm/backend/llm/base.py
next_token_logprobs_sync(token_ids)
Get next token log probabilities synchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token_ids
|
list[int]
|
Input token IDs. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Normalized log probability tensor. |