Skip to content

Commit

Permalink
Merge pull request #3 from junaire/jun/rename
Browse files Browse the repository at this point in the history
Rename wasi_llm -> wasmedge_llmc
  • Loading branch information
hydai authored Sep 10, 2024
2 parents be48126 + 60d73c8 commit 7a27a85
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
sudo apt update && sudo apt install software-properties-common
git clone https://github.com/WasmEdge/WasmEdge /tmp/WasmEdge
mkdir /tmp/build && cd /tmp/build
cmake /tmp/WasmEdge -DCMAKE_BUILD_TYPE=Release -DWASMEDGE_USE_LLVM=OFF -DWASMEDGE_PLUGIN_LLM=ON -DWASMEDGE_BUILD_TESTS=OFF
cmake /tmp/WasmEdge -DCMAKE_BUILD_TYPE=Release -DWASMEDGE_USE_LLVM=OFF -DWASMEDGE_PLUGIN_LLMC=ON -DWASMEDGE_BUILD_TESTS=OFF
make -j$(nproc) && sudo make install
- name: Train GPT2
run: |
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A Rust library for using llm.c functions when the Wasi is being executed on Wasm
```bash
git clone https://github.com/WasmEdge/WasmEdge.git
cd WasmEdge
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release -DWASMEDGE_BUILD_TESTS=OFF -DWASMEDGE_PLUGIN_LLM=On
cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release -DWASMEDGE_BUILD_TESTS=OFF -DWASMEDGE_PLUGIN_LLMC=ON
cmake --build build
cmake --install build
```
Expand All @@ -20,6 +20,7 @@ wget -P /tmp/data/ https://huggingface.co/datasets/karpathy/llmc-starter-pack/re

## Run the example
```bash
cd example
cargo build --target wasm32-wasi --release
wasmedge --dir .:. ./target/wasm32-wasi/release/wasmedge_stable_diffusion_example.wasm
wasmedge --dir .:. ./target/wasm32-wasi/release/example.wasm
```
8 changes: 4 additions & 4 deletions wasmedge-llmc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ConfigBuilder {
}

