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

started the burn developer book #1184

Merged
merged 33 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
260f93b
started the burn developer book
skewballfox Jan 26, 2024
d9a637f
forgot to enable mathjax for mdbook
skewballfox Jan 26, 2024
8fc11bb
copied the contents of architecture.md, and fleshing things out
skewballfox Jan 26, 2024
c1b4dae
fixed issue with inline mathjax
skewballfox Jan 26, 2024
e2738a8
fixed typos, added instructions
skewballfox Jan 26, 2024
79c29c6
updating info on tensorops, fixing typos
skewballfox Jan 27, 2024
cc93bab
added test for powf, fixed typos, updated index, etc
skewballfox Jan 27, 2024
fb64d11
fixed issue with burn-wgpu 0^0
skewballfox Jan 28, 2024
bcc232e
formatting
skewballfox Jan 28, 2024
227a5ea
updated section for adding ops to wgpu
skewballfox Jan 28, 2024
9ea4498
changed powf_scalar to powf_primitive for wgpu code
skewballfox Jan 29, 2024
15c0212
Update contributor-book/src/getting-started/testing.md
skewballfox Jan 29, 2024
f408eff
Update contributor-book/src/guides/adding-a-new-operation-to-burn.md
skewballfox Jan 29, 2024
b4f84d0
Update contributor-book/src/guides/adding-a-new-operation-to-burn.md
skewballfox Jan 29, 2024
151f444
Update contributor-book/src/getting-started/testing.md
skewballfox Jan 29, 2024
8c67766
Update contributor-book/src/getting-started/testing.md
skewballfox Jan 29, 2024
b312607
Update contributor-book/src/getting-started/setting-up-the-environmen…
skewballfox Jan 29, 2024
5ac299a
implementeds suggestions by @syl20bnr
skewballfox Jan 29, 2024
c4ee85b
fixed typography
skewballfox Jan 29, 2024
f63a79d
Apply suggestions from code review
skewballfox Jan 29, 2024
07db8ad
fixed typos, and incorrect rendering of footnotes
skewballfox Jan 29, 2024
1f89007
Format the text using prettier
antimora Jan 31, 2024
20057bf
implemented suggestions
skewballfox Jan 31, 2024
f0ba1d2
implemented suggestion
skewballfox Jan 31, 2024
418a08a
Merge branch 'main' into contributor-book
skewballfox Feb 1, 2024
3ea3219
updated testing autodiff section
skewballfox Feb 1, 2024
2739781
fixed typo
skewballfox Feb 1, 2024
5d06209
Apply suggestions from code review
skewballfox Feb 2, 2024
726d232
fixes related to code review
skewballfox Feb 2, 2024
e9ee469
added links to discord server
skewballfox Feb 2, 2024
c1f6304
fixed a typo in the book xtask and implemented changes from code review
skewballfox Feb 2, 2024
b3e84ef
implemented suggestions from code reviews
skewballfox Feb 2, 2024
6d9c783
implemented suggestions from code review
skewballfox Feb 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions contributor-book/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
target

# MacOS temp file
.DS_Store

book-test
guide/book

.vscode
tests/burn-book/book/
book/

# Ignore Jetbrains specific files.
.idea/

# Ignore Vim temporary and swap files.
*.sw?
*~
4 changes: 4 additions & 0 deletions contributor-book/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 100,
"proseWrap": "always"
}
1 change: 1 addition & 0 deletions contributor-book/LICENSE-APACHE
1 change: 1 addition & 0 deletions contributor-book/LICENSE-MIT
16 changes: 16 additions & 0 deletions contributor-book/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[book]
authors = [
"Wouter Doppenberg",
"Nathaniel Simard",
"Louis Fortier-Dubois",
"Dilshod Tadjibaev",
"Guillaume Lagrange",
"Joshua Ferguson",
skewballfox marked this conversation as resolved.
Show resolved Hide resolved
]
language = "en"
multilingual = false
src = "src"
title = "The Burn Developer Book 🔥"
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

