Skip to content

Commit

Permalink
Enable native sign operation for Candle backend (#1647)
Browse files Browse the repository at this point in the history
* Enable native sign operation for Candle backend

* Use fixed revision
  • Loading branch information
antimora authored Apr 17, 2024
1 parent 4240332 commit 2a721a9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ license = "MIT OR Apache-2.0"
[workspace.dependencies]
async-trait = "0.1.80"
bytemuck = "1.14"
candle-core = { version = "0.4.1" }
# candle-core = { version = "0.4.1" }
candle-core = { git = "https://github.com/huggingface/candle.git", rev = "2817643" }
clap = { version = "4.5.4", features = ["derive"] }
colored = "2.1.0"
console_error_panic_hook = "0.1.7"
Expand Down
4 changes: 4 additions & 0 deletions crates/burn-candle/src/ops/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,7 @@ pub fn expand<E: CandleElement, const D1: usize, const D2: usize>(
) -> CandleTensor<E, D2> {
CandleTensor::new(tensor.tensor.broadcast_as(&shape.dims).unwrap())
}

pub fn sign<E: CandleElement, const D: usize>(tensor: CandleTensor<E, D>) -> CandleTensor<E, D> {
CandleTensor::new(tensor.tensor.sign().unwrap())
}
7 changes: 4 additions & 3 deletions crates/burn-candle/src/ops/int_tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
Candle, CandleTensor,
};

use super::base::{expand, permute};
use super::base::{expand, permute, sign};

impl<F: FloatCandleElement, I: IntCandleElement> IntTensorOps<Self> for Candle<F, I> {
fn int_empty<const D: usize>(shape: Shape<D>, device: &Device<Self>) -> IntTensor<Self, D> {
Expand Down Expand Up @@ -447,6 +447,7 @@ impl<F: FloatCandleElement, I: IntCandleElement> IntTensorOps<Self> for Candle<F
expand(tensor, shape)
}

// TODO add sign operator once Candle supports it:
// https://github.com/huggingface/candle/issues/1827
fn int_sign<const D: usize>(tensor: IntTensor<Self, D>) -> IntTensor<Self, D> {
sign(tensor)
}
}
7 changes: 4 additions & 3 deletions crates/burn-candle/src/ops/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
Candle, CandleTensor,
};

use super::base::{expand, permute};
use super::base::{expand, permute, sign};

impl<F: FloatCandleElement, I: IntCandleElement> FloatTensorOps<Self> for Candle<F, I> {
fn float_from_data<const D: usize>(
Expand Down Expand Up @@ -539,6 +539,7 @@ impl<F: FloatCandleElement, I: IntCandleElement> FloatTensorOps<Self> for Candle
expand(tensor, shape)
}

// TODO add sign operator once Candle supports it:
// https://github.com/huggingface/candle/issues/1827
fn float_sign<const D: usize>(tensor: FloatTensor<Self, D>) -> FloatTensor<Self, D> {
sign(tensor)
}
}

0 comments on commit 2a721a9

Please sign in to comment.