Skip to content

Commit 8e7e581

Browse files
committed
fix Tensor::ones for fp8
1 parent 5db2349 commit 8e7e581

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

candle-core/src/cpu_backend/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,6 +2656,7 @@ impl BackendStorage for CpuStorage {
26562656
(Self::U8(storage), Scalar::U8(v)) => set(storage, l, v),
26572657
(Self::U32(storage), Scalar::U32(v)) => set(storage, l, v),
26582658
(Self::I64(storage), Scalar::I64(v)) => set(storage, l, v),
2659+
(Self::F8E4M3(storage), Scalar::F8E4M3(v)) => set(storage, l, v),
26592660
(st, s) => crate::bail!(
26602661
"const_set dtype mismatch, expected {:?} but got {:?}",
26612662
st.dtype(),

candle-core/tests/tensor_tests.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use candle_core::{test_device, test_utils, DType, Device, IndexOp, Result, Tensor, D};
2+
use float8::F8E4M3;
23

34
fn zeros(device: &Device) -> Result<()> {
45
let tensor = Tensor::zeros((5, 2), DType::F32, device)?;
@@ -61,6 +62,22 @@ fn ones(device: &Device) -> Result<()> {
6162
]
6263
],
6364
);
65+
66+
assert_eq!(
67+
Tensor::ones((2, 3), DType::F8E4M3, device)?.to_vec2::<F8E4M3>()?,
68+
[
69+
[
70+
F8E4M3::from_f32(1.),
71+
F8E4M3::from_f32(1.),
72+
F8E4M3::from_f32(1.)
73+
],
74+
[
75+
F8E4M3::from_f32(1.),
76+
F8E4M3::from_f32(1.),
77+
F8E4M3::from_f32(1.)
78+
]
79+
],
80+
);
6481
Ok(())
6582
}
6683

0 commit comments

Comments
 (0)