[output.html]
mathjax-support = true
14 changes: 14 additions & 0 deletions contributor-book/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- [Overview](./overview.md)
- [How to Read This Book](./how-to-read-this-book.md)
- [Getting Started](./getting-started/ReadMe.md)
- [setting up the environment](./getting-started/setting-up-the-environment.md)
- [configuring your editor(optional)](./getting-started/configuring-your-editor.md)
- [testing](./getting-started/testing.md)
skewballfox marked this conversation as resolved.
Show resolved Hide resolved
- [Architecture Overview](./project-architecture/ReadMe.md)
- [Modules](./project-architecture/module.md)
- [Serialization](./project-architecture/serialization.md)
- [Tensor](./project-architecture/tensor.md)
- [Backend](./project-architecture/backend.md)
- [Guides for Contributors](./guides/ReadMe.md)
- [adding a new operation to burn](./guides/adding-a-new-operation-to-burn.md)
skewballfox marked this conversation as resolved.
Show resolved Hide resolved
- [Issue related to adding operators](./frequently-encountered-issues/issues-while-adding-ops.md)
3 changes: 3 additions & 0 deletions contributor-book/src/frequently-encountered-issues/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Frequently Encountered Issues

This is a collection of issues people have encountered and asked about on the discord, and is separate from the guides since it often involves a wall of text that is only relevant to a small subset of contributors.
skewballfox marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Issues encountered while adding ops

Most issues were fairly straight forward, and I was able to play whack-a-bug until I hit ones were I needed outside help (on the discord channels), so I'll share some of the ones that had me stumped enough to ask for help in case you too encounter them.

## Off by .000001 errors

```sh
---- fusion::base::tests::maxmin::tests::test_mean_dim_2d stdout ---- thread 'fusion::base::tests::maxmin::tests::test_mean_dim_2d' panicked at burn-wgpu/src/fusion/base.rs:185:5: assertion `left == right` failed left: Data { value: [1.0, 4.0], shape: Shape { dims: [2, 1] } } right: Data { value: [0.99999994, 3.9999998], shape: Shape { dims: [2, 1] } } ----

tests::maxmin::tests::test_mean_dim_2d stdout ---- thread 'tests::maxmin::tests::test_mean_dim_2d' panicked at burn-wgpu/src/lib.rs:49:5: assertion `left == right` failed left: Data { value: [1.0, 4.0], shape: Shape { dims: [2, 1] } } right: Data { value: [0.99999994, 3.9999998], shape: Shape { dims: [2, 1] } }
```

If you encounter this, swap out the `assert_eq!` in the failing test for `tensor1.assert_approx_eq` with `3` as the second argument.

## Mismatched types and missing functions

```sh
error[E0308]: mismatched types --> {burn_dir}/target/debug/build/onnx-tests-fed12aaf3671687f/out/model/pow.rs:48:45 | 48 | let pow1_out1 = input1.clone().powf(input1); | ---- ^^^^^^ expected `f32`, found `Tensor<B, 4>` | | | arguments to this method are incorrect | = note: expected type `f32` found struct `Tensor<B, 4>`

note: method defined here --> {burn_dir}/burn-tensor/src/tensor/api/float.rs:65:12 | 65 | pub fn powf(self, value: f32) -> Self { | ^^^^

error[E0599]: no method named `powf_scalar` found for struct `Tensor` in the current scope --> {burn_dir}/target/debug/build/onnx-tests-fed12aaf3671687f/out/model/pow.rs:50:35 | 50 | let pow2_out1 = pow1_out1.powf_scalar(cast1_out1); | ^^^^^^^^^^^ method not found in `Tensor<B, 4>`

error[E0599]: no method named `powi` found for struct `Tensor` in the current scope --> {burn_dir}/target/debug/build/onnx-tests-fed12aaf3671687f/out/model/pow_int.rs:49:40 | 49 | let pow1_out1 = input1.clone().powi(input1); | ^^^^ method not found in `Tensor<B, 4, Int>` Some errors have detailed explanations: E0308, E0599.
For more information about an error, try `rustc --explain E0308`. error: could not compile `onnx-tests` (test "onnx_tests") due to 3 previous errors
```

