-
Notifications
You must be signed in to change notification settings - Fork 9
feat: 添加minicpm3模型缺失的算子 #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
onenewcode
wants to merge
7
commits into
YdrMaster:main
Choose a base branch
from
onenewcode:dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
120d30f
fix: 支持attention计算 q,k,v不相同的情况
onenewcode f4a83f7
feat: 添加Scale算子
onenewcode ab65dfa
fix: 添加更多rope
onenewcode 6989b92
feat: 添加mmla的吸收版本
onenewcode ab2c196
feat: 添加mla_cache
onenewcode 1e4b2f5
t
onenewcode 20f9c5a
finish
onenewcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ mod test { | |
seq.into(), | ||
att.into(), | ||
dyn_(), | ||
dyn_(), | ||
) | ||
} | ||
|
||
|
This file contains hidden or 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 hidden or 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 hidden or 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,125 @@ | ||
use crate::{ | ||
dyn_, | ||
fuesd_softmax::AttnMask, | ||
utils::{dim_distinct, rank_error, type_distinct}, | ||
ConstPtr, Hardware, MaybeDyn, MutPtr, SchemeError, TensorLayout, | ||
}; | ||
use digit_layout::DigitLayout; | ||
use std::ptr::{null, null_mut}; | ||
|
||
pub struct Args<H: Hardware> { | ||
// q传入的是是吸收后的 | ||
pub q_layout: TensorLayout, | ||
pub q_base: MutPtr<H>, | ||
|
||
pub kv_layout: TensorLayout, | ||
pub kv_base: ConstPtr<H>, | ||
|
||
pub absorb_layout: TensorLayout, | ||
pub absorb_base: ConstPtr<H>, | ||
|
||
pub qr_layout: TensorLayout, | ||
pub qr_base: ConstPtr<H>, | ||
|
||
pub kr_layout: TensorLayout, | ||
pub kr_base: ConstPtr<H>, | ||
|
||
pub o_layout: TensorLayout, | ||
pub o_base: MutPtr<H>, | ||
|
||
pub mask: AttnMask, | ||
} | ||
|
||
pub(super) struct Meta { | ||
pub dt: DigitLayout, | ||
pub nh: MaybeDyn<usize>, | ||
pub seq: MaybeDyn<usize>, | ||
pub att: MaybeDyn<usize>, | ||
pub dkv: MaybeDyn<usize>, | ||
pub dv: MaybeDyn<usize>, | ||
pub dr: MaybeDyn<usize>, | ||
} | ||
|
||
impl<H: Hardware> Args<H> { | ||
#[allow(clippy::too_many_arguments)] | ||
pub(crate) fn new_null( | ||
Check warningCode scanning / clippy associated function new_null is never used Warning
associated function new\_null is never used
|
||
mask: AttnMask, | ||
dt: DigitLayout, | ||
nh: MaybeDyn<usize>, | ||
dkv: MaybeDyn<usize>, | ||
seq: MaybeDyn<usize>, | ||
att: MaybeDyn<usize>, | ||
dv: MaybeDyn<usize>, | ||
dr: MaybeDyn<usize>, | ||
) -> Self { | ||
let q_layout = TensorLayout::new_dyn(dt, &[nh, seq, dkv], &[dyn_(); 3]); | ||
let kv_layout = TensorLayout::new_dyn(dt, &[nh, att, dkv], &[dyn_(); 3]); | ||
let absorb_layout = TensorLayout::new_dyn(dt, &[nh, dv, dkv], &[dyn_(); 3]); | ||
let qr_layout = TensorLayout::new_dyn(dt, &[nh, seq, dr], &[dyn_(); 3]); | ||
let kr_layout = TensorLayout::new_dyn(dt, &[nh, att, dr], &[dyn_(); 3]); | ||
let o_layout = TensorLayout::new_dyn(dt, &[nh, seq, dv], &[dyn_(); 3]); | ||
Self { | ||
q_layout, | ||
q_base: null_mut(), | ||
kv_layout, | ||
kv_base: null(), | ||
absorb_layout, | ||
absorb_base: null(), | ||
qr_layout, | ||
qr_base: null(), | ||
kr_layout, | ||
kr_base: null(), | ||
o_layout, | ||
o_base: null_mut(), | ||
mask, | ||
} | ||
} | ||
|
||
pub(super) fn meta(&self) -> Result<Meta, SchemeError> { | ||
let Self { | ||
q_layout, | ||
kv_layout, | ||
absorb_layout, | ||
qr_layout, | ||
kr_layout, | ||
o_layout, | ||
.. | ||
} = self; | ||
|
||
let &[nh_q, seq_q, dkv_q] = q_layout.shape() else { | ||
return Err(rank_error("q", 3, q_layout.ndim())); | ||
}; | ||
|
||
let &[nh_kv, attn_kv, dkv_kv] = kv_layout.shape() else { | ||
return Err(rank_error("kv", 3, kv_layout.ndim())); | ||
}; | ||
let &[nh_a, dv_a, dkv_a] = absorb_layout.shape() else { | ||
return Err(rank_error("absorb", 3, absorb_layout.ndim())); | ||
}; | ||
let &[nh_qr, seq_qr, dr_qr] = qr_layout.shape() else { | ||
return Err(rank_error("qr", 3, qr_layout.ndim())); | ||
}; | ||
let &[nh_kr, att_kr, dr_kr] = kr_layout.shape() else { | ||
return Err(rank_error("kr", 3, kr_layout.ndim())); | ||
}; | ||
let &[nh_o, seq_o, dv_o] = o_layout.shape() else { | ||
return Err(rank_error("o", 3, o_layout.ndim())); | ||
}; | ||
|
||
Ok(Meta { | ||
dt: type_distinct(&[ | ||
q_layout.dt(), | ||
kv_layout.dt(), | ||
qr_layout.dt(), | ||
kr_layout.dt(), | ||
o_layout.dt(), | ||
])?, | ||
nh: dim_distinct(&[nh_q, nh_kv, nh_a, nh_qr, nh_kr, nh_o])?, | ||
seq: dim_distinct(&[seq_q, seq_o, seq_qr])?, | ||
att: dim_distinct(&[attn_kv, att_kr])?, | ||
dkv: dim_distinct(&[dkv_a, dkv_kv, dkv_q])?, | ||
dv: dim_distinct(&[dv_a, dv_o])?, | ||
dr: dim_distinct(&[dr_kr, dr_qr])?, | ||
}) | ||
} | ||
} |
This file contains hidden or 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 @@ | ||
impl_op!(common_cpu, Cpu); |
This file contains hidden or 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 @@ | ||
impl_op!(cuda, Gpu); |
This file contains hidden or 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 @@ | ||
impl_op!(infini, Device); |
This file contains hidden or 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,26 @@ | ||
mod args; | ||
mod operator; | ||
|
||
pub use args::Args; | ||
|
||
crate::op_trait!(AttentionMLA); | ||
|
||
macro_rules! impl_op { | ||
($dev:ident, $proc:ident) => { | ||
pub type Operator = super::operator::Operator< | ||
crate::$dev::$proc, | ||
crate::mat_mul::$dev::Operator, | ||
crate::fuesd_softmax::$dev::Operator, | ||
crate::rearrange::$dev::Operator, | ||
>; | ||
}; | ||
} | ||
|
||
#[cfg(any(use_cpu, test))] | ||
pub mod common_cpu; | ||
#[cfg(use_cuda)] | ||
pub mod cuda; | ||
#[cfg(use_infini)] | ||
pub mod infini; | ||
#[cfg(use_cl)] | ||
pub mod opencl; |
This file contains hidden or 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 @@ | ||
impl_op!(opencl, ClDevice); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / clippy
associated function new_null is never used Warning