Skip to content

Commit

Permalink
Merge pull request #1359 from sonos/task/improve-f32-to-f16
Browse files Browse the repository at this point in the history
Add cast op conversion from f32 to f16
  • Loading branch information
kali authored Mar 25, 2024
2 parents 9180657 + ab4c92f commit 000196a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::internal::translator::Translate;
use crate::internal::*;
use crate::ops::array::{Pad, PadMode};
use crate::ops::einsum::EinSum;
use crate::ops::cast::Cast;
use crate::ops::konst::Const;
use crate::ops::scan::Scan;
use crate::ops::source::TypedSource;
Expand Down Expand Up @@ -39,6 +40,12 @@ impl<T1: Datum + Float, T2: Datum + Float>
Box::new(TypedSource::new(fact_float_precision_conversion::<T1, T2>(&source.fact)))
} else if let Some(konst) = node.op_as::<Const>() {
Box::new(Const(tensor_float_precision_conversion::<T1, T2>(&konst.0)))
} else if let Some(cast) = node.op_as::<Cast>() {
if cast.to == T1::datum_type() {
Box::new(Cast { to: T2::datum_type() })
} else {
node.op.clone()
}
} else if let Some(op) = node.op_as::<Scan>() {
let body = FloatPrecisionTranslator::<T1, T2>::default().translate_model(&op.body)?;
Box::new(Scan { body, ..op.clone() })
Expand Down

0 comments on commit 000196a

Please sign in to comment.