So if you are getting this, you probably didn't impl your operator for the actual Tensor struct. I wasn't aware of the existence or role of `burn-tensor/src/tensor/api/numeric.rs`, and had first defined just the Ops for the Int and Float tensors, that coupled with `powf` existing prior to the PR though for scalar values(which had been renamed, just not in the right place), led to this confusing issue where it looked like the function was found, but the type was wrong. If that's the case, make sure that it's implemented for the appropriate type, in this case `Float` under [burn-tensor/src/tensor/api/numeric.rs](https://github.com/tracel-ai/burn/blob/4ca3e31601228952bb1c1492bc9cd2adf15b5cf1/burn-tensor/src/tensor/api/numeric.rs#L2186), and calling the `TensorOp.foo_op` defined under [burn-tensor/src/ops/tensor.rs](https://github.com/tracel-ai/burn/blob/4ca3e31601228952bb1c1492bc9cd2adf15b5cf1/burn-tensor/src/tensor/ops/tensor.rs#L873)
skewballfox marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions contributor-book/src/getting-started/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Getting Started
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

This section is for setting up the environment and how to do basic development tasks such as running tests and checking your code before committing.
24 changes: 24 additions & 0 deletions contributor-book/src/getting-started/configuring-your-editor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Configuring your editor

These are not required, and most of this isn't specific to Burn, but it's definitely helpful if you haven't already done it.

## VSCode

1. Install the following extensions:

- [rust-lang.rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
- [tamasfe.even-better-toml](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml)
- [serayuzgur.crates](https://marketplace.visualstudio.com/items?itemName=serayuzgur.crates)
- [vadimcn.vscode-lldb](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)

2. Open `Command Palette` with Ctrl+Shift+P or F1 and type `LLDB: Generate Launch Configurations from Cargo.toml` then select it, this will generate a file that should be saved as `.vscode/launch.json`.

3. Now you can enable breakpoint on code through IDE and then start debugging the library/binary you want, such as the following example:

<div align="center">
<img src="./assets/debug-options-vscode.png" width="700px"/>
skewballfox marked this conversation as resolved.
Show resolved Hide resolved
<div align="left">

4. If you're creating a new library or binary, keep in mind to repeat the step 2 to always keep a fresh list of targets.

## Have another editor? Open a PR!
32 changes: 32 additions & 0 deletions contributor-book/src/getting-started/setting-up-the-environment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# setting up the environment
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

There are a couple of tools that need to be installed, and commands to be familiar with, depending on what part of the project you plan on contributing to. This section should be up to date with current project practices (as of 2024-01-26)

## General

there are a few commands you want to run prior to any commit for a non-draft PR:
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

1. `cargo clippy --fix --allow-dirty`, this will run clippy and fix any issues it can, the allow dirty flag is required whenever you have uncommitted changes
2. `cargo fmt --all`, this will run rustfmt on all files in the project
3. `./run_checks.sh all`, this is a script located in the project root that builds and tests the project. It is required that this pass prior to merging a PR. Fair warning, running these tests can take a while[^2].
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

## Updating the burn semver version

To bump for the next version, install `cargo-edit` if its not on your system, and use this command:

```sh
cargo set-version --bump minor
```
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

## Contributing to the Burn (Developer) Book

Copy link
Member

Choose a reason for hiding this comment

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

We have a new Xtask command to manage our books, for instance cargo xtask books burn open. It will install the required cargo crates automatically. We should consolidate all our commands behind cargo xtask.

Both the Burn book and the burn developer book are built with mdbook. To install mdbook, run the following command[^1]:

```bash
cargo install mdbook
```

also instead of running `./run_checks.sh all`, you can run `./run_checks.sh typo` to only check for misspellings. This will install [typo](https://crates.io/crates/typos-cli), and if any are encountered you should be able to run `typo -w /path/to/book` to fix them.
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

[^1]: You might also want to install [cargo-update](https://github.com/nabijaczleweli/cargo-update) to easily keep your tools up to date, though it is in no way required.
[^2]: if your system is running into issues with memory and you are on linux you may want to switch to a [virtual console](https://wiki.archlinux.org/title/Linux_console#Virtual_consoles) to run the tests. To do this, press `ctrl+alt+f3` to switch to a virtual console(and log in), and either `ctrl+alt+f2` or `ctrl+alt+f1` to switch back to your graphical session.
skewballfox marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions contributor-book/src/getting-started/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# testing
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

## Test for TensorOps

the following examples use matrix multiplication operation
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

Test for Tensor operations (as in given this input, expect it match or approximate this output) are defined only in [`burn-tensor/src/test/ops`](https://github.com/tracel-ai/burn/blob/b9bd42959b0d3e755a25e383cb5b38beb25559b8/burn-tensor/src/tests/ops/matmul.rs#L1) and not in the backends, with the exception of `burn-autodiff`. These test are added to the `testgen_all` macro rule in [`burn-tensor/src/test/mod.rs`](https://github.com/tracel-ai/burn/blob/b9bd42959b0d3e755a25e383cb5b38beb25559b8/burn-tensor/src/tests/mod.rs#L59). This is then propagated to the existing backends without any additional work.
Copy link
Member

Choose a reason for hiding this comment

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

That's hard to read.

Also I would recommend to avoid pointing to lines of code because the code base will evolve and we will end up with broken links. I suggest to point to files only and then use struct names to point a specific part in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, all the links are permalinks, as in line numbers on specific commits. Those should only be changed if the code undergoes changes so significant that the specific section would need to be rewritten

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also what do you mean it's hard to read? do you mean the structure of the text is hard to understand or the unrendered markdown links are hard to read?

Copy link
Member

@syl20bnr syl20bnr Jan 29, 2024

Choose a reason for hiding this comment

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

I had to reread it several times but I was not using the rendered files indeed 😆. While those links are locked to a specific commit I believe it is better to make the documentation more resilient to the changes by avoiding the necessity to link to the code base.

Also a trick to avoid inlining HTTP links in the paragraphs is to write them at the end of the file. They become [the burn-tensor crate]() in the text and then at the end of the file we have [the burn-tensor crate]: https://.... This link can also be reused easily in the same file making it easier to update.

Here is an example of how we can avoid being too close to the source code:

Tensor operations tests are defined in the burn-tensor crate under the test folder. This crate defines a macro called testgen_all which generates the code for the common tensor operations tests in all the backends crates like burn-wgpu, burn-ndarray, etc...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to reread it several times but I was not using the rendered files indeed 😆. While those links are locked to a specific commit I believe it is better to make the documentation more resilient to the changes by avoiding the necessity to link to the code base.

for sections like the architecture, that's probably a good idea, though in the case of guides for contributions that involve a significant amount of changes across the project I disagree. take the case of the op addition. Some of the files linked are a thousand+ lines, and may involve changes in multiple places. Plus, IMHO it's generally better to lean towards making instructions as explicit and unambiguous as possible. It's easy to scan over a file and miss something, I definitely did a few times.

Also a trick to avoid inlining HTTP links in the paragraphs is to write them at the end of the file. They become the burn-tensor crate in the text and then at the end of the file we have [the burn-tensor crate]: https://.... This link can also be reused easily in the same file making it easier to update.

I'm currently using that for the footnotes, generally for useful information or tips not directly related to burn.

Copy link
Member

Choose a reason for hiding this comment

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

Fine with me. But we should avoid linking to the code base when it is not strictly necessary. For instance I don't think it is really necessary to link to the exact line of the macro rule definition in the file. In a big file there can be value to those links indeed.


### Test for Autodiff

the following examples use the power operation
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

Test for autodiff go under [burn-autodiff/src/tests/foo.rs](https://github.com/tracel-ai/burn/blob/4ca3e31601228952bb1c1492bc9cd2adf15b5cf1/burn-autodiff/src/tests/pow.rs#L31) (replacing foo for whatever makes sense for your op), and for tensor operations both the left and right side need to be verified. The easiest way to do this, is to

1. use small tensors with simple values
2. pop open a terminal and launch `ipython` import `numpy` (or just use [google colab](https://colab.google/) if you don't have the packages installed and don't want to install them), and do the calculations by hand.
skewballfox marked this conversation as resolved.
Show resolved Hide resolved
3. comparing the actual to expected output for lhs, rhs and regular operation
skewballfox marked this conversation as resolved.
Show resolved Hide resolved

generally, it seems preferable to use `actual_output_tensor.to_data().assert_approx_eq(&expected_tensor_data,3)` to `assert_eq!(...` due to occasional hiccups with floating point calculations.
skewballfox marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions contributor-book/src/guides/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Guides for Contributors

The following guides are meant to help contributors trying to accomplish specific tasks, such as adding a new operations to Burn or generating test models for burn-import.
Loading
Loading