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

Add float cast tensor op #2483

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Add float cast tensor op #2483

wants to merge 10 commits into from

Conversation

laggui
Copy link
Member

@laggui laggui commented Nov 12, 2024

Checklist

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

Changes

Add tensor.cast(dtype) op for floating point casting to different precision types.

Currently implemented for candle and tch. Had to remove the element type generic on both tensor primitives for this change.

Will be implemented in a follow-up PR for: burn-ndarray, burn-jit, burn-fusion and burn-router.

Important: handling different floating point precision types in operations between multiple tensors might require automatic type promotion based on a selected strategy (e.g., cast to the higher precision type like torch). This is not in the current scope, instead backends can panic with a dtype mismatch.

Testing

Added a unit test.

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 38.93443% with 298 lines in your changes missing coverage. Please review.

Project coverage is 82.85%. Comparing base (a4567db) to head (1018228).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/burn-tch/src/ops/int_tensor.rs 18.07% 68 Missing ⚠️
crates/burn-tch/src/ops/module.rs 3.22% 60 Missing ⚠️
crates/burn-tch/src/ops/tensor.rs 54.23% 54 Missing ⚠️
crates/burn-tch/src/ops/base.rs 52.05% 35 Missing ⚠️
crates/burn-tch/src/ops/bool_tensor.rs 30.76% 18 Missing ⚠️
crates/burn-tensor/src/tests/ops/cast.rs 0.00% 9 Missing ⚠️
crates/burn-tensor/src/tensor/element/base.rs 0.00% 8 Missing ⚠️
crates/burn-candle/src/ops/base.rs 83.33% 7 Missing ⚠️
crates/burn-candle/src/ops/tensor.rs 57.14% 6 Missing ⚠️
crates/burn-tensor/src/tensor/api/float.rs 0.00% 6 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2483      +/-   ##
==========================================
- Coverage   82.97%   82.85%   -0.13%     
==========================================
  Files         812      814       +2     
  Lines      105212   105351     +139     
==========================================
- Hits        87304    87288      -16     
- Misses      17908    18063     +155     

☔ 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 14, 2024 19:01
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.

1 participant