Skip to content

Commit

Permalink
🔧 chore: release 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-francoisreboud authored Dec 16, 2022
2 parents d1945b5 + 733793a commit 3c09c23
Show file tree
Hide file tree
Showing 115 changed files with 8,624 additions and 2,198 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
Tests/MAExamples/Base/data/**/* filter=lfs diff=lfs merge=lfs -text
6 changes: 1 addition & 5 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Pull lfs
run: git lfs pull

- name: Setup Conda Environment
run: |
conda create --name maexamples-ci python=3.7
conda create --name maexamples-ci python=3.9
conda env list
- name: Install Python Library
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- name: Setup Conda Environment
run: |
conda create --name matorch-ci python=3.7
conda create --name matorch-ci python=3.9
conda env list
- name: Install Python Library
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ jobs:
runs-on: self-hosted

steps:
- uses: swift-actions/setup-swift@v1
with:
swift-version: "5.7.0"
- uses: actions/checkout@v3
- name: Build
run: swift build
- name: Test
run: swift test --filter MAKitTests
run: swift test -c release --filter MAKitTests
2 changes: 1 addition & 1 deletion Docs/Architecture/MATorchTests.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ in [GitHub](https://github.com/owkin/MAKit/actions) .
These tests require a special `Python` environment.

```bash
conda create --name matorch python=3.7
conda create --name matorch python=3.9
conda activate matorch
cd Tests/MATorchTests/Base
pip install -e .
Expand Down
13 changes: 9 additions & 4 deletions Docs/Concepts/MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ Let us imagine the two models have been trained and we want to save them
to the disk:

```swift
let encoder = PropertyListEncoder()
// Use JSONEncoder to encode a readable file
// or PropertyListEncoder to encode a binary file
// (takes less space on the disk).
let encoder = JSONEncoder()

// Encode first model.
var data = try! encoder.encode(cnn)
Expand All @@ -154,15 +157,17 @@ to the full `Model` API:
```swift
// Load the data of our first model from the disk.
data = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/model1.plist"))
// Initialize a base model out of it.
let baseCNN = try! PropertyListDecoder().decode(
// Initialize a base model out of it.
// Use PropertyListDecoder instead to decode a binary file.
let baseCNN = try! JSONDecoder().decode(
BaseModel.self, from: data
)

// Load the data of our second model from the disk.
data = try! Data(contentsOf: URL(fileURLWithPath: "/path/to/model2.plist"))
// Initialize a base model ouf of it.
let baseClassifier = try! PropertyListDecoder().decode(
// Use PropertyListDecoder instead to decode a binary file.
let baseClassifier = try! JSONDecoder().decode(
BaseModel.self, from: data
)

Expand Down
32 changes: 30 additions & 2 deletions Docs/Contributing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,36 @@ All notable changes to this project will be documented in this file.

## [unreleased]

🔧 **chore:** rollback changelog ([#16](https://github.com/owkin/MAKit/pull/16))\
🔧 **chore:** fix badges in the readme ([#15](https://github.com/owkin/MAKit/pull/15))
## 0.1.1 (2022-12-16)

### Features

🪜 **layer_2d:** ResizeBilinearCrop ([#36](https://github.com/owkin/MAKit/pull/36))\
🚀 **perf:** enhance backwardGPU for ResizeBilinear ([#35](https://github.com/owkin/MAKit/pull/35))\
🪜 **layer_2d:** Rotate2D ([#34](https://github.com/owkin/MAKit/pull/34))\
🪜 **layer_2d:** ResizeBilinear ([#32](https://github.com/owkin/MAKit/pull/32))\
🪜 **layer_2d:** Pad2D & Jitter2D ([#30](https://github.com/owkin/MAKit/pull/30))\
🪜 **layer_2d:** add tests for non dirty status ([#27](https://github.com/owkin/MAKit/pull/27))\
🪜 **layer_2d:** FTFrequences2D & Multiply2D ([#25](https://github.com/owkin/MAKit/pull/25))\
🪜 **layer_2d:** LinearScale2D ([#24](https://github.com/owkin/MAKit/pull/24))\
🪜 **layer_2d:** DecorelateRGB ([#23](https://github.com/owkin/MAKit/pull/23))\
🪜 **layer_2d:** RDFT2Image ([#22](https://github.com/owkin/MAKit/pull/22))\
🪜 **core:** Sigmoid activation ([#21](https://github.com/owkin/MAKit/pull/21))\
🚀 **metal:** systematic dispatchThreads API ([#19](https://github.com/owkin/MAKit/pull/19))\

### Bug Fixes

🐛 **fix:** update correlation matrix coeffs ([#37](https://github.com/owkin/MAKit/pull/37))\
🐛 **fix:** ResizeBilinear to output deterministic dimensions ([#33](https://github.com/owkin/MAKit/pull/33))\

### Miscellaneous Tasks

🔨 **refactor:** remove transaction ([#31](https://github.com/owkin/MAKit/pull/31))\
🚨 **integration:** activate DecorrelateRGB in test ([#29](https://github.com/owkin/MAKit/pull/29))\
🚨 **integration:** test IDFT and complex numbers ([#28](https://github.com/owkin/MAKit/pull/28))\
🔨 **tests:** factorize transform tests ([#26](https://github.com/owkin/MAKit/pull/26))\
👷 **ci:** remove swift action ([#20](https://github.com/owkin/MAKit/pull/20))\
👷 **ci:** remove LFS ([#17](https://github.com/owkin/MAKit/pull/17))\

## 0.1.0 (2022-10-28)

Expand Down
9 changes: 5 additions & 4 deletions Docs/Contributing/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,13 @@ containing the commits to merge into the `main` branch.
Do not delete the "Unreleased" section title: future PRs will insert
changelog items in this section.
- Commit and push the changes.
- Squash and merge the new branch into `release_N` with commit message \
🔧 chore: release X.Y.Z
- Squash and merge the new branch into `release_N`.

1. Create a Pull Request
1. Create a Pull Request for `release_N` targeting the `main` branch.

1. Review and Merge the Pull Request
1. Review and Merge the Pull Request, change the commit
message \
🔧 chore: release X.Y.Z

1. Create a GitHub release X.Y.Z from `main`:
- GitHub > Releases > Draft new Release
Expand Down
14 changes: 1 addition & 13 deletions Docs/Examples/VGG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ This example has some `Python` dependencies. In order to run
the example, we first have to setup the environment:

```bash
conda create --name maexamples python=3.7
conda create --name maexamples python=3.9
conda activate maexamples
cd Tests/MAExamples/Base
pip install -e .
Expand All @@ -80,18 +80,6 @@ conda deactivate
conda env remove --name maexamples
```

## Known Issues

The following error may follow on local setup:
`UnpicklingError: invalid load key, ‘v’`.

This may occur when lfs data files are not pulled.
To fix this:

```bash
git lfs pull
```

## Steps

1. Dump the training and testing datasets.
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

116 changes: 99 additions & 17 deletions Sources/MAKit/Core/Function/Activation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
//

import Foundation
import MetalKit

/// Registry of activation function types.
let ACTIVATION_REGISTRY: [String: Codable.Type] = buildRegistry(
[
ReLU.self,
LeakyReLU.self,
SoftReLU.self,
Sigmoid.self
])

/// Activation function to be used in a layer.
open class ActivationFunction: Codable
Expand Down Expand Up @@ -253,13 +261,7 @@ open class ActivationFunction: Codable
command.setBuffer(tmp.metal, atIndex: 1)
command.setBuffer(outs.metal, atIndex: 2)

let threads = command.threadExecutionWidth
let threadsPerThreadgroup = MTLSizeMake(threads, 1, 1)
let threadsPerGrid = MTLSize(width: nbElems, height: 1, depth: 1)
command.dispatchThreads(
threadsPerGrid: threadsPerGrid,
threadsPerThreadgroup: threadsPerThreadgroup
)
command.dispatchThreads(nbElems)
command.enqueue()
}

Expand Down Expand Up @@ -326,13 +328,7 @@ open class ActivationFunction: Codable
command.setBytes(pNbElems, atIndex: 1)
command.setBuffer(delta.metal, atIndex: 2)

let threads = command.threadExecutionWidth
let threadsPerThreadgroup = MTLSizeMake(threads, 1, 1)
let threadsPerGrid = MTLSize(width: nbElems, height: 1, depth: 1)
command.dispatchThreads(
threadsPerGrid: threadsPerGrid,
threadsPerThreadgroup: threadsPerThreadgroup
)
command.dispatchThreads(nbElems)
command.enqueue()
}

Expand Down Expand Up @@ -607,6 +603,81 @@ public class SoftReLU: ActivationFunction
}
}

/// Sigmoid activation function.
public class Sigmoid: ActivationFunction
{
public static let str = "Sigmoid"

/// Forward GPU kernel.
public override var forwardKernel: String
{
get {
return "forwardSigmoid"
}
}
/// Backward GPU kernel.
public override var backwardKernel: String
{
get {
return "backwardSigmoid"
}
}

/// Create a Sigmoid activation function.
init()
{
super.init(Sigmoid.str)
}

///
/// Decode from the disk.
///
/// Throw an error if reading from the decoder fails, or
/// if the data read is corrupted or otherwise invalid.
///
/// - Parameter decoder: The decoder to read data from.
///
required public init(from decoder: Decoder) throws
{
try super.init(from: decoder)
}

///
/// Coefficient to apply during the weights initialization.
///
/// - Parameters:
/// - nPrev: The number of input connections.
/// - nCur: The number of output connections.
///
public override func coeffInitWeights(nPrev: Int, nCur: Int) -> Double
{
return sqrt(1.0 / Double(nPrev))
}

///
/// Forward CPU.
///
/// - Parameter x: The input.
/// - Returns: The output.
///
public override func apply(_ x: Double) -> Double
{
return 1 / (1 + exp(-x))
}

///
/// Backward CPU.
///
/// - Parameter x: The input.
/// - Returns: The output.
///
public override func derivate(_ x: Double) -> Double
{
let fx = apply(x)
return fx * (1 - fx)
}
}

/// Factory API to build an activation function.
public protocol ActivationKernel
{
Expand All @@ -627,6 +698,7 @@ class ActivationKernelImpl: ActivationKernel
ReLU.str: ReLUKernel(),
LeakyReLU.str: LeakyReLUKernel(),
SoftReLU.str: SoftReLUKernel(),
Sigmoid.str: SigmoidKernel()
]

///
Expand Down Expand Up @@ -664,7 +736,7 @@ private class ReLUKernel: ActivationKernelImpl
}
}

/// Factory to build a ReLU function.
/// Factory to build a LeakyReLU function.
private class LeakyReLUKernel: ActivationKernelImpl
{
/// Build a LeakyReLU function.
Expand All @@ -674,7 +746,7 @@ private class LeakyReLUKernel: ActivationKernelImpl
}
}

/// Factory to build a ReLU function.
/// Factory to build a SoftReLU function.
private class SoftReLUKernel: ActivationKernelImpl
{
/// Build a SoftReLU function.
Expand All @@ -683,3 +755,13 @@ private class SoftReLUKernel: ActivationKernelImpl
return SoftReLU()
}
}

/// Factory to build a Sigmoid function.
private class SigmoidKernel: ActivationKernelImpl
{
/// Build a Sigmoid function.
override func build() -> ActivationFunction
{
return Sigmoid()
}
}
Loading

0 comments on commit 3c09c23

Please sign in to comment.