Skip to content

Commit

Permalink
More utils for ModelOutput.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryscan committed Feb 4, 2024
1 parent f6bef59 commit 1f4c531
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "web-rwkv"
version = "0.6.1"
version = "0.6.2"
edition = "2021"
authors = ["Zhenyuan Zhang <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ where
// run initial prompt
loop {
let logits = model.run(&mut tokens, &state).await?;
if logits.iter().any(|x| matches!(x, ModelOutput::Last(_))) {
if logits.iter().any(ModelOutput::is_some) {
break;
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ where
loop {
let mut logits = loop {
let logits = model.run(&mut tokens, &state).await?;
if logits.iter().any(|x| matches!(x, ModelOutput::Last(_))) {
if logits.iter().any(ModelOutput::is_some) {
break logits;
}
};
Expand Down
2 changes: 1 addition & 1 deletion examples/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ async fn run(cli: Cli) -> Result<()> {
// run initial prompt
let logits = loop {
let logits = model.run_with_hooks(&mut tokens, &state, &hooks).await?;
if logits.iter().any(|x| matches!(x, ModelOutput::Last(_))) {
if logits.iter().any(ModelOutput::is_some) {
break logits;
}
};
Expand Down
8 changes: 8 additions & 0 deletions src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ pub enum ModelOutput {
}

impl ModelOutput {
pub fn is_none(&self) -> bool {
matches!(self, Self::None)
}

pub fn is_some(&self) -> bool {
!self.is_none()
}

pub fn concat(self, other: Self) -> Self {
match (self, other) {
(Self::None, y) => y,
Expand Down

0 comments on commit 1f4c531

Please sign in to comment.