Skip to content
Merged
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
5 changes: 5 additions & 0 deletions candle-core/src/backprop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,11 @@ impl GradStore {
self.0.insert(tensor.id(), grad)
}

/// Insert a gradient tensor associated with the given tensor id, returning the previous gradient tensor if it existed
pub fn insert_id(&mut self, id: TensorId, grad: Tensor) -> Option<Tensor> {
self.0.insert(id, grad)
}

/// Get the gradient tensor associated with the given tensor, or, if it does not exist,
/// insert a tensor of zeroes, with the same shape and type as the given tensors and return it
fn or_insert(&mut self, tensor: &Tensor) -> Result<&mut Tensor> {
Expand Down
Loading