Skip to content

Commit

Permalink
chore: cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
FL33TW00D committed Jan 26, 2024
1 parent c66b991 commit 03f174b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
2 changes: 0 additions & 2 deletions crates/ratchet-core/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{rvec, Binary, CompiledOp, InvariantError, Matmul, RVec, Softmax, Sto

#[derive(Clone, Debug)]
pub enum LazyOp {
Dummy(Tensor),
Matmul(Matmul),
Binary(Binary),
Softmax(Softmax),
Expand All @@ -21,7 +20,6 @@ impl LazyOp {
LazyOp::Binary(b) => b.srcs(),
LazyOp::Matmul(m) => m.srcs(),
LazyOp::Softmax(s) => s.srcs(),
LazyOp::Dummy(t) => rvec![t],
LazyOp::Const => rvec![], //end of the line kid
_ => unimplemented!(),
}
Expand Down
36 changes: 10 additions & 26 deletions crates/ratchet-core/src/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ impl Tensor {
Self::new(op, meta, None, device)
}

pub fn dummy(src: Tensor) -> Self {
Self::new(
LazyOp::Dummy(src),
StorageView::new(shape![], DType::F32, Strides::default()),
None,
Device::CPU,
)
}

fn update_storage(&self, storage: Storage) {
*self.inner.storage.write() = Some(storage);
}
Expand Down Expand Up @@ -298,19 +289,14 @@ impl Tensor {
if visited.contains(&tensor) {
continue;
}
match &tensor.inner.op {
LazyOp::Const => {}
LazyOp::Binary(b) => {
stack.extend(b.srcs().into_iter().cloned());
}
LazyOp::Matmul(m) => {
stack.extend(m.srcs().into_iter().cloned());
}
LazyOp::Softmax(s) => {
stack.extend(s.srcs().into_iter().cloned());
}
let srcs = match &tensor.inner.op {
LazyOp::Const => rvec![],
LazyOp::Binary(b) => b.srcs(),
LazyOp::Matmul(m) => m.srcs(),
LazyOp::Softmax(s) => s.srcs(),
_ => unimplemented!(),
}
};
stack.extend(srcs.into_iter().cloned());
visited.push(tensor);
}
visited.reverse();
Expand Down Expand Up @@ -352,6 +338,7 @@ impl Tensor {
t.update_storage(Storage::GPU(storage));
}

//Can inplace && only 1 consumer
let can_inplace = t.op().supports_inplace()
&& execution_order[tix + 1..]
.iter()
Expand Down Expand Up @@ -469,6 +456,7 @@ impl Tensor {
}
}

#[derive(Default)]
struct CloseStats {
total_error: f32,
max_abs_error: f32,
Expand All @@ -482,13 +470,9 @@ struct CloseStats {
impl CloseStats {
fn new(atol: f32, rtol: f32) -> Self {
Self {
total_error: 0.0,
max_abs_error: 0.0,
max_abs_error_idxs: None,
element_count: 0,
fail_count: 0,
atol,
rtol,
..Default::default()
}
}

Expand Down

0 comments on commit 03f174b

Please sign in to comment.