-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transformer): 抽取 transformer 平台无关部分到 crate
Signed-off-by: YdrMaster <[email protected]>
- Loading branch information
Showing
13 changed files
with
113 additions
and
102 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
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ authors = ["YdrMaster <[email protected]>"] | |
common = { path = "../common" } | ||
tensor = { path = "../tensor" } | ||
model-parameters = { path = "../model-parameters" } | ||
transformer = { path = "../transformer" } | ||
gemm = "0.17" | ||
|
||
[dev-dependencies] | ||
|
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
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ authors = ["YdrMaster <[email protected]>"] | |
common = { path = "../common" } | ||
tensor = { path = "../tensor" } | ||
model-parameters = { path = "../model-parameters" } | ||
transformer = { path = "../transformer" } | ||
cuda = { git = "https://github.com/YdrMaster/cuda-bench" } | ||
cublas = { git = "https://github.com/YdrMaster/cuda-bench" } | ||
half.workspace = true | ||
|
This file was deleted.
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
File renamed without changes.
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,12 @@ | ||
[package] | ||
name = "transformer" | ||
version = "0.0.0" | ||
edition = "2021" | ||
authors = ["YdrMaster <[email protected]>"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
common = { path = "../common" } | ||
tensor = { path = "../tensor" } | ||
model-parameters = { path = "../model-parameters" } |
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,54 @@ | ||
//! Common code for transformers. | ||
#![deny(warnings, missing_docs)] | ||
|
||
mod cache; | ||
|
||
use common::{upos, utok}; | ||
use tensor::udim; | ||
|
||
pub use cache::LayerCache; | ||
|
||
/// A request to decode a sequence. | ||
pub struct Request<'a, Storage> { | ||
/// Prompt of this request. | ||
pub prompt: Prompt<'a>, | ||
/// Context cache of this request. | ||
pub cache: &'a mut [LayerCache<Storage>], | ||
/// Position of `prompt` in context. | ||
pub pos: upos, | ||
} | ||
|
||
/// User prompt in transformer inference once. | ||
pub enum Prompt<'a> { | ||
/// Prefill the sequence with tokens. | ||
Prefill(&'a [utok]), | ||
/// Decode the next token. | ||
Decode(utok), | ||
} | ||
|
||
impl<S> Request<'_, S> { | ||
/// Tokens in the prompt. | ||
#[inline] | ||
pub const fn tokens(&self) -> &[utok] { | ||
match &self.prompt { | ||
Prompt::Prefill(tokens) => tokens, | ||
Prompt::Decode(token) => std::slice::from_ref(&token), | ||
} | ||
} | ||
|
||
/// Length of tokens in the prompt. | ||
#[inline] | ||
pub const fn seq_len(&self) -> udim { | ||
match self.prompt { | ||
Prompt::Prefill(tokens) => tokens.len() as _, | ||
Prompt::Decode(_) => 1, | ||
} | ||
} | ||
|
||
/// Length of tokens in attention computation. | ||
#[inline] | ||
pub const fn att_len(&self) -> udim { | ||
self.pos + self.seq_len() | ||
} | ||
} |
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