Skip to content

Commit

Permalink
20250102 amplify (#97)
Browse files Browse the repository at this point in the history
* update main.rs

* export ESM2 output

* fix log_softmax --> softmax
  • Loading branch information
zachcp authored Jan 2, 2025
1 parent 50930fa commit 92fbf3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ferritin-examples/examples/esm2-onnx/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ fn main() -> Result<()> {
let esm2 = ESM2::new(esm_model)?;
let protein = args.protein_string.as_ref().unwrap().as_str();
let logits = esm2.run_model(protein)?;
println!("Outputs: {:?}", logits);

let normed = esm2.extract_logits(&logits)?;
println!("{:?}", normed);
// println!("Normalized: {:?}", normed);

Ok(())
}
5 changes: 4 additions & 1 deletion ferritin-onnx-models/src/models/esm2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,17 @@ impl ESM2 {
)?;
let outputs =
model.run(ort::inputs!["input_ids" => tokens_array,"attention_mask" => mask_array]?)?;

let logits = outputs["logits"].try_extract_tensor::<f32>()?.to_owned();

Ok(ndarray_to_tensor_f32(logits)?)
}

// Softmax and simplify
pub fn extract_logits(&self, tensor: &Tensor) -> Result<Vec<LogitPosition>> {
let tensor = ops::log_softmax(tensor, D::Minus1)?;
let tensor = ops::softmax(tensor, D::Minus1)?;
let data = tensor.to_vec3::<f32>()?;
println!("Data: {:?}", data);
let shape = tensor.dims();
let mut logit_positions = Vec::new();
for seq_pos in 0..shape[1] {
Expand Down

0 comments on commit 92fbf3b

Please sign in to comment.