impl Model {
pub fn from_checkpoints(checkpoint_path: &str) -> Result<Self, WasmedgeLLMErrno> {
pub fn from_checkpoints(checkpoint_path: &str) -> Result<Self, WasmedgeLLMCErrno> {
let mut model_id = MaybeUninit::<u32>::uninit();
unsafe {
let result = model_create(checkpoint_path, model_id.as_mut_ptr());
Expand All @@ -64,7 +64,7 @@ impl Model {
val_data_loader: DataLoader,
tokenizer: Tokenizer,
config: Config,
) -> Result<(), WasmedgeLLMErrno> {
) -> Result<(), WasmedgeLLMCErrno> {
unsafe {
model_train(
self.id,
Expand Down Expand Up @@ -94,7 +94,7 @@ impl DataLoader {
process_rank: u32,
num_processes: u32,
should_shuffle: bool,
) -> Result<Self, WasmedgeLLMErrno> {
) -> Result<Self, WasmedgeLLMCErrno> {
let mut dataloader_id = MaybeUninit::<u32>::uninit();
unsafe {
let result = dataloader_create(
Expand Down Expand Up @@ -123,7 +123,7 @@ pub struct Tokenizer {
}

impl Tokenizer {
pub fn from_file(filepath: &str) -> Result<Self, WasmedgeLLMErrno> {
pub fn from_file(filepath: &str) -> Result<Self, WasmedgeLLMCErrno> {
let mut tokenizer_id = MaybeUninit::<u32>::uninit();
unsafe {
let result = tokenizer_create(filepath, tokenizer_id.as_mut_ptr());
Expand Down
38 changes: 19 additions & 19 deletions wasmedge-llmc/src/llmc_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use core::fmt;
use std::error::Error;
#[repr(transparent)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct WasmedgeLLMErrno(u32);
pub const WASMEDGE_LLM_ERRNO_SUCCESS: WasmedgeLLMErrno = WasmedgeLLMErrno(0);
pub const WASMEDGE_LLM_ERRNO_INVALID_ARGUMENT: WasmedgeLLMErrno = WasmedgeLLMErrno(1);
pub const WASMEDGE_LLM_ERRNO_MISSING_MEMORY: WasmedgeLLMErrno = WasmedgeLLMErrno(2);
impl WasmedgeLLMErrno {
pub struct WasmedgeLLMCErrno(u32);
pub const WASMEDGE_LLM_ERRNO_SUCCESS: WasmedgeLLMCErrno = WasmedgeLLMCErrno(0);
pub const WASMEDGE_LLM_ERRNO_INVALID_ARGUMENT: WasmedgeLLMCErrno = WasmedgeLLMCErrno(1);
pub const WASMEDGE_LLM_ERRNO_MISSING_MEMORY: WasmedgeLLMCErrno = WasmedgeLLMCErrno(2);
impl WasmedgeLLMCErrno {
pub const fn raw(&self) -> u32 {
self.0
}
Expand All @@ -31,38 +31,38 @@ impl WasmedgeLLMErrno {
}
}
}
impl fmt::Debug for WasmedgeLLMErrno {
impl fmt::Debug for WasmedgeLLMCErrno {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("WasmedgeLLMErrno")
f.debug_struct("WasmedgeLLMCErrno")
.field("code", &self.0)
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
impl fmt::Display for WasmedgeLLMErrno {
impl fmt::Display for WasmedgeLLMCErrno {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} (error {})", self.name(), self.0)
}
}

impl Error for WasmedgeLLMErrno {}
impl Error for WasmedgeLLMCErrno {}

#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
impl std::error::Error for WasmedgeLLMErrno {}
impl std::error::Error for WasmedgeLLMCErrno {}

pub unsafe fn model_create(
checkpoint_path: &str,
model_id: *mut u32,
) -> Result<(), WasmedgeLLMErrno> {
) -> Result<(), WasmedgeLLMCErrno> {
let checkpoint_path_ptr = checkpoint_path.as_ptr() as u32;
let checkpoint_path_len = checkpoint_path.len() as u32;
let model_id_ptr = model_id as u32;
let result = wasmedge_llm::model_create(checkpoint_path_ptr, checkpoint_path_len, model_id_ptr);
if result != 0 {
Err(WasmedgeLLMErrno(result as u32))
Err(WasmedgeLLMCErrno(result as u32))
} else {
Ok(())
}
Expand All @@ -76,7 +76,7 @@ pub unsafe fn dataloader_create(
num_processes: u32,
should_shuffule: bool,
dataloader_id: *mut u32,
) -> Result<(), WasmedgeLLMErrno> {
) -> Result<(), WasmedgeLLMCErrno> {
let data_path_str = data_path.as_ptr() as u32;
let data_path_len = data_path.len() as u32;
let dataloader_id_ptr = dataloader_id as u32;
Expand All @@ -91,7 +91,7 @@ pub unsafe fn dataloader_create(
dataloader_id_ptr,
);
if result != 0 {
Err(WasmedgeLLMErrno(result as u32))
Err(WasmedgeLLMCErrno(result as u32))
} else {
Ok(())
}
Expand All @@ -100,13 +100,13 @@ pub unsafe fn dataloader_create(
pub unsafe fn tokenizer_create(
filepath: &str,
tokenizer_id: *mut u32,
) -> Result<(), WasmedgeLLMErrno> {
) -> Result<(), WasmedgeLLMCErrno> {
let filepath_ptr = filepath.as_ptr() as u32;
let filepath_len = filepath.len() as u32;
let tokenizer_id_ptr = tokenizer_id as u32;
let result = wasmedge_llm::tokenizer_create(filepath_ptr, filepath_len, tokenizer_id_ptr);
if result != 0 {
Err(WasmedgeLLMErrno(result as u32))
Err(WasmedgeLLMCErrno(result as u32))
} else {
Ok(())
}
Expand All @@ -121,7 +121,7 @@ pub unsafe fn model_train(
sequence_length: u32,
lr: f32,
epoch: u32,
) -> Result<(), WasmedgeLLMErrno> {
) -> Result<(), WasmedgeLLMCErrno> {
let result = wasmedge_llm::model_train(
model_id,
train_dataloader_id,
Expand All @@ -134,14 +134,14 @@ pub unsafe fn model_train(
);

if result != 0 {
Err(WasmedgeLLMErrno(result as u32))
Err(WasmedgeLLMCErrno(result as u32))
} else {
Ok(())
}
}

pub mod wasmedge_llm {
#[link(wasm_import_module = "wasi_llm")]
#[link(wasm_import_module = "wasmedge_llmc")]
extern "C" {
pub fn model_create(
checkpoint_path_ptr: u32,
Expand Down

0 comments on commit 7a27a85

Please sign in to comment.