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
24 changes: 2 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,7 @@ jobs:
toolchain: "1.92.0"
components: rustfmt

- run: cargo fmt --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y cmake libclang-dev

- uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.92.0"
components: clippy

- uses: Swatinem/rust-cache@v2

- run: cargo clippy --workspace -- -D warnings
- run: make fmt

test:
name: Tests
Expand All @@ -60,4 +40,4 @@ jobs:

- uses: Swatinem/rust-cache@v2

- run: cargo test --workspace
- run: make test.unit
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CARGO_TEST_LLM_FLAGS = --lib -p llama-cpp-bindings --features tests_that_use_llms,mtmd -- --test-threads=1
CARGO_COV_LLM_FLAGS = --lib --features tests_that_use_llms,mtmd -p llama-cpp-bindings
FEATURES = mtmd,sampler,llguidance
CARGO_TEST_LLM_FLAGS = --lib -p llama-cpp-bindings --features tests_that_use_llms,$(FEATURES) -- --test-threads=1
CARGO_COV_LLM_FLAGS = --lib --features tests_that_use_llms,$(FEATURES) -p llama-cpp-bindings

QWEN3_5_0_8B_ENV = \
LLAMA_TEST_HF_REPO=unsloth/Qwen3.5-0.8B-GGUF \
Expand All @@ -12,7 +13,7 @@ QWEN3_5_0_8B_ENV = \

.PHONY: test.unit
test.unit: clippy
cargo test --lib -p llama-cpp-bindings
cargo test --lib -p llama-cpp-bindings --features $(FEATURES)

.PHONY: test.qwen3.5_0.8B
test.qwen3.5_0.8B: clippy
Expand Down Expand Up @@ -42,8 +43,8 @@ test: test.unit test.llms

.PHONY: fmt
fmt:
cargo fmt --check
cargo fmt --all --check

.PHONY: clippy
clippy:
cargo clippy --all-targets -p llama-cpp-bindings
cargo clippy --all-targets -p llama-cpp-bindings --features $(FEATURES) -- -D warnings
6 changes: 5 additions & 1 deletion llama-cpp-bindings/src/llguidance_sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn build_tok_env(model: &LlamaModel) -> Arc<ApproximateTokEnv> {

// --- extern "C" vtable callbacks ---

unsafe extern "C" fn llg_name(
const unsafe extern "C" fn llg_name(
_smpl: *const llama_cpp_bindings_sys::llama_sampler,
) -> *const std::os::raw::c_char {
c"llguidance".as_ptr()
Expand Down Expand Up @@ -168,6 +168,10 @@ static mut LLG_SAMPLER_I: llama_cpp_bindings_sys::llama_sampler_i =
};

/// Create an llguidance-based constrained decoding sampler.
///
/// # Errors
///
/// Returns `GrammarError` if the parser factory, grammar, or parser cannot be created.
pub fn create_llg_sampler(
model: &LlamaModel,
grammar_kind: &str,
Expand Down
1 change: 1 addition & 0 deletions llama-cpp-bindings/src/mtmd/mtmd_bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ mod tests {

#[test]
fn from_audio_data_creates_valid_bitmap() {
#[allow(clippy::cast_precision_loss)]
let audio_samples: Vec<f32> = (0..100).map(|index| (index as f32 * 0.1).sin()).collect();
let bitmap = MtmdBitmap::from_audio_data(&audio_samples).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions llama-cpp-bindings/src/mtmd/mtmd_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use super::mtmd_input_chunk::MtmdInputChunk;
use super::mtmd_input_chunks::MtmdInputChunks;
use super::mtmd_input_text::MtmdInputText;

fn tokenize_result_to_error(result: i32) -> MtmdTokenizeError {
const fn tokenize_result_to_error(result: i32) -> MtmdTokenizeError {
match result {
1 => MtmdTokenizeError::BitmapCountMismatch,
2 => MtmdTokenizeError::ImagePreprocessingError,
_ => MtmdTokenizeError::UnknownError(result),
}
}

fn check_encode_result(result: i32) -> Result<(), MtmdEncodeError> {
const fn check_encode_result(result: i32) -> Result<(), MtmdEncodeError> {
if result == 0 {
Ok(())
} else {
Expand Down
2 changes: 1 addition & 1 deletion llama-cpp-bindings/src/mtmd/mtmd_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub enum MtmdEvalError {
/// Requested batch size exceeds the context's maximum batch size
#[error("batch size {requested} exceeds context batch size {context_max}")]
BatchSizeExceedsContextLimit {
/// The batch size requested in eval_chunks
/// The batch size requested in `eval_chunks`
requested: i32,
/// The maximum batch size configured on the context
context_max: u32,
Expand Down
4 changes: 2 additions & 2 deletions llama-cpp-bindings/src/mtmd/mtmd_input_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::mtmd_input_chunk_type::{MtmdInputChunkType, MtmdInputChunkTypeError};
///
/// `tokens_ptr` must point to at least `n_tokens` valid `llama_token` values
/// that remain valid for the lifetime `'chunk`.
unsafe fn tokens_from_raw_ptr<'chunk>(
const unsafe fn tokens_from_raw_ptr<'chunk>(
tokens_ptr: *const llama_cpp_bindings_sys::llama_token,
n_tokens: usize,
) -> Option<&'chunk [LlamaToken]> {
Expand Down Expand Up @@ -131,7 +131,7 @@ mod unit_tests {
#[test]
fn tokens_from_raw_ptr_returns_none_for_zero_count() {
let token: llama_cpp_bindings_sys::llama_token = 42;
assert!(unsafe { tokens_from_raw_ptr(&token, 0) }.is_none());
assert!(unsafe { tokens_from_raw_ptr(&raw const token, 0) }.is_none());
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions llama-cpp-bindings/src/mtmd/mtmd_input_chunk_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl TryFrom<llama_cpp_bindings_sys::mtmd_input_chunk_type> for MtmdInputChunkTy
chunk_type: llama_cpp_bindings_sys::mtmd_input_chunk_type,
) -> Result<Self, Self::Error> {
match chunk_type {
llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_TEXT => Ok(MtmdInputChunkType::Text),
llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_IMAGE => Ok(MtmdInputChunkType::Image),
llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_AUDIO => Ok(MtmdInputChunkType::Audio),
llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_TEXT => Ok(Self::Text),
llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_IMAGE => Ok(Self::Image),
llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_AUDIO => Ok(Self::Audio),
unknown => Err(MtmdInputChunkTypeError(unknown)),
}
}
Expand Down
4 changes: 2 additions & 2 deletions llama-cpp-bindings/src/mtmd/mtmd_input_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::mtmd_context::MtmdContext;
use super::mtmd_error::MtmdEvalError;
use super::mtmd_input_chunk::MtmdInputChunk;

fn check_eval_result(result: i32) -> Result<(), MtmdEvalError> {
const fn check_eval_result(result: i32) -> Result<(), MtmdEvalError> {
if result == 0 {
Ok(())
} else {
Expand Down Expand Up @@ -109,7 +109,7 @@ impl MtmdInputChunks {
) -> Result<llama_cpp_bindings_sys::llama_pos, MtmdEvalError> {
let context_max_batch = llama_ctx.n_batch();

if n_batch > 0 && (n_batch as u32) > context_max_batch {
if n_batch > 0 && n_batch.cast_unsigned() > context_max_batch {
return Err(MtmdEvalError::BatchSizeExceedsContextLimit {
requested: n_batch,
context_max: context_max_batch,
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[toolchain]
channel = "1.92.0"
components = ["clippy", "rustfmt"]
Loading