Skip to content

Add tensor quantization #1963

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

Merged
merged 13 commits into from
Jul 8, 2024
Merged

Add tensor quantization #1963

merged 13 commits into from
Jul 8, 2024

Conversation

laggui
Copy link
Member

@laggui laggui commented Jul 3, 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

Progress towards #464

Changes

Support for static per-tensor quantization.

  • Added new DType::QFloat
  • Added backend trait associative type QuantizedTensorPrimitive
  • Added QTensorOps for quantize/dequantize ops
  • Added TensorPrimitive enum for float tensors to include float and qfloat (quantized type)
    • All existing float ops now automatically retrieve the .tensor() (dequantized) before calling the backend implementation on the FloatTensorPrimitive
  • Added QuantizationStrategy enum with per-tensor affine and symmetric int8 quantization

Note: QAT support should be added in a future PR

Testing

Added unit tests for affine and symmetric per-tensor quantization

Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 69.59707% with 249 lines in your changes missing coverage. Please review.

Project coverage is 85.15%. Comparing base (1ad2a63) to head (1a224c2).

Files Patch % Lines
crates/burn-tensor/src/tensor/data.rs 9.75% 37 Missing ⚠️
...es/burn-tensor/src/tensor/quantization_strategy.rs 75.00% 33 Missing ⚠️
crates/burn-ndarray/src/ops/qtensor.rs 0.00% 29 Missing ⚠️
crates/burn-tch/src/ops/qtensor.rs 0.00% 29 Missing ⚠️
crates/burn-tensor/src/tensor/api/autodiff.rs 45.71% 19 Missing ⚠️
crates/burn-autodiff/src/ops/qtensor.rs 0.00% 16 Missing ⚠️
crates/burn-candle/src/ops/qtensor.rs 0.00% 16 Missing ⚠️
crates/burn-fusion/src/ops/qtensor.rs 0.00% 16 Missing ⚠️
crates/burn-jit/src/ops/qtensor.rs 0.00% 16 Missing ⚠️
crates/burn-autodiff/src/backend.rs 0.00% 10 Missing ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1963      +/-   ##
==========================================
- Coverage   85.29%   85.15%   -0.15%     
==========================================
  Files         798      804       +6     
  Lines       95512    96050     +538     
==========================================
+ Hits        81471    81788     +317     
- Misses      14041    14262     +221     

☔ 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 July 3, 2024 21:53
@laggui laggui requested a review from nathanielsimard July 3, 2024 21:53
Copy link
Member

@nathanielsimard nathanielsimard left a comment

Choose a reason for hiding this comment

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

Some comments, but LGTM great job!

Comment on lines 90 to 96
TensorPrimitive::Float(B::inner(tensor.tensor()))
}

fn from_inner<const D: usize>(
inner: <Self::InnerKind as TensorKind<<B as AutodiffBackend>::InnerBackend>>::Primitive<D>,
) -> <Self as TensorKind<B>>::Primitive<D> {
B::from_inner(inner)
TensorPrimitive::Float(B::from_inner(inner.tensor()))
Copy link
Member

Choose a reason for hiding this comment

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

We will need to implement a q_inner and q_from_inner at some point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, this should be fairly straightforward. I'll add it.

@laggui
Copy link
Member Author

laggui commented Jul 4, 2024

Not sure what's up with the wgpu tests, they seem to be failing intermittently even on main

error: test failed, to rerun pass `-p burn-wgpu --lib`
  
  Caused by:
    process didn't exit successfully: `/home/runner/work/burn/burn/target/debug/deps/burn_wgpu-c73d9b81b38abf9c --color=always` (signal: 11, SIGSEGV: invalid memory reference)

@nathanielsimard
Copy link
Member

Not sure what's up with the wgpu tests, they seem to be failing intermittently even on main

error: test failed, to rerun pass `-p burn-wgpu --lib`
  
  Caused by:
    process didn't exit successfully: `/home/runner/work/burn/burn/target/debug/deps/burn_wgpu-c73d9b81b38abf9c --color=always` (signal: 11, SIGSEGV: invalid memory reference)

Working on it

@laggui laggui force-pushed the feat/quant/tensor branch from 84d8ee7 to 1a224c2 Compare July 5, 2024 14:18
@laggui laggui merged commit c0211e2 into main Jul 8, 2024
12 checks passed
@laggui laggui deleted the feat/quant/tensor branch July 8, 2024 14:17
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