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

[Breaking] Refactor Backend Names #904

Merged
merged 28 commits into from
Oct 29, 2023
Merged

Conversation

nathanielsimard
Copy link
Member

@nathanielsimard nathanielsimard commented Oct 26, 2023

This refactor aims to improve the clarity of Burn when selecting a backend. Also, it aims to make it easier to create new backends without having to deal with unreadable associative types through the use of type aliases (FloatTensor, IntTensor, BoolTensor, FloatElem, IntElem, and Device).

There are breaking changes, but only for the naming. The type aliases don't break anything but simplify the process of creating new backends!

Also, some other changes are made to be more in line with the Rust way of naming things, namely having UpperCamelCase for acronyms and contractions, as well as for types.

  • ADBackend => AutodiffBackend
  • ADModule => AutodiffModule
  • ADTensor => AutodiffTensor
  • TestADBackend => TestAutodiffBackend
  • TestADTensor => TestAutodiffTensor
  • ADBackendDecorator => AutodiffDecorator

One of the main changes for backend names is to remove the Backend suffix, since the types are now available through burn::backend. Also, I think it's way cleaner to have Autodiff<LibTorch> than to have ADBackendDecorator<TchBackend>. The LibTorch change is also motivated by better clarity. Yes, we use tch for the bindings, but the most interesting part of the backend isn't the binding, but the code that is used!

I removed the re-exported backend type alias such as WgpuAutodiffBackend since now the name of the autodiff backend isn't as obscure as before. The biggest benefit is that users will have access to the actual documentation of the backend they use instead of the small doc on top of each alias.

The autodiff backend name ADBackendDecorator was bothering me for some time. Including the pattern in the name isn't something really bad in some cases, but we don't add a macro suffix to all macros or derive to all Derive, so I think it's better to emphasize the actual behavior that is added instead of the pattern used. I think it's more appropriate to describe the pattern in the documentation.

@nathanielsimard nathanielsimard marked this pull request as draft October 26, 2023 17:20
@antimora
Copy link
Collaborator

The description lacks mention of the fundamental rules or principles being followed. Please summarize all changes in terms of rules or principles, so others can easily follow and review your changes. This request stems from the fact that many people are accustomed to the previous convention, so adapting to the new changes will require a shift in both mindset and the code/APIs.

@nathanielsimard
Copy link
Member Author

The description lacks mention of the fundamental rules or principles being followed. Please summarize all changes in terms of rules or principles, so others can easily follow and review your changes. This request stems from the fact that many people are accustomed to the previous convention, so adapting to the new changes will require a shift in both mindset and the code/APIs.

Agreed! I'm still working on it after an earlier self-review. More descriptions and changes are expected to better follow the Rust naming conventions!

Copy link
Member

@louisfd louisfd left a comment

Choose a reason for hiding this comment

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

It's especially great when long lines like ADBackendDecorator<WgpuBackend<... become Autodiff<Wgpu<...
I also like the fact that the backend word is now reserved for traits only. It's very wordy to say that NdArrayBackend implements Backend, when NdArray implements Backend is enough

@@ -420,8 +419,7 @@ operation nodes.
The only remaining part is to implement our autodiff-decorated backend trait for our WGPUBackend.
Copy link
Member

Choose a reason for hiding this comment

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

We should write WGPU backend


#[cfg(feature = "std")]
#[cfg(test)]
pub type TestADBackend = burn_autodiff::ADBackendDecorator<TestBackend>;
pub type TestADBackend = burn_autodiff::Autodiff<TestBackend>;
Copy link
Member

Choose a reason for hiding this comment

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

I think we aim at changing every mention of 'AD'?

@nathanielsimard nathanielsimard marked this pull request as ready for review October 27, 2023 18:24
@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

Attention: 126 lines in your changes are missing coverage. Please review.

Comparison is base (e2a3329) 86.50% compared to head (14e8969) 86.49%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #904      +/-   ##
==========================================
- Coverage   86.50%   86.49%   -0.01%     
==========================================
  Files         471      471              
  Lines       44142    44217      +75     
==========================================
+ Hits        38183    38244      +61     
- Misses       5959     5973      +14     
Files Coverage Δ
burn-autodiff/src/backend.rs 76.19% <100.00%> (ø)
burn-autodiff/src/grads.rs 98.03% <100.00%> (ø)
burn-autodiff/src/graph/backward.rs 96.42% <100.00%> (ø)
burn-autodiff/src/ops/activation.rs 97.56% <100.00%> (ø)
burn-autodiff/src/ops/base.rs 94.28% <100.00%> (+0.34%) ⬆️
burn-autodiff/src/tensor.rs 93.75% <ø> (ø)
burn-autodiff/src/tests/abs.rs 100.00% <100.00%> (ø)
burn-autodiff/src/tests/adaptive_avgpool1d.rs 100.00% <100.00%> (ø)
burn-autodiff/src/tests/adaptive_avgpool2d.rs 100.00% <100.00%> (ø)
burn-autodiff/src/tests/add.rs 100.00% <100.00%> (ø)
... and 119 more

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

@nathanielsimard nathanielsimard merged commit 96524d4 into main Oct 29, 2023
9 checks passed
@nathanielsimard nathanielsimard deleted the refactor/backend-names branch October 29, 2023 22:27
@dcvz dcvz mentioned this pull request Nov 28, 2023
2 tasks
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.

3 participants