Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove precision bridge and complete float_cast implementation for ndarray #2538

Merged
merged 6 commits into from
Nov 28, 2024

Conversation

laggui
Copy link
Member

@laggui laggui commented Nov 25, 2024

Checklist

  • Confirmed that run-checks all script has been executed.
  • Made sure the book is up to date with changes in this PR.

Related Issues/PRs

#2483 #2511

Changes

  • Removed backend bridge (redundant now that we have tensor.cast(dtype)
  • Added public tensor.dtype() method (helpful to perform to/from a type, e.g. full precision usage)
  • Implemented float_cast for ndarray backend
    • Changed primitive to NdArrayTensorFloat enum
    • Refactored float ops to use execute_with_float_dtype macro which handles ops w/ generics based on the float enum variant

Testing

Cast unit test + float ops unit tests

- Change primitive to `NdArrayTensorFloat` enum
- Use `execute_with_float_dtype` macro to handle ops w/ generics based on the float enum variant
Copy link

codecov bot commented Nov 25, 2024

Codecov Report

Attention: Patch coverage is 93.70748% with 37 lines in your changes missing coverage. Please review.

Project coverage is 82.56%. Comparing base (fe3e43a) to head (8779f46).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
crates/burn-ndarray/src/ops/tensor.rs 92.90% 22 Missing ⚠️
crates/burn-ndarray/src/ops/int_tensor.rs 40.00% 6 Missing ⚠️
crates/burn-ndarray/src/tensor.rs 77.27% 5 Missing ⚠️
crates/burn-ndarray/src/ops/bool_tensor.rs 75.00% 1 Missing ⚠️
crates/burn-ndarray/src/ops/module.rs 99.40% 1 Missing ⚠️
crates/burn-ndarray/src/ops/qtensor.rs 88.88% 1 Missing ⚠️
crates/burn-remote/src/server/base.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #2538    +/-   ##
========================================
  Coverage   82.56%   82.56%            
========================================
  Files         827      822     -5     
  Lines      106855   106964   +109     
========================================
+ Hits        88226    88320    +94     
- Misses      18629    18644    +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@laggui laggui marked this pull request as ready for review November 25, 2024 20:12
Comment on lines 343 to 355
// pub(crate) fn cast_to<O: Element>(self) -> NdArrayTensor<O> {
// let array = self.array.mapv(|a| a.elem()).into_shared();

// NdArrayTensor::new(array)
// }

// pub(crate) fn to_float(self) -> NdArrayTensorFloat {
// match E::dtype() {
// DType::F64 => NdArrayTensorFloat::F64(self.cast_to()),
// DType::F32 => NdArrayTensorFloat::F32(self.cast_to()),
// _ => unimplemented!("Invalid float type"),
// }
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code detector on point, as always 😄

@nathanielsimard nathanielsimard merged commit 33cbb3b into main Nov 28, 2024
11 checks passed
@nathanielsimard nathanielsimard deleted the refactor/precision-bridge branch November 28, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants