Skip to content

Commit

Permalink
chore: see if it fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FL33TW00D committed Jan 26, 2024
1 parent 506b9dc commit 2e91106
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions crates/ratchet-core/src/ops/matmul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ def matmul(a, b):
let ground = ground_truth(&a, &b)?;

let device = Device::request_device(DeviceRequest::GPU)?;
let a_gpu = a.to(device.clone())?;
let b_gpu = b.to(device.clone())?;
let a_gpu = a.to(&device)?;
let b_gpu = b.to(&device)?;
let c_gpu = a_gpu.matmul(&b_gpu)?;
c_gpu.resolve()?;

let d_gpu = c_gpu.to(Device::CPU)?;
let d_gpu = c_gpu.to(&Device::CPU)?;
ground.all_close(&d_gpu, 1e-4, 1e-4)?;
Ok(())
}
Expand All @@ -370,11 +370,11 @@ def matmul(a, b):
let quantizer = Quantizer::new(Quantization::SInt8);
let bq = quantizer.sint8_quantize(b);
let device = Device::request_device(DeviceRequest::GPU)?;
let a_gpu = a.to(device.clone())?;
let b_gpu = bq.to(device.clone())?;
let a_gpu = a.to(&device)?;
let b_gpu = bq.to(&device)?;
let c_gpu = a_gpu.matmul(&b_gpu)?;
c_gpu.resolve()?;
let ours = c_gpu.to(Device::CPU)?;
let ours = c_gpu.to(&Device::CPU)?;

println!("RATCHET WQ8\n{:?}\n", ours);
println!("PYTORCH FP32:\n{:?}", ground);
Expand Down
4 changes: 2 additions & 2 deletions crates/ratchet-core/src/ops/softmax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def softmax(a):
let a = Tensor::randn::<f32>(shape![64, 64], Device::CPU);
let ground = ground_truth(&a)?;

let a_gpu = a.to(gpu_device.clone())?;
let a_gpu = a.to(&gpu_device)?;
let b = a_gpu.softmax(1)?;
b.resolve()?;
let ours = b.to(Device::CPU)?;
let ours = b.to(&Device::CPU)?;
println!("GROUND: \n{:?}", ground);
println!("OURS: \n{:?}", ours);
ground.all_close(&ours, 1e-6, 1e-6)?;
Expand Down
6 changes: 3 additions & 3 deletions crates/ratchet-core/src/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,10 @@ impl Tensor {
/// If the tensor is already on the specified device, it will be returned as-is,
/// and the underlying storage will not be copied.
/// If the tensor is on a different device, it will be copied to the specified device.
pub fn to(&self, device: Device) -> Result<Tensor, TensorError> {
match (self.device(), &device) {
pub fn to(&self, device: &Device) -> Result<Tensor, TensorError> {
match (self.device(), device) {
(Device::GPU(_), Device::CPU) => self.to_cpu(),
(Device::CPU, Device::GPU(_)) => self.to_gpu(&device),
(Device::CPU, Device::GPU(_)) => self.to_gpu(device),
_ => Ok(self.clone()),
}
}
Expand Down

0 comments on commit 2e91106

Please sign in to comment.