Skip to content

Commit

Permalink
Merge pull request #504 from brittlewis12/ubatch
Browse files Browse the repository at this point in the history
Expose `n_ubatch` context param
  • Loading branch information
MarcusDunn authored Sep 23, 2024
2 parents ea798fa + 56625a6 commit b1420f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion llama-cpp-2/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ impl<'model> LlamaContext<'model> {
}
}

/// Gets the max number of tokens in a batch.
/// Gets the max number of logical tokens that can be submitted to decode. Must be greater than or equal to n_ubatch.
#[must_use]
pub fn n_batch(&self) -> u32 {
unsafe { llama_cpp_sys_2::llama_n_batch(self.context.as_ptr()) }
}

/// Gets the max number of physical tokens (hardware level) to decode in batch. Must be less than or equal to n_batch.
#[must_use]
pub fn n_ubatch(&self) -> u32 {
unsafe { llama_cpp_sys_2::llama_n_ubatch(self.context.as_ptr()) }
}

/// Gets the size of the context.
#[must_use]
pub fn n_ctx(&self) -> u32 {
Expand Down
31 changes: 31 additions & 0 deletions llama-cpp-2/src/context/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,37 @@ impl LlamaContextParams {
self.context_params.n_batch
}

/// Set the `n_ubatch`
///
/// # Examples
///
/// ```rust
/// # use std::num::NonZeroU32;
/// use llama_cpp_2::context::params::LlamaContextParams;
/// let params = LlamaContextParams::default()
/// .with_n_ubatch(512);
/// assert_eq!(params.n_ubatch(), 512);
/// ```
#[must_use]
pub fn with_n_ubatch(mut self, n_ubatch: u32) -> Self {
self.context_params.n_ubatch = n_ubatch;
self
}

/// Get the `n_ubatch`
///
/// # Examples
///
/// ```rust
/// use llama_cpp_2::context::params::LlamaContextParams;
/// let params = LlamaContextParams::default();
/// assert_eq!(params.n_ubatch(), 512);
/// ```
#[must_use]
pub fn n_ubatch(&self) -> u32 {
self.context_params.n_ubatch
}

/// Set the type of rope scaling.
///
/// # Examples
Expand Down

0 comments on commit b1420f3

Please sign in to comment.