Skip to content

Commit

Permalink
feat(xtask): convert 支持合并权重矩阵
Browse files Browse the repository at this point in the history
Signed-off-by: YdrMaster <ydrml@hotmail.com>
  • Loading branch information
YdrMaster committed Aug 15, 2024
1 parent 44ee36a commit 80a6330
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 51 deletions.
2 changes: 2 additions & 0 deletions xtask/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ impl ConvertArgs {
Operator::cast(content)
} else if let Some(content) = op.strip_prefix("transpose:") {
Operator::transpose_linear(content)
} else if let Some(content) = op.strip_prefix("merge:") {
Operator::merge_linear(content)
} else {
panic!("Unsupported operation: {}", op)
}
Expand Down
6 changes: 6 additions & 0 deletions xtask/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ enum DataPromise<'a> {
Lazy(Arc<dyn LazyData + Send + Sync + 'a>),
}

impl<'a> DataPromise<'a> {
fn lazy(f: impl FnOnce() -> MmapMut + Send + Sync + 'a) -> Self {
Self::Lazy(Arc::new(LazyLock::new(f)))
}
}

impl ggus::DataFuture for DataPromise<'_> {
#[inline]
fn get(&self) -> &[u8] {
Expand Down
5 changes: 2 additions & 3 deletions xtask/src/utils/operator/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterato
use std::{
alloc::Layout,
slice::{from_raw_parts, from_raw_parts_mut},
sync::{Arc, LazyLock},
};

impl Operator {
Expand All @@ -31,15 +30,15 @@ impl Content<'_> {
let data = tensor.data.clone();

tensor.ty = ty;
tensor.data = DataPromise::Lazy(Arc::new(LazyLock::new(move || {
tensor.data = DataPromise::lazy(move || {
use GGmlType as Ty;
let data = data.get();
match (from, to) {
(Ty::F32, Ty::F16) => cast(data, |&x| f16::from_f32(x)),
(Ty::F16, Ty::F32) => cast(data, |&x| f16::to_f32(x)),
(_, _) => todo!("unsupported cast: {from:?} -> {to:?}"),
}
})));
});
}
}

Expand Down
Loading

0 comments on commit 80a6330

Please sign in to comment.