Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llama-cpp-2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ pub mod token;
pub mod token_type;

/// A failable result from a llama.cpp function.
pub type Result<T> = std::result::Result<T, LLamaCppError>;
pub type Result<T> = std::result::Result<T, LlamaCppError>;

/// All errors that can occur in the llama-cpp crate.
#[derive(Debug, Eq, PartialEq, thiserror::Error)]
pub enum LLamaCppError {
pub enum LlamaCppError {
/// The backend was already initialized. This can generally be ignored as initializing the backend
/// is idempotent.
#[error("BackendAlreadyInitialized")]
Expand Down
8 changes: 4 additions & 4 deletions llama-cpp-2/src/llama_backend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Representation of an initialized llama backend

use crate::LLamaCppError;
use crate::LlamaCppError;
use llama_cpp_sys_2::ggml_log_level;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::SeqCst;
Expand All @@ -18,7 +18,7 @@ impl LlamaBackend {
fn mark_init() -> crate::Result<()> {
match LLAMA_BACKEND_INITIALIZED.compare_exchange(false, true, SeqCst, SeqCst) {
Ok(_) => Ok(()),
Err(_) => Err(LLamaCppError::BackendAlreadyInitialized),
Err(_) => Err(LlamaCppError::BackendAlreadyInitialized),
}
}

Expand All @@ -28,15 +28,15 @@ impl LlamaBackend {
///
/// ```
///# use llama_cpp_2::llama_backend::LlamaBackend;
///# use llama_cpp_2::LLamaCppError;
///# use llama_cpp_2::LlamaCppError;
///# use std::error::Error;
///
///# fn main() -> Result<(), Box<dyn Error>> {
///
///
/// let backend = LlamaBackend::init()?;
/// // the llama backend can only be initialized once
/// assert_eq!(Err(LLamaCppError::BackendAlreadyInitialized), LlamaBackend::init());
/// assert_eq!(Err(LlamaCppError::BackendAlreadyInitialized), LlamaBackend::init());
///
///# Ok(())
///# }
Expand Down
10 changes: 5 additions & 5 deletions llama-cpp-2/src/model/params.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A safe wrapper around `llama_model_params`.

use crate::model::params::kv_overrides::KvOverrides;
use crate::LLamaCppError;
use crate::LlamaCppError;
use std::ffi::{c_char, CStr};
use std::fmt::{Debug, Formatter};
use std::pin::Pin;
Expand Down Expand Up @@ -375,19 +375,19 @@ impl LlamaModelParams {
/// You don't need to specify CPU or ACCEL devices.
///
/// # Errors
/// Returns `LLamaCppError::BackendDeviceNotFound` if any device index is invalid.
pub fn with_devices(mut self, devices: &[usize]) -> Result<Self, LLamaCppError> {
/// Returns `LlamaCppError::BackendDeviceNotFound` if any device index is invalid.
pub fn with_devices(mut self, devices: &[usize]) -> Result<Self, LlamaCppError> {
for dev in self.devices.iter_mut() {
*dev = std::ptr::null_mut();
}
// Check device count
let max_devices = crate::max_devices().min(LLAMA_CPP_MAX_DEVICES);
if devices.len() > max_devices {
return Err(LLamaCppError::MaxDevicesExceeded(max_devices));
return Err(LlamaCppError::MaxDevicesExceeded(max_devices));
}
for (i, &dev) in devices.iter().enumerate() {
if dev >= unsafe { llama_cpp_sys_2::ggml_backend_dev_count() } {
return Err(LLamaCppError::BackendDeviceNotFound(dev));
return Err(LlamaCppError::BackendDeviceNotFound(dev));
}
let backend_dev = unsafe { llama_cpp_sys_2::ggml_backend_dev_get(dev) };
self.devices[i] = backend_dev;
Expand Down
Loading