mirror of https://github.com/tracel-ai/burn.git
Add run-before-pr.sh script and fix clippy errors (#397)
This commit is contained in:
parent
e2adb294e9
commit
80d145d629
|
@ -0,0 +1,66 @@
|
||||||
|
# Contributing to the Burn Project
|
||||||
|
|
||||||
|
Welcome to the Burn project! We're thrilled that you're considering contributing to our project.
|
||||||
|
Every contribution helps, and we're delighted to have you on board.
|
||||||
|
|
||||||
|
## How to Contribute?
|
||||||
|
|
||||||
|
Here are some steps to guide you through the process of contributing to the Burn project:
|
||||||
|
|
||||||
|
### Step 1: Review the Issue Tickets
|
||||||
|
|
||||||
|
Before you start working on a contribution, please take a moment to look through the open issues in
|
||||||
|
the [issue tracker](https://github.com/burn-rs/burn/issues) for this project. This will give you an
|
||||||
|
idea of what kind of work is currently being planned or is in progress.
|
||||||
|
|
||||||
|
### Step 2: Get Familiar with the Project Architecture
|
||||||
|
|
||||||
|
It's crucial to have an understanding of the [project's architecture](/ARCHITECTURE.md). Familiarize
|
||||||
|
yourself with the structure of the project, the purpose of different components, and how they
|
||||||
|
interact with each other. This will give you the context needed to make meaningful contributions.
|
||||||
|
|
||||||
|
### Step 3: Fork and Clone the Repository
|
||||||
|
|
||||||
|
Before you can start making changes, you'll need to fork the Burn repository and clone it to your
|
||||||
|
local machine. This can be done via the GitHub website or the GitHub Desktop application. Here are
|
||||||
|
the steps:
|
||||||
|
|
||||||
|
1. Click the "Fork" button at the top-right of this page to create a copy of this project in your
|
||||||
|
GitHub account.
|
||||||
|
2. Clone the repository to your local machine. You can do this by clicking the "Code" button on the
|
||||||
|
GitHub website and copying the URL. Then open a terminal on your local machine and type
|
||||||
|
`git clone [the URL you copied]`.
|
||||||
|
|
||||||
|
### Step 4: Create a New Branch
|
||||||
|
|
||||||
|
It's a good practice to create a new branch for each contribution you make. This keeps your changes
|
||||||
|
organized and separated from the main project, which can make the process of reviewing and merging
|
||||||
|
your changes easier. You can create a new branch by using the command
|
||||||
|
`git checkout -b [branch-name]`.
|
||||||
|
|
||||||
|
### Step 5: Make Your Changes
|
||||||
|
|
||||||
|
Once you have set up your local repository and created a new branch, you can start making changes.
|
||||||
|
Be sure to follow the coding standards and guidelines used in the rest of the project.
|
||||||
|
|
||||||
|
### Step 6: Run the Pre-Pull Request Script
|
||||||
|
|
||||||
|
Before you open a pull request, please run the [`run-before-pr.sh`](/run-before-pr.sh) script. This
|
||||||
|
will ensure that your changes are in line with our project's standards and guidelines. You can run
|
||||||
|
this script by opening a terminal, navigating to your local project directory, and typing
|
||||||
|
`./run-before-pr.sh`.
|
||||||
|
|
||||||
|
### Step 7: Submit a Pull Request
|
||||||
|
|
||||||
|
After you've made your changes and run the pre-pull request script, you're ready to submit a pull
|
||||||
|
request. This can be done through the GitHub website or the [GitHub Desktop application](https://desktop.github.com/).
|
||||||
|
|
||||||
|
When submitting your pull request, please provide a brief description of the changes you've made and
|
||||||
|
the issue or issues that your changes address.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
We look forward to seeing your contributions to the Burn project. Happy coding!
|
||||||
|
|
||||||
|
If you have any questions and would like to get in touch with us, please feel free to join our
|
||||||
|
discord server: [](https://discord.gg/uPEBbYYDB6)
|
|
@ -231,7 +231,7 @@ Additionally, [spin::mutex::Mutex](https://docs.rs/spin/latest/spin/mutex/struct
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Before contributing, please take a moment to review our [code of conduct](https://github.com/burn-rs/burn/tree/main/CODE-OF-CONDUCT.md).
|
Before contributing, please take a moment to review our [code of conduct](https://github.com/burn-rs/burn/tree/main/CODE-OF-CONDUCT.md).
|
||||||
It's also highly recommended to read our [architecture document](https://github.com/burn-rs/burn/tree/main/ARCHITECTURE.md), which explains our architectural decisions.
|
It's also highly recommended to read our [architecture document](https://github.com/burn-rs/burn/tree/main/ARCHITECTURE.md), which explains our architectural decisions. Please see more details in our [contributing guide](/CONTRIBUTING.md).
|
||||||
|
|
||||||
## Sponsors
|
## Sponsors
|
||||||
|
|
||||||
|
|
|
@ -364,7 +364,11 @@ impl<PS: PrecisionSettings> BurnGraph<PS> {
|
||||||
.map(|(index, node)| node.forward(&mut self.scope, index))
|
.map(|(index, node)| node.forward(&mut self.scope, index))
|
||||||
.for_each(|code| body.extend(code));
|
.for_each(|code| body.extend(code));
|
||||||
|
|
||||||
|
// TODO Return the result without a `let` binding from a block,
|
||||||
|
// otherwise let_and_return error will be triggered by clippy.
|
||||||
|
// For now, we just disable the warning.
|
||||||
quote! {
|
quote! {
|
||||||
|
#[allow(clippy::let_and_return)]
|
||||||
pub fn forward(&self, #input_def) -> #output_type_def {
|
pub fn forward(&self, #input_def) -> #output_type_def {
|
||||||
#body
|
#body
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ mod tests {
|
||||||
conv2d,
|
conv2d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(clippy::let_and_return)]
|
||||||
pub fn forward(&self, tensor1: Tensor<B, 4>, tensor2: Tensor<B, 4>) -> Tensor<B, 4> {
|
pub fn forward(&self, tensor1: Tensor<B, 4>, tensor2: Tensor<B, 4>) -> Tensor<B, 4> {
|
||||||
let tensor3 = tensor1.matmul(tensor2);
|
let tensor3 = tensor1.matmul(tensor2);
|
||||||
let tensor4 = self.conv2d.forward(tensor3);
|
let tensor4 = self.conv2d.forward(tensor3);
|
||||||
|
@ -277,7 +277,7 @@ mod tests {
|
||||||
conv2d,
|
conv2d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(clippy::let_and_return)]
|
||||||
pub fn forward(&self, tensor1: Tensor<B, 4>, tensor2: Tensor<B, 4>) -> Tensor<B, 4> {
|
pub fn forward(&self, tensor1: Tensor<B, 4>, tensor2: Tensor<B, 4>) -> Tensor<B, 4> {
|
||||||
let tensor3 = tensor1.matmul(tensor2.clone());
|
let tensor3 = tensor1.matmul(tensor2.clone());
|
||||||
let tensor4 = self.conv2d.forward(tensor2);
|
let tensor4 = self.conv2d.forward(tensor2);
|
||||||
|
|
|
@ -205,7 +205,7 @@ mod tests {
|
||||||
norm,
|
norm,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(clippy::let_and_return)]
|
||||||
pub fn forward(&self, input: Tensor<B, 4>) -> Tensor<B, 4> {
|
pub fn forward(&self, input: Tensor<B, 4>) -> Tensor<B, 4> {
|
||||||
let output = self.norm.forward(input);
|
let output = self.norm.forward(input);
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ mod tests {
|
||||||
conv2d,
|
conv2d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(clippy::let_and_return)]
|
||||||
pub fn forward(&self, input: Tensor<B, 4>) -> Tensor<B, 4> {
|
pub fn forward(&self, input: Tensor<B, 4>) -> Tensor<B, 4> {
|
||||||
let output = self.conv2d.forward(input);
|
let output = self.conv2d.forward(input);
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ mod tests {
|
||||||
linear,
|
linear,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(clippy::let_and_return)]
|
||||||
pub fn forward(&self, input: Tensor<B, 4>) -> Tensor<B, 4> {
|
pub fn forward(&self, input: Tensor<B, 4>) -> Tensor<B, 4> {
|
||||||
let output = self.linear.forward(input);
|
let output = self.linear.forward(input);
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ mod tests {
|
||||||
pub fn new_with(record: ModelRecord<B>) -> Self {
|
pub fn new_with(record: ModelRecord<B>) -> Self {
|
||||||
Self { }
|
Self { }
|
||||||
}
|
}
|
||||||
|
#[allow(clippy::let_and_return)]
|
||||||
pub fn forward(&self, tensor1: Tensor<B, 4>, tensor2: Tensor<B, 4>) -> Tensor<B, 4> {
|
pub fn forward(&self, tensor1: Tensor<B, 4>, tensor2: Tensor<B, 4>) -> Tensor<B, 4> {
|
||||||
let tensor3 = tensor1.matmul(tensor2);
|
let tensor3 = tensor1.matmul(tensor2);
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ impl<B: Backend> Model<B> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::let_and_return)]
|
||||||
pub fn forward(&self, input1: Tensor<B, 4>) -> Tensor<B, 2> {
|
pub fn forward(&self, input1: Tensor<B, 4>) -> Tensor<B, 2> {
|
||||||
let conv2d1_out1 = self.conv2d1.forward(input1);
|
let conv2d1_out1 = self.conv2d1.forward(input1);
|
||||||
let relu1_out1 = burn::tensor::activation::relu(conv2d1_out1);
|
let relu1_out1 = burn::tensor::activation::relu(conv2d1_out1);
|
||||||
|
|
|
@ -17,6 +17,7 @@ use burn_tensor::{backend::Backend, ops::TensorOps, Data, ElementConversion, Sha
|
||||||
use libm::{cos, erf, sin, tanh};
|
use libm::{cos, erf, sin, tanh};
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
|
#[allow(unused_imports)]
|
||||||
use num_traits::Float;
|
use num_traits::Float;
|
||||||
|
|
||||||
impl<E: FloatNdArrayElement> TensorOps<NdArrayBackend<E>> for NdArrayBackend<E> {
|
impl<E: FloatNdArrayElement> TensorOps<NdArrayBackend<E>> for NdArrayBackend<E> {
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script is run before a PR is created.
|
||||||
|
# It is used to check that the code compiles and passes all tests.
|
||||||
|
# It is also used to check that the code is formatted correctly and passes clippy.
|
||||||
|
|
||||||
|
# Exit immediately if a command exits with a non-zero status.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Function to handle errors
|
||||||
|
error_handler() {
|
||||||
|
local exit_status=$?
|
||||||
|
local line_number=$1
|
||||||
|
local command=$2
|
||||||
|
|
||||||
|
echo "Error on line $line_number"
|
||||||
|
echo "Command '$command' exited with status $exit_status"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Signal trap to call error_handler when a command fails
|
||||||
|
trap 'error_handler $LINENO $BASH_COMMAND' ERR
|
||||||
|
|
||||||
|
# Function to build and test no_std
|
||||||
|
build_and_test_no_std() {
|
||||||
|
local dir=$1
|
||||||
|
|
||||||
|
echo "$dir"
|
||||||
|
cd $dir || exit
|
||||||
|
|
||||||
|
echo "Build without defaults"
|
||||||
|
cargo build --no-default-features
|
||||||
|
|
||||||
|
echo "Test without defaults"
|
||||||
|
cargo test --no-default-features
|
||||||
|
|
||||||
|
echo "Build for WebAssembly"
|
||||||
|
cargo build --no-default-features --target wasm32-unknown-unknown
|
||||||
|
|
||||||
|
echo "Build for ARM"
|
||||||
|
cargo build --no-default-features --target thumbv7m-none-eabi
|
||||||
|
|
||||||
|
cd .. || exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to build and test all features
|
||||||
|
build_and_test_all_features() {
|
||||||
|
local dir=$1
|
||||||
|
|
||||||
|
echo "$dir"
|
||||||
|
cd $dir || exit
|
||||||
|
|
||||||
|
echo "Build with all defaults"
|
||||||
|
cargo build --all-features
|
||||||
|
|
||||||
|
echo "Test with defaults"
|
||||||
|
cargo test --all-features
|
||||||
|
|
||||||
|
cd .. || exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Save the script start time
|
||||||
|
start_time=$(date +%s)
|
||||||
|
|
||||||
|
# Add wasm32 target for compiler.
|
||||||
|
rustup target add wasm32-unknown-unknown
|
||||||
|
rustup target add thumbv7m-none-eabi
|
||||||
|
|
||||||
|
# TODO decide if we should "cargo clean" here.
|
||||||
|
cargo build --workspace
|
||||||
|
cargo test --workspace
|
||||||
|
cargo fmt --check --all
|
||||||
|
cargo clippy -- -D warnings
|
||||||
|
|
||||||
|
# no_std tests
|
||||||
|
build_and_test_no_std "burn"
|
||||||
|
build_and_test_no_std "burn-core"
|
||||||
|
build_and_test_no_std "burn-common"
|
||||||
|
build_and_test_no_std "burn-tensor"
|
||||||
|
build_and_test_no_std "burn-ndarray"
|
||||||
|
build_and_test_no_std "burn-no-std-tests"
|
||||||
|
|
||||||
|
# all features tests
|
||||||
|
build_and_test_all_features "burn-dataset"
|
||||||
|
|
||||||
|
# Calculate and print the script execution time
|
||||||
|
end_time=$(date +%s)
|
||||||
|
execution_time=$((end_time - start_time))
|
||||||
|
echo "Script executed in $execution_time seconds."
|
Loading…
Reference in New Issue