This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move loader to standalone crate llama-loader
- Loading branch information
Showing
10 changed files
with
127 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
members = [ | ||
"ggml-sys", | ||
"ggml", | ||
"llama-loader", | ||
"llama-rs", | ||
"llama-cli", | ||
"generate-ggml-bindings" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "llama-loader" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
ggml = { path = "../ggml" } | ||
thiserror = "*" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::io::BufRead; | ||
|
||
pub fn read_bytes<const N: usize>(reader: &mut impl BufRead) -> Result<[u8; N], std::io::Error> { | ||
let mut bytes = [0u8; N]; | ||
reader.read_exact(&mut bytes)?; | ||
Ok(bytes) | ||
} | ||
|
||
pub fn read_i32(reader: &mut impl BufRead) -> Result<i32, std::io::Error> { | ||
Ok(i32::from_le_bytes(read_bytes::<4>(reader)?)) | ||
} | ||
|
||
pub fn read_u32(reader: &mut impl BufRead) -> Result<u32, std::io::Error> { | ||
Ok(u32::from_le_bytes(read_bytes::<4>(reader)?)) | ||
} | ||
|
||
pub fn read_f32(reader: &mut impl BufRead) -> Result<f32, std::io::Error> { | ||
Ok(f32::from_le_bytes(read_bytes::<4>(reader)?)) | ||
} | ||
|
||
pub fn read_bytes_with_len( | ||
reader: &mut impl BufRead, | ||
len: usize, | ||
) -> Result<Vec<u8>, std::io::Error> { | ||
let mut bytes = vec![0u8; len]; | ||
reader.read_exact(&mut bytes)?; | ||
Ok(bytes) | ||
} | ||
|
||
// NOTE: Implementation from #![feature(buf_read_has_data_left)] | ||
pub fn has_data_left(reader: &mut impl BufRead) -> Result<bool, std::io::Error> { | ||
reader.fill_buf().map(|b| !b.is_empty()) | ||
} |
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
Oops, something went wrong.