Skip to content
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

Remove htod, dtoh copy #3

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/logits_processor.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::{cmp::Ordering, collections::HashMap, iter::zip};

Check failure on line 1 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused imports: `cmp::Ordering`, `iter::zip`

Check warning on line 1 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

unused imports: `cmp::Ordering`, `iter::zip`

Check warning on line 1 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

unused imports: `cmp::Ordering`, `iter::zip`

Check warning on line 1 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

unused imports: `cmp::Ordering`, `iter::zip`

Check failure on line 1 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused imports: `cmp::Ordering`, `iter::zip`

Check warning on line 1 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

unused imports: `cmp::Ordering`, `iter::zip`

Check warning on line 1 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

unused imports: `cmp::Ordering`, `iter::zip`

Check warning on line 1 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

unused imports: `cmp::Ordering`, `iter::zip`

use candle_core::{bail, DType, Error, Result, Tensor};
use candle_core::{bail, DType, Device, Error, Result, Tensor, D};

Check failure on line 3 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused imports: `Device`, `Error`, `bail`

Check warning on line 3 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

unused imports: `Device`, `Error`, `bail`

Check warning on line 3 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

unused imports: `Device`, `Error`, `bail`

Check warning on line 3 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

unused imports: `Device`, `Error`, `bail`

Check failure on line 3 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused imports: `Device`, `Error`, `bail`

Check warning on line 3 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

unused imports: `Device`, `Error`, `bail`

Check warning on line 3 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

unused imports: `Device`, `Error`, `bail`

Check warning on line 3 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

unused imports: `Device`, `Error`, `bail`
use rand::{
distributions::{Distribution, WeightedIndex},

Check failure on line 5 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused imports: `Distribution`, `WeightedIndex`

Check warning on line 5 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

unused imports: `Distribution`, `WeightedIndex`

Check warning on line 5 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

unused imports: `Distribution`, `WeightedIndex`

Check warning on line 5 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

unused imports: `Distribution`, `WeightedIndex`

Check failure on line 5 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused imports: `Distribution`, `WeightedIndex`

Check warning on line 5 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

unused imports: `Distribution`, `WeightedIndex`

Check warning on line 5 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

unused imports: `Distribution`, `WeightedIndex`

Check warning on line 5 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

unused imports: `Distribution`, `WeightedIndex`
SeedableRng,
};
use serde::{Deserialize, Serialize};

Check failure on line 8 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused imports: `Deserialize`, `Serialize`

Check warning on line 8 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

unused imports: `Deserialize`, `Serialize`

Check warning on line 8 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

unused imports: `Deserialize`, `Serialize`

Check warning on line 8 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

unused imports: `Deserialize`, `Serialize`

Check failure on line 8 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused imports: `Deserialize`, `Serialize`

Check warning on line 8 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

unused imports: `Deserialize`, `Serialize`

Check warning on line 8 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

unused imports: `Deserialize`, `Serialize`

Check warning on line 8 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

unused imports: `Deserialize`, `Serialize`
use tokenizers::Tokenizer;

/// LogitsProcessor for sampling.
pub struct LogitsProcessor {
rng: rand::rngs::StdRng,

Check failure on line 13 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

multiple fields are never read

Check warning on line 13 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

multiple fields are never read

Check warning on line 13 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

multiple fields are never read

Check warning on line 13 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

multiple fields are never read

Check failure on line 13 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

multiple fields are never read

Check warning on line 13 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

multiple fields are never read

Check warning on line 13 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

multiple fields are never read

Check warning on line 13 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

multiple fields are never read
temperature: Option<f64>,
sampling_method: SamplingMethod,
top_n_logprobs: usize,
Expand All @@ -34,17 +34,17 @@
TopKP((usize, f64)),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone)]
// Top-n logprobs element
pub struct TopLogprob {
pub token: u32,
pub token: Tensor,
pub logprob: f32,
pub bytes: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone)]
pub struct Logprobs {
pub token: u32,
pub token: Tensor,
pub logprob: f32,
pub bytes: String,
pub top_logprobs: Vec<TopLogprob>,
Expand Down Expand Up @@ -79,7 +79,7 @@
}
}

fn apply_logit_bias(&self, probs: &mut [f32]) -> Result<()> {
/*fn apply_logit_bias(&self, probs: &mut [f32]) -> Result<()> {
if let Some(ref bias) = self.logits_bias {
for (id, bias_v) in bias {
let idx = probs.get_mut(*id as usize);
Expand Down Expand Up @@ -383,5 +383,15 @@
}
};
Ok(next_token)
}*/

pub fn sample(&mut self, logits: &Tensor, penalty_ctxt: Option<&Tensor>) -> Result<Logprobs> {

Check failure on line 388 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused variable: `penalty_ctxt`

Check warning on line 388 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

unused variable: `penalty_ctxt`

Check warning on line 388 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

unused variable: `penalty_ctxt`

Check warning on line 388 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

unused variable: `penalty_ctxt`

Check failure on line 388 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused variable: `penalty_ctxt`

Check warning on line 388 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

unused variable: `penalty_ctxt`

Check warning on line 388 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

unused variable: `penalty_ctxt`

Check warning on line 388 in src/logits_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite (windows-latest, stable)

unused variable: `penalty_ctxt`
let logits = logits.to_dtype(DType::F32)?;
Ok(Logprobs {
token: logits.argmax(D::Minus1)?,
logprob: 0.0,
bytes: "".to_string(),
top_logprobs: vec![],
})
}
}
Loading