-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #393 from robertknight/logits-filter
Add API to rten-generate for filtering/processing logits
- Loading branch information
Showing
3 changed files
with
142 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//! Filters for processing model outputs prior to sampling. | ||
|
||
use rten_tensor::{NdTensor, NdTensorView}; | ||
|
||
/// Filter which modifies the output logits from a model. | ||
/// | ||
/// The filter is applied to the model outputs before a token is sampled. | ||
pub trait LogitsFilter { | ||
/// Filter the model's output and return the modified logits. | ||
/// | ||
/// If this method returns `None`, the input logits are passed unmodified | ||
/// to the sampler. `prev_tokens` contains the previously sampled tokens, | ||
/// including the prompt. | ||
fn filter(&self, logits: NdTensorView<f32, 1>, prev_tokens: &[u32]) | ||
-> Option<NdTensor<f32, 1>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters