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
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()
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
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. |