From f2b1de2d94b396b7bb10847bcf8d07099753fd43 Mon Sep 17 00:00:00 2001 From: willeagren Date: Fri, 13 Jan 2023 20:00:19 +0000 Subject: [PATCH 01/15] Do not pip install requirements in build --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 177c820..18d6cba 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ SHELL := /bin/bash build: - python3 -m pip install -r requirements.txt cd leafrs && maturin develop --release clean: From 7ea7070a837f8954a3dec79c533968f94534593e Mon Sep 17 00:00:00 2001 From: willeagren Date: Fri, 13 Jan 2023 20:00:41 +0000 Subject: [PATCH 02/15] Apply changes according to refactor, set np.float32 --- pyvsrust.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyvsrust.py b/pyvsrust.py index ab11499..1233b17 100644 --- a/pyvsrust.py +++ b/pyvsrust.py @@ -50,7 +50,7 @@ def info(s, strftime=True): info('Running performance test Python vs Rust API\n') info(f'Generating test data with shape: {dimensions}...') -data = np.random.rand(*dimensions) +data = np.random.rand(*dimensions).astype(np.float32) info('OK\n', strftime=False) pysum = 0 @@ -66,7 +66,7 @@ def info(s, strftime=True): info('Starting Rust API job...') t_rustart = time.time() -rusum = rs.rusum(data).sum() +rusum = rs.EXAMPLE_MATRIX_SUM(data).sum() t_ru = time.time() - t_rustart info('OK\n', strftime=False) info(f'Time: {t_ru:.3f} seconds\n') From dc511f1ba26a991d551e704812fdf72bcffb9cd9 Mon Sep 17 00:00:00 2001 From: willeagren Date: Fri, 13 Jan 2023 20:01:01 +0000 Subject: [PATCH 03/15] Remove torch-cpu reduandat version --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b7224fd..1c5cc2e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ maturin==0.13.7 numpy==1.23.4 tomli==2.0.1 -torch>=1.7.0+cpu From 0510532c7588245a5ff55935a4eb7479cf51f04f Mon Sep 17 00:00:00 2001 From: willeagren Date: Fri, 13 Jan 2023 20:01:42 +0000 Subject: [PATCH 04/15] Add comments, remove redundant code, clean up (#24) --- leafrs/src/lib.rs | 82 ++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/leafrs/src/lib.rs b/leafrs/src/lib.rs index 52e0fa3..7aab557 100644 --- a/leafrs/src/lib.rs +++ b/leafrs/src/lib.rs @@ -41,31 +41,18 @@ use pyo3::prelude::{ Python }; -mod rust_fn { - use ndarray::{arr1, Array1, Array2, ArrayD}; +// Declare the scope/module for function specific implementations, called from Python +// through the created maturin bindings of the `PyO3` crate. Inside this scope +// we operate on the dynamic arrays specified by the `ndarray` crate. The `numpy` +// crate used in the outer scope is only used as API for the native C bindings. +mod RUST_BACKEND { + use ndarray::{Array2, ArrayD}; use ndarray::prelude::*; use numpy::ndarray::{ArrayViewD, ArrayView4}; - use ordered_float::OrderedFloat; - pub fn max_min(x: &ArrayViewD<'_, f32>) -> Array1 { - if x.len() == 0 { return arr1(&[]); } - let max_val = x - .iter() - .map(|a| OrderedFloat(*a)) - .max() - .expect("Error calculating max value.") - .0; - let min_val = x - .iter() - .map(|a| OrderedFloat(*a)) - .min() - .expect("Error calculating min value.") - .0; - let result_array = arr1(&[max_val, min_val]); - result_array - } - - pub fn rusum(x: &ArrayView4<'_, f32>) -> Array2 { + // BACKEND FUNC, only used in Python vs Rust performance example. + // Calculates the sum of a 4 dimensional f32 matrix. + pub fn EXAMPLE_MATRIX_SUM(x: &ArrayView4<'_, f32>) -> Array2 { let xshape = x.shape(); let mut result_array = Array2::zeros((xshape[0], xshape[1])); for h in 0..xshape[2] { @@ -76,49 +63,58 @@ mod rust_fn { result_array } - pub fn add(x: &ArrayViewD<'_, f32>, y: &ArrayViewD<'_, f32>) -> ArrayD { + // BACKEND FUNC, performs addition on two ndarrays. + pub fn add( + x: &ArrayViewD<'_, f32>, + y: &ArrayViewD<'_, f32> + ) -> ArrayD { x + y } + + // BACKEND FUNC, performs subtraction on two ndarrays. + // z = y + x + pub fn sub( + x: &ArrayViewD<'_, f32>, + y: &ArrayViewD<'_, f32> + ) -> ArrayD { + x - y + } } #[pymodule] fn leafrs(_py: Python<'_>, m: &PyModule) -> PyResult<()> { - #[pyfn(m)] - fn max_min<'py>( - py: Python<'py>, - x: PyReadonlyArrayDyn - ) -> &'py PyArray1 { - let array = x.as_array(); - let result_array = rust_fn::max_min(&array); - result_array.into_pyarray(py) - } + // Unary operator, calculates the sum of a 4D matrix/tensor. + // ONLY USED IN EXAMPLE SCRIPT COMPARING PYTHON AND RUST SPEED! #[pyfn(m)] - fn rusum<'py>( + fn EXAMPLE_MATRIX_SUM<'py>( py: Python<'py>, x: PyReadonlyArray4 ) -> &'py PyArray2 { - let array = x.as_array(); - let rustsum = rust_fn::rusum(&array); - rustsum.into_pyarray(py) + let arr = x.as_array(); + let sum = RUST_BACKEND::EXAMPLE_MATRIX_SUM(&arr); + sum.into_pyarray(py) } + // Binary operator, performs addition on two ndarrays. #[pyfn(m)] - fn eye<'py>( + fn add<'py>( py: Python<'py>, - size: usize - ) -> &PyArray2 { - let array = ndarray::Array::eye(size); - array.into_pyarray(py) + x: PyReadonlyArrayDyn, + y: PyReadonlyArrayDyn + ) -> &'py PyArrayDyn { + let result = RUST_BACKEND::add(&x.as_array(), &y.as_array()); + result.into_pyarray(py) } + // Binary operator, performs subtraction on two ndarrays. #[pyfn(m)] - fn add<'py>( + fn sub<'py>( py: Python<'py>, x: PyReadonlyArrayDyn, y: PyReadonlyArrayDyn ) -> &'py PyArrayDyn { - let result = rust_fn::add(&x.as_array(), &y.as_array()); + let result = RUST_BACKEND::sub(&x.as_array(), &y.as_array()); result.into_pyarray(py) } From 3eecb95396abac592e5b7c2e2bdfa79bc26b9134 Mon Sep 17 00:00:00 2001 From: willeagren Date: Fri, 13 Jan 2023 20:09:45 +0000 Subject: [PATCH 05/15] Add torch>=1.7.0+cpu wheel to requirements, not supported by Python3.11! --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 1c5cc2e..585bbed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ maturin==0.13.7 numpy==1.23.4 tomli==2.0.1 +torch>=1.7.0+cpu \ No newline at end of file From 8fc8b5c64c5583467e2c33fe90e0532ed0015484 Mon Sep 17 00:00:00 2001 From: willeagren Date: Fri, 13 Jan 2023 20:09:56 +0000 Subject: [PATCH 06/15] Perform pip install -r requirements in build --- .github/workflows/builds.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 482a730..6340bff 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -22,6 +22,7 @@ jobs: run: | python3 -m pip install --upgrade pip python3 -m venv venv + python3 -m pip install -r requirements.txt source venv/bin/activate make @@ -37,6 +38,7 @@ jobs: run: | python3 -m pip install --upgrade pip python3 -m venv venv + python3 -m pip install -r requirements.txt source venv/bin/activate make From a50b97c334514d6e852ac6f1283e8f4272f688b4 Mon Sep 17 00:00:00 2001 From: willeagren Date: Fri, 13 Jan 2023 20:12:31 +0000 Subject: [PATCH 07/15] Install requirements.txt in unittests job --- .github/workflows/unittests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 034cd91..623dc26 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -27,6 +27,7 @@ jobs: run: | python3 -m pip install --upgrade pip python3 -m venv venv + python3 -m pip install -r requirements source venv/bin/activate make python3 -m unittest From 8091fec7b76b3fefc28edafd363061a60ee861ac Mon Sep 17 00:00:00 2001 From: willeagren Date: Fri, 13 Jan 2023 20:14:21 +0000 Subject: [PATCH 08/15] Fix broken yml syntax in PR auto assign (#24) --- .github/workflows/auto-assign-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-assign-pr.yml b/.github/workflows/auto-assign-pr.yml index b5cc747..47e30e7 100644 --- a/.github/workflows/auto-assign-pr.yml +++ b/.github/workflows/auto-assign-pr.yml @@ -8,7 +8,7 @@ jobs: auto-assign: runs-on: ubuntu-latest permissions: - pull-request: write + pull-requests: write steps: - name: 'Auto assign PR' uses: pozil/auto-assign-issue@v1 From 622680338f9ad705b0142309769acba4e397580a Mon Sep 17 00:00:00 2001 From: willeagren Date: Fri, 13 Jan 2023 20:15:43 +0000 Subject: [PATCH 09/15] Change yml expression with GITHUB_TOKEN (#24) --- .github/workflows/auto-assign-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-assign-pr.yml b/.github/workflows/auto-assign-pr.yml index 47e30e7..009036b 100644 --- a/.github/workflows/auto-assign-pr.yml +++ b/.github/workflows/auto-assign-pr.yml @@ -13,7 +13,7 @@ jobs: - name: 'Auto assign PR' uses: pozil/auto-assign-issue@v1 with: - repo-token: ${{ secrets.MY_PERSONAL_TOKEN }} + repo-token: ${{ secrets.GITHUB_TOKEN }} assignees: willeagren numOfAssignee: 1 allowSelfAssign: true From d27abfacc690434484349a7de120e883f5e2bab7 Mon Sep 17 00:00:00 2001 From: willeagren Date: Fri, 13 Jan 2023 20:16:59 +0000 Subject: [PATCH 10/15] Fix broken pip install to requirements.txt (#24) --- .github/workflows/unittests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 623dc26..7889643 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -27,7 +27,7 @@ jobs: run: | python3 -m pip install --upgrade pip python3 -m venv venv - python3 -m pip install -r requirements + python3 -m pip install -r requirements.txt source venv/bin/activate make python3 -m unittest From 9146b6d1f8c139f507dd4818830d115537ebf83c Mon Sep 17 00:00:00 2001 From: willeagren Date: Sat, 14 Jan 2023 17:13:36 +0000 Subject: [PATCH 11/15] Try without Python3.8 setup --- .github/workflows/builds.yml | 2 ++ .github/workflows/unittests.yml | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 6340bff..81d277e 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -18,6 +18,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.8 + - name: Build run: | python3 -m pip install --upgrade pip @@ -34,6 +35,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.8 + - name: Build run: | python3 -m pip install --upgrade pip diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 7889643..d8dbd40 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -6,9 +6,8 @@ on: pull_request: branches: [main] - jobs: - testsCPU: + unit-tests-CPU: name: CPU Tests runs-on: ubuntu-latest @@ -19,10 +18,11 @@ jobs: - name: Update packages run: sudo apt-get update - - name: Set up Python 3.8 - uses: actions/setup-python@v2 - with: - python-version: "3.8" +# - name: Set up Python 3.8 +# uses: actions/setup-python@v2 +# with: +# python-version: "3.8" + - name: Dependencies, build and test run: | python3 -m pip install --upgrade pip From ba97e466adb11dd68859a6736ab48ae24633e30c Mon Sep 17 00:00:00 2001 From: willeagren Date: Sat, 14 Jan 2023 17:27:35 +0000 Subject: [PATCH 12/15] Change function names to snake case --- leafrs/src/lib.rs | 8 +++----- pyvsrust.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/leafrs/src/lib.rs b/leafrs/src/lib.rs index 7aab557..a3085e5 100644 --- a/leafrs/src/lib.rs +++ b/leafrs/src/lib.rs @@ -25,10 +25,8 @@ // Last updated: 2023-01-13 // -use ndarray; use numpy::{ IntoPyArray, - PyArray1, PyArray2, PyArrayDyn, PyReadonlyArrayDyn, @@ -52,7 +50,7 @@ mod RUST_BACKEND { // BACKEND FUNC, only used in Python vs Rust performance example. // Calculates the sum of a 4 dimensional f32 matrix. - pub fn EXAMPLE_MATRIX_SUM(x: &ArrayView4<'_, f32>) -> Array2 { + pub fn _example_matrix_sum(x: &ArrayView4<'_, f32>) -> Array2 { let xshape = x.shape(); let mut result_array = Array2::zeros((xshape[0], xshape[1])); for h in 0..xshape[2] { @@ -87,12 +85,12 @@ fn leafrs(_py: Python<'_>, m: &PyModule) -> PyResult<()> { // Unary operator, calculates the sum of a 4D matrix/tensor. // ONLY USED IN EXAMPLE SCRIPT COMPARING PYTHON AND RUST SPEED! #[pyfn(m)] - fn EXAMPLE_MATRIX_SUM<'py>( + fn example_matrix_sum<'py>( py: Python<'py>, x: PyReadonlyArray4 ) -> &'py PyArray2 { let arr = x.as_array(); - let sum = RUST_BACKEND::EXAMPLE_MATRIX_SUM(&arr); + let sum = RUST_BACKEND::_example_matrix_sum(&arr); sum.into_pyarray(py) } diff --git a/pyvsrust.py b/pyvsrust.py index 1233b17..2f619e0 100644 --- a/pyvsrust.py +++ b/pyvsrust.py @@ -66,7 +66,7 @@ def info(s, strftime=True): info('Starting Rust API job...') t_rustart = time.time() -rusum = rs.EXAMPLE_MATRIX_SUM(data).sum() +rusum = rs.example_matrix_sum(data).sum() t_ru = time.time() - t_rustart info('OK\n', strftime=False) info(f'Time: {t_ru:.3f} seconds\n') From 23df1d39b8bb8f818b5f4e4f5949eec2f6765026 Mon Sep 17 00:00:00 2001 From: willeagren Date: Sat, 14 Jan 2023 19:23:48 +0000 Subject: [PATCH 13/15] Formatting and doc changes --- .github/workflows/builds.yml | 5 ++--- .github/workflows/unittests.yml | 14 +++++++------- leafrs/src/lib.rs | 3 ++- pyvsrust.py | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 81d277e..bec7a7b 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -25,7 +25,7 @@ jobs: python3 -m venv venv python3 -m pip install -r requirements.txt source venv/bin/activate - make + make build build-macos: runs-on: macos-latest @@ -42,5 +42,4 @@ jobs: python3 -m venv venv python3 -m pip install -r requirements.txt source venv/bin/activate - make - + make build diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index d8dbd40..111c79a 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -2,9 +2,9 @@ name: Unit tests on: push: - branches: [main] + branches: [ main ] pull_request: - branches: [main] + branches: [ main ] jobs: unit-tests-CPU: @@ -18,10 +18,10 @@ jobs: - name: Update packages run: sudo apt-get update -# - name: Set up Python 3.8 -# uses: actions/setup-python@v2 -# with: -# python-version: "3.8" + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: "3.8" - name: Dependencies, build and test run: | @@ -29,5 +29,5 @@ jobs: python3 -m venv venv python3 -m pip install -r requirements.txt source venv/bin/activate - make + make build python3 -m unittest diff --git a/leafrs/src/lib.rs b/leafrs/src/lib.rs index a3085e5..85ba220 100644 --- a/leafrs/src/lib.rs +++ b/leafrs/src/lib.rs @@ -22,7 +22,7 @@ // SOFTWARE. // // File created: 2022-11-01 -// Last updated: 2023-01-13 +// Last updated: 2023-01-14 // use numpy::{ @@ -43,6 +43,7 @@ use pyo3::prelude::{ // through the created maturin bindings of the `PyO3` crate. Inside this scope // we operate on the dynamic arrays specified by the `ndarray` crate. The `numpy` // crate used in the outer scope is only used as API for the native C bindings. +#[allow(non_snake_case)] mod RUST_BACKEND { use ndarray::{Array2, ArrayD}; use ndarray::prelude::*; diff --git a/pyvsrust.py b/pyvsrust.py index 2f619e0..a1de430 100644 --- a/pyvsrust.py +++ b/pyvsrust.py @@ -22,7 +22,7 @@ # SOFTWARE. # # File created: 2022-11-01 -# Last updated: 2023-01-13 +# Last updated: 2023-01-14 # import leafrs as rs From 907169f35772938b7ac8adcda25a39bbc34c94a7 Mon Sep 17 00:00:00 2001 From: willeagren Date: Sat, 14 Jan 2023 19:38:07 +0000 Subject: [PATCH 14/15] Doc formatting changes (#25) --- leaf/functions/_binary_ops.py | 4 ++-- leaf/functions/function.py | 9 +++++---- leaf/nn/base.py | 23 +++++++++++++++++------ leaf/nn/linear.py | 8 +++++--- leaf/tensor.py | 8 +++++--- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/leaf/functions/_binary_ops.py b/leaf/functions/_binary_ops.py index 081b094..741eaa8 100644 --- a/leaf/functions/_binary_ops.py +++ b/leaf/functions/_binary_ops.py @@ -22,7 +22,7 @@ # SOFTWARE. # # File created: 2022-11-05 -# Last updated: 2023-01-13 +# Last updated: 2023-01-14 # import numpy as np @@ -37,7 +37,7 @@ def _unbroadcast(arr, shape) -> np.ndarray: class Add(Function): def forward(self, x, y) -> np.ndarray: self.save_for_backward(x.shape, y.shape) - return rs.add(x, y) + return x + y def backward(self, grad) -> Tuple[np.ndarray]: xshape, yshape, = self.saved_tensors diff --git a/leaf/functions/function.py b/leaf/functions/function.py index 679c9f5..85bb3ed 100644 --- a/leaf/functions/function.py +++ b/leaf/functions/function.py @@ -22,7 +22,7 @@ # SOFTWARE. # # File created: 2022-11-05 -# Last updated: 2023-01-13 +# Last updated: 2023-01-14 # import numpy as np @@ -39,11 +39,11 @@ def _verify_tensors(*tensors) -> List[np.ndarray]: return [_extract_data(t) for t in tensors] def _extract_data(tensor) -> np.ndarray: - """ TEMPORARY!!!! EDIT this function """ return tensor.data class Function(object): - """ Definition and impelmentation of the Function class. + """ + Definition and impelmentation of the Function class. Parameters ---------- @@ -72,7 +72,8 @@ def backward(self, *args, **kwargs): @classmethod def apply(cls, *tensors) -> Tensor: - """ This classmethod constructs a Function, also referred to as a context, when + """ + This classmethod constructs a Function, also referred to as a context, when a tensor invokes an operation. As such, the tensor initially invoking the call, self, is represented as part of the *tensors arg together with any optional tensors that are to be part of the context. diff --git a/leaf/nn/base.py b/leaf/nn/base.py index 890b4fb..eb8f514 100644 --- a/leaf/nn/base.py +++ b/leaf/nn/base.py @@ -22,13 +22,14 @@ # SOFTWARE. # # File created: 2022-11-01 -# Last updated: 2023-01-13 +# Last updated: 2023-01-14 # from leaf import Tensor class Module(object): - """ Parent class for the neural network building blocks, i.e. so called Modules. + """ + Parent class for the neural network building blocks, i.e. so called Modules. They each define specific forward pass functionality based on their needs that is invoked by calling the module object with the input tensor. No __init__ method is defined for parent class, please see respective implementations for specific @@ -45,13 +46,23 @@ def forward(self, input_, *args, **kwargs) -> Tensor: ) def parameters(self) -> list: - pass + params = [] + for attr in self.__dict__.values(): + if isinstance(attr, Tensor): + params.extend([attr] if attr.requires_grad else []) + if isinstance(attr, (tuple, list)): + params.extend([p for p in attr if p.requires_grad]) + if isinstance(attr, (Module, Sequential)): + # recursive call to find learnable parameter modules + params.extend([p for p in attr.parameters() if p.requires_grad]) + class Sequential(object): - """ A high-level wrapper for the module object, simplifies the forward pass when + """ + A high-level wrapper for the module object, simplifies the forward pass when multiple operations are needed to perform in order. Follows the same naming - convention as the main module object, namely, __call__() forward() and parameters(), - that make up the API for neural networks. + convention as the main module object with `__call__`, `forward` and + `parameters`, that make up the API for neural networks. Parameters ---------- diff --git a/leaf/nn/linear.py b/leaf/nn/linear.py index 2e47b56..f0e8964 100644 --- a/leaf/nn/linear.py +++ b/leaf/nn/linear.py @@ -22,14 +22,15 @@ # SOFTWARE. # # File created: 2022-11-18 -# Last updated: 2023-01-13 +# Last updated: 2023-01-14 # from leaf import Tensor from leaf.nn import Module class Linear(Module): - """ Linear layer implementation as a neural network module. + """ + Linear layer implementation as a neural network module. This module requires input to be 2D tensor, allowing standard matmul op. Parameters @@ -49,7 +50,8 @@ def __init__(self, fan_in, fan_out, bias=True) -> None: self._bias = Tensor.uniform(fan_out, requires_grad=True) if bias else None def forward(self, input_) -> Tensor: - """ Propagate data through a linear layer, performing linear transform operation. + """ + Propagate data through a linear layer, performing the linear transform operation. Parameters ---------- diff --git a/leaf/tensor.py b/leaf/tensor.py index 3bdc36e..7a8d34c 100644 --- a/leaf/tensor.py +++ b/leaf/tensor.py @@ -22,7 +22,7 @@ # SOFTWARE. # # File created: 2022-11-01 -# Last updated: 2023-01-13 +# Last updated: 2023-01-14 # from __future__ import annotations @@ -30,7 +30,8 @@ import numpy as np class Tensor(object): - """ Definition and implementation of the Tensor class. + """ + Definition and implementation of the Tensor class. Parameters ---------- @@ -103,7 +104,8 @@ def normal(cls, *shape, loc=0.0, scale=1.0, **kwargs): ) def detach(self) -> Tensor: - """ Create a copy of the current tensor that is not part of the + """ + Create a copy of the current tensor that is not part of the dynamic DAG. As such, the new tensor does not, and can not, require grad because it is not part of any context nor DAG. Subsequentially move the tensor to cpu device, if it was on other. From ebd4a3dab139823630761878d829e794f4ebdfc3 Mon Sep 17 00:00:00 2001 From: willeagren Date: Sun, 15 Jan 2023 13:45:58 +0000 Subject: [PATCH 15/15] Clear pycache script for PowerShell --- scripts/cc.ps1 | 1 + cc.sh => scripts/cc.sh | 0 2 files changed, 1 insertion(+) create mode 100644 scripts/cc.ps1 rename cc.sh => scripts/cc.sh (100%) mode change 100755 => 100644 diff --git a/scripts/cc.ps1 b/scripts/cc.ps1 new file mode 100644 index 0000000..c9caa46 --- /dev/null +++ b/scripts/cc.ps1 @@ -0,0 +1 @@ +Get-ChildItem -Include __pycache__ -Recurse -force | Remove-Item -Force -Recurse diff --git a/cc.sh b/scripts/cc.sh old mode 100755 new mode 100644 similarity index 100% rename from cc.sh rename to scripts/cc.sh