Skip to content

Commit

Permalink
Add skeleton code for 4-bit quantization.
Browse files Browse the repository at this point in the history
The type is now recognized and I have a very simple quantizer too but no
operations are done yet.
  • Loading branch information
Noeda committed Mar 21, 2023
1 parent 26f343a commit f6249e8
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 57 deletions.
60 changes: 33 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod token_sampler;
pub mod tokenizer;
pub mod transformer;
pub mod unpickler;
pub mod weight_compression;
#[cfg(feature = "server")]
#[macro_use]
extern crate rocket;
38 changes: 38 additions & 0 deletions src/semaphore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// There is no semaphore in Rust standard library. wat??
// So I've made a simple one I can use out of a mutex and condition variable..

use std::sync::{Arc, Condvar, Mutex, MutexGuard};

#[derive(Clone)]
pub struct Semaphore {
count: Arc<Mutex<usize>>,
waiters: Arc<Condvar>,
}

pub struct SemaphoreGuard<'a> {
mutex_guard: MutexGuard<'a, usize>,
}

impl<'a> Drop for SemaphoreGuard<'a> {
fn drop(&mut self) {
*self.mutex_guard += 1;
}
}

impl Semaphore {
pub fn new(count: usize) -> Semaphore {
Semaphore {
count: Arc::new(Mutex::new(count)),
waiters: Arc::new(Condvar::new()),
}
}

pub fn acquire(&self) -> SemaphoreGuard {
let mut count = self.count.lock().unwrap();
while *count == 0 {
count = self.waiters.wait(count).unwrap();
}
*count -= 1;
SemaphoreGuard { mutex_guard: count }
}
}
Loading

0 comments on commit f6249e8

Please sign in to